use of org.springframework.mock.web.MockServletContext 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.mock.web.MockServletContext 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.mock.web.MockServletContext 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.mock.web.MockServletContext 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();
}
use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class SamlMetadataUIParserActionTests method verifyEntityIdUIInfoExists.
@Test
public void verifyEntityIdUIInfoExists() throws Exception {
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(SamlProtocolConstants.PARAMETER_ENTITY_ID, "https://carmenwiki.osu.edu/shibboleth");
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockServletContext sCtx = new MockServletContext();
ctx.setExternalContext(new ServletExternalContext(sCtx, request, response));
ctx.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE, RegisteredServiceTestUtils.getService());
samlMetadataUIParserAction.execute(ctx);
assertNotNull(WebUtils.getServiceUserInterfaceMetadata(ctx, SamlMetadataUIInfo.class));
}
Aggregations