|
|
|
@ -150,15 +150,15 @@ public class SecurityAutoConfigurationTests { |
|
|
|
public void testEventPublisherInjected() throws Exception { |
|
|
|
public void testEventPublisherInjected() throws Exception { |
|
|
|
this.context = new AnnotationConfigWebApplicationContext(); |
|
|
|
this.context = new AnnotationConfigWebApplicationContext(); |
|
|
|
this.context.setServletContext(new MockServletContext()); |
|
|
|
this.context.setServletContext(new MockServletContext()); |
|
|
|
this.context.register(TestAuthenticationManagerConfiguration.class, SecurityAutoConfiguration.class, |
|
|
|
this.context.register(TestAuthenticationManagerConfiguration.class, |
|
|
|
|
|
|
|
SecurityAutoConfiguration.class, |
|
|
|
PropertyPlaceholderAutoConfiguration.class); |
|
|
|
PropertyPlaceholderAutoConfiguration.class); |
|
|
|
this.context.refresh(); |
|
|
|
this.context.refresh(); |
|
|
|
AuthenticationListener listener = new AuthenticationListener(); |
|
|
|
AuthenticationListener listener = new AuthenticationListener(); |
|
|
|
this.context.addApplicationListener(listener); |
|
|
|
this.context.addApplicationListener(listener); |
|
|
|
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class); |
|
|
|
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class); |
|
|
|
manager.authenticate(new TestingAuthenticationToken("foo", "wrong")); |
|
|
|
manager.authenticate(new TestingAuthenticationToken("foo", "wrong")); |
|
|
|
assertThat(listener.event) |
|
|
|
assertThat(listener.event).isInstanceOf(AuthenticationSuccessEvent.class); |
|
|
|
.isInstanceOf(AuthenticationSuccessEvent.class); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -168,12 +168,14 @@ public class SecurityAutoConfigurationTests { |
|
|
|
this.context.register(SecurityAutoConfiguration.class); |
|
|
|
this.context.register(SecurityAutoConfiguration.class); |
|
|
|
this.context.refresh(); |
|
|
|
this.context.refresh(); |
|
|
|
UserDetailsService manager = this.context.getBean(UserDetailsService.class); |
|
|
|
UserDetailsService manager = this.context.getBean(UserDetailsService.class); |
|
|
|
assertThat(this.outputCapture.toString()).contains("Using default security password:"); |
|
|
|
assertThat(this.outputCapture.toString()) |
|
|
|
|
|
|
|
.contains("Using default security password:"); |
|
|
|
assertThat(manager.loadUserByUsername("user")).isNotNull(); |
|
|
|
assertThat(manager.loadUserByUsername("user")).isNotNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void defaultUserNotCreatedIfAuthenticationManagerBeanPresent() throws Exception { |
|
|
|
public void defaultUserNotCreatedIfAuthenticationManagerBeanPresent() |
|
|
|
|
|
|
|
throws Exception { |
|
|
|
this.context = new AnnotationConfigWebApplicationContext(); |
|
|
|
this.context = new AnnotationConfigWebApplicationContext(); |
|
|
|
this.context.setServletContext(new MockServletContext()); |
|
|
|
this.context.setServletContext(new MockServletContext()); |
|
|
|
this.context.register(TestAuthenticationManagerConfiguration.class, |
|
|
|
this.context.register(TestAuthenticationManagerConfiguration.class, |
|
|
|
@ -181,13 +183,11 @@ public class SecurityAutoConfigurationTests { |
|
|
|
PropertyPlaceholderAutoConfiguration.class); |
|
|
|
PropertyPlaceholderAutoConfiguration.class); |
|
|
|
this.context.refresh(); |
|
|
|
this.context.refresh(); |
|
|
|
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class); |
|
|
|
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class); |
|
|
|
assertThat(manager) |
|
|
|
assertThat(manager).isEqualTo(this.context.getBean( |
|
|
|
.isEqualTo(this.context.getBean( |
|
|
|
TestAuthenticationManagerConfiguration.class).authenticationManager); |
|
|
|
TestAuthenticationManagerConfiguration.class).authenticationManager); |
|
|
|
|
|
|
|
assertThat(this.outputCapture.toString()) |
|
|
|
assertThat(this.outputCapture.toString()) |
|
|
|
.doesNotContain("Using default security password: "); |
|
|
|
.doesNotContain("Using default security password: "); |
|
|
|
TestingAuthenticationToken token = new TestingAuthenticationToken( |
|
|
|
TestingAuthenticationToken token = new TestingAuthenticationToken("foo", "bar"); |
|
|
|
"foo", "bar"); |
|
|
|
|
|
|
|
assertThat(manager.authenticate(token)).isNotNull(); |
|
|
|
assertThat(manager.authenticate(token)).isNotNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -199,25 +199,27 @@ public class SecurityAutoConfigurationTests { |
|
|
|
SecurityAutoConfiguration.class, |
|
|
|
SecurityAutoConfiguration.class, |
|
|
|
PropertyPlaceholderAutoConfiguration.class); |
|
|
|
PropertyPlaceholderAutoConfiguration.class); |
|
|
|
this.context.refresh(); |
|
|
|
this.context.refresh(); |
|
|
|
UserDetailsService userDetailsService = this.context.getBean(UserDetailsService.class); |
|
|
|
UserDetailsService userDetailsService = this.context |
|
|
|
|
|
|
|
.getBean(UserDetailsService.class); |
|
|
|
assertThat(this.outputCapture.toString()) |
|
|
|
assertThat(this.outputCapture.toString()) |
|
|
|
.doesNotContain("Using default security password: "); |
|
|
|
.doesNotContain("Using default security password: "); |
|
|
|
assertThat(userDetailsService.loadUserByUsername("foo")).isNotNull(); |
|
|
|
assertThat(userDetailsService.loadUserByUsername("foo")).isNotNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void defaultUserNotCreatedIfAuthenticationProviderBeanPresent() throws Exception { |
|
|
|
public void defaultUserNotCreatedIfAuthenticationProviderBeanPresent() |
|
|
|
|
|
|
|
throws Exception { |
|
|
|
this.context = new AnnotationConfigWebApplicationContext(); |
|
|
|
this.context = new AnnotationConfigWebApplicationContext(); |
|
|
|
this.context.setServletContext(new MockServletContext()); |
|
|
|
this.context.setServletContext(new MockServletContext()); |
|
|
|
this.context.register(TestAuthenticationProviderConfiguration.class, |
|
|
|
this.context.register(TestAuthenticationProviderConfiguration.class, |
|
|
|
SecurityAutoConfiguration.class, |
|
|
|
SecurityAutoConfiguration.class, |
|
|
|
PropertyPlaceholderAutoConfiguration.class); |
|
|
|
PropertyPlaceholderAutoConfiguration.class); |
|
|
|
this.context.refresh(); |
|
|
|
this.context.refresh(); |
|
|
|
AuthenticationProvider provider = this.context.getBean(AuthenticationProvider.class); |
|
|
|
AuthenticationProvider provider = this.context |
|
|
|
|
|
|
|
.getBean(AuthenticationProvider.class); |
|
|
|
assertThat(this.outputCapture.toString()) |
|
|
|
assertThat(this.outputCapture.toString()) |
|
|
|
.doesNotContain("Using default security password: "); |
|
|
|
.doesNotContain("Using default security password: "); |
|
|
|
TestingAuthenticationToken token = new TestingAuthenticationToken( |
|
|
|
TestingAuthenticationToken token = new TestingAuthenticationToken("foo", "bar"); |
|
|
|
"foo", "bar"); |
|
|
|
|
|
|
|
assertThat(provider.authenticate(token)).isNotNull(); |
|
|
|
assertThat(provider.authenticate(token)).isNotNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -311,7 +313,8 @@ public class SecurityAutoConfigurationTests { |
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public AuthenticationManager myAuthenticationManager() { |
|
|
|
public AuthenticationManager myAuthenticationManager() { |
|
|
|
AuthenticationProvider authenticationProvider = new TestingAuthenticationProvider(); |
|
|
|
AuthenticationProvider authenticationProvider = new TestingAuthenticationProvider(); |
|
|
|
this.authenticationManager = new ProviderManager(Collections.singletonList(authenticationProvider)); |
|
|
|
this.authenticationManager = new ProviderManager( |
|
|
|
|
|
|
|
Collections.singletonList(authenticationProvider)); |
|
|
|
return this.authenticationManager; |
|
|
|
return this.authenticationManager; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -322,7 +325,8 @@ public class SecurityAutoConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public InMemoryUserDetailsManager myUserDetailsService() { |
|
|
|
public InMemoryUserDetailsManager myUserDetailsService() { |
|
|
|
return new InMemoryUserDetailsManager(User.withUsername("foo").password("bar").roles("USER").build()); |
|
|
|
return new InMemoryUserDetailsManager( |
|
|
|
|
|
|
|
User.withUsername("foo").password("bar").roles("USER").build()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|