use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method testDefaultUsernamePassword.
@Test
public void testDefaultUsernamePassword() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(SecurityAutoConfiguration.class);
this.context.refresh();
SecurityProperties security = this.context.getBean(SecurityProperties.class);
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(security.getUser().getName(), security.getUser().getPassword());
assertThat(manager.authenticate(token)).isNotNull();
}
use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method testCustomAuthenticationDoesNotAuthenticateWithBootSecurityUser.
@Test
public void testCustomAuthenticationDoesNotAuthenticateWithBootSecurityUser() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(AuthenticationManagerCustomizer.class, SecurityAutoConfiguration.class);
this.context.refresh();
SecurityProperties security = this.context.getBean(SecurityProperties.class);
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(security.getUser().getName(), security.getUser().getPassword());
try {
manager.authenticate(token);
fail("Expected Exception");
} catch (AuthenticationException success) {
// Expected
}
token = new UsernamePasswordAuthenticationToken("foo", "bar");
assertThat(manager.authenticate(token)).isNotNull();
}
use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method testWebConfiguration.
@Test
public void testWebConfiguration() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(SecurityAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(AuthenticationManagerBuilder.class)).isNotNull();
// 1 for static resources and one for the rest
assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains()).hasSize(2);
}
use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method testAuthenticationManagerCreated.
@Test
public void testAuthenticationManagerCreated() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(SecurityAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(AuthenticationManager.class)).isNotNull();
}
use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method testOverrideAuthenticationManagerWithBuilderAndInjectBuilderIntoSecurityFilter.
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectBuilderIntoSecurityFilter() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(AuthenticationManagerCustomizer.class, WorkaroundSecurityCustomizer.class, SecurityAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken("foo", "bar", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
assertThat(this.context.getBean(AuthenticationManager.class).authenticate(user)).isNotNull();
}
Aggregations