@Test
 public void testWithAuthServerAndGlobalMethodSecurity() throws Exception {
   AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
   context.setServletContext(new MockServletContext());
   context.register(ResourceServerAndAuthorizationServerContextAndGlobalMethodSecurity.class);
   context.refresh();
   context.close();
 }
Esempio n. 2
0
 @Override
 public void contextDestroyed(ServletContextEvent sce) {
   log.info("Destroying Web application");
   WebApplicationContext ac =
       WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext());
   AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac;
   gwac.close();
   log.debug("Web application destroyed");
 }
 @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();
 }
 @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();
 }
Esempio n. 5
0
  private WebAppContext buildWebAppContext(String[] args, Enviroment env) {

    AnnotationConfigWebApplicationContext applicationContext =
        new AnnotationConfigWebApplicationContext();
    applicationContext.register(WebContext.class);

    WebAppContext handler = new WebAppContext();
    handler.setContextPath(CONTEXT_NAME);
    handler.setDisplayName(DISPLAY_NAME);

    String[] resources = null;
    resources = new String[] {"./WebContent"};

    handler.setWelcomeFiles(new String[] {"index.html"});
    handler.setInitParameter("useFileMappedBuffer", "false");
    handler.setBaseResource(new ResourceCollection(resources));
    handler.setResourceAlias("/WEB-INF/classes/", "/classes/");

    this.appendListeners(applicationContext, handler);
    this.appendSpringDispatcherServlet(applicationContext, handler);

    applicationContext.close();
    return handler;
  }