コード例 #1
0
  @Override
  public void onStartup(ServletContext container) throws ServletException {

    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(AppConfig.class);
    ctx.register(SecurityConfig.class);
    container.addListener(new ContextLoaderListener(ctx));

    container
        .addFilter("springSecurityFilterChain", DelegatingFilterProxy.class)
        .addMappingForUrlPatterns(null, false, "/*");
    Map<String, String> initParams = new HashMap<String, String>();
    initParams.put("encoding", "UTF-8");
    initParams.put("forceEncoding", "true");
    FilterRegistration.Dynamic ceFilter =
        container.addFilter("encodingFilter", CharacterEncodingFilter.class);
    ceFilter.setInitParameters(initParams);
    ceFilter.addMappingForUrlPatterns(null, false, "/*");

    ctx.setServletContext(container);

    ServletRegistration.Dynamic servlet =
        container.addServlet("dispatcher", new DispatcherServlet(ctx));

    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");
  }
 public static WebApplicationContext createJavaConfiguration(ServletContext context) {
   AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
   appContext.setServletContext(context);
   appContext.register(ZenContactConfiguration.class);
   appContext.refresh();
   return appContext;
 }
 @Test
 public void testWithAuthServerAndGlobalMethodSecurity() throws Exception {
   AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
   context.setServletContext(new MockServletContext());
   context.register(ResourceServerAndAuthorizationServerContextAndGlobalMethodSecurity.class);
   context.refresh();
   context.close();
 }
コード例 #4
0
ファイル: WebInitializer.java プロジェクト: tpokora/workout
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(AppConfig.class);

    ctx.setServletContext(servletContext);

    Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
  }
コード例 #5
0
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(AppWebConfig.class);
    ctx.setServletContext(servletContext);

    Dynamic dynamic = servletContext.addServlet("web-dispatcher", new DispatcherServlet(ctx));
    dynamic.addMapping("/");
    dynamic.setLoadOnStartup(1);
    dynamic.setAsyncSupported(true);
  }
コード例 #6
0
  public void onStartup(ServletContext container) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(ToyboxConfiguration.class);
    ctx.setServletContext(container);

    ServletRegistration.Dynamic servlet =
        container.addServlet("dispatcher", new DispatcherServlet(ctx));

    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");
  }
  public DispatcherServletChannelInitializer() throws ServletException {

    MockServletContext servletContext = new MockServletContext();
    MockServletConfig servletConfig = new MockServletConfig(servletContext);

    AnnotationConfigWebApplicationContext wac = new AnnotationConfigWebApplicationContext();
    wac.setServletContext(servletContext);
    wac.setServletConfig(servletConfig);
    wac.register(WebConfig.class);
    wac.refresh();

    this.dispatcherServlet = new DispatcherServlet(wac);
    this.dispatcherServlet.init(servletConfig);
  }
コード例 #8
0
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(WebAppConfig.class);
    ctx.register(SecurityConfig.class);
    servletContext.addListener(new ContextLoaderListener(ctx));

    ctx.setServletContext(servletContext);

    Dynamic servlet =
        servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
  }
コード例 #9
0
ファイル: Initializer.java プロジェクト: mfofana/TPMavenBack
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.getEnvironment().setActiveProfiles("dev");
    ctx.register(WebAppConfig.class);
    servletContext.addListener(new ContextLoaderListener(ctx));

    ctx.setServletContext(servletContext);

    registerHiddenHttpMethodFilter(servletContext);

    Dynamic servlet =
        servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
  }
 @Test
 public void testCustomAuthenticationEntryPoint() throws Exception {
   tokenStore.storeAccessToken(token, authentication);
   AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
   context.setServletContext(new MockServletContext());
   context.register(AuthenticationEntryPointContext.class);
   context.refresh();
   MockMvc mvc =
       MockMvcBuilders.webAppContextSetup(context)
           .addFilters(
               new DelegatingFilterProxy(
                   context.getBean("springSecurityFilterChain", Filter.class)))
           .build();
   mvc.perform(MockMvcRequestBuilders.get("/").header("Authorization", "Bearer FOO"))
       .andExpect(MockMvcResultMatchers.status().isFound());
   context.close();
 }
コード例 #11
0
 @Test
 public void createLayoutFromConfigClass() throws Exception {
   AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
   context.register(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
   MockServletContext servletContext = new MockServletContext();
   context.setServletContext(servletContext);
   context.refresh();
   ThymeleafView view =
       (ThymeleafView)
           context.getBean(ThymeleafViewResolver.class).resolveViewName("view", Locale.UK);
   MockHttpServletResponse response = new MockHttpServletResponse();
   MockHttpServletRequest request = new MockHttpServletRequest();
   request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
   view.render(Collections.singletonMap("foo", "bar"), request, response);
   String result = response.getContentAsString();
   assertThat(result).contains("<title>Content</title>");
   assertThat(result).contains("<span>bar</span>");
   context.close();
 }
コード例 #12
0
  @Override
  public void onStartup(ServletContext container) {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(WebConfig.class);
    ctx.scan("com.taskstrategy.data", "com.taskstrategy.business");
    ctx.setServletContext(container);
    ctx.refresh();

    container.addListener(new ContextLoaderListener(ctx));
    container.setInitParameter("defaultHtmlEscape", "true");

    FilterRegistration.Dynamic securityFilter =
        container.addFilter(
            "securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"));
    securityFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

    ServletRegistration.Dynamic registration =
        container.addServlet("dispatcher", new DispatcherServlet(ctx));
    registration.setLoadOnStartup(1);
    registration.setAsyncSupported(true);
    registration.addMapping("/");
  }
コード例 #13
0
  /**
   * Initialize servlet when application on startup.
   *
   * @param servletContext Get ServletContext.
   * @throws ServletException push ServletException in up.
   */
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {

    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(WebAppConfig.class);
    ctx.register(SecurityConfig.class);
    servletContext.addListener(new ContextLoaderListener(ctx));
    ctx.setServletContext(servletContext);

    Dynamic servlet =
        servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(ctx));
    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");

    FilterRegistration.Dynamic encodingFilter =
        servletContext.addFilter(ENCODING_FILTER_NAME, new CharacterEncodingFilter());
    encodingFilter.setInitParameter("encoding", "UTF-8");
    encodingFilter.setInitParameter("forceEncoding", "true");
    encodingFilter.addMappingForUrlPatterns(null, true, "/*");

    FilterRegistration.Dynamic springSecurityFilterChain =
        servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
    springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*");
  }