|
|
@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.security;
|
|
|
|
package org.springframework.boot.autoconfigure.security;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.DispatcherType;
|
|
|
|
import javax.servlet.DispatcherType;
|
|
|
@ -38,29 +39,27 @@ import org.springframework.context.ApplicationListener;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
|
|
|
|
import org.springframework.mock.web.MockServletContext;
|
|
|
|
import org.springframework.mock.web.MockServletContext;
|
|
|
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
|
|
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
|
|
import org.springframework.security.authentication.AuthenticationProvider;
|
|
|
|
|
|
|
|
import org.springframework.security.authentication.ProviderManager;
|
|
|
|
|
|
|
|
import org.springframework.security.authentication.TestingAuthenticationProvider;
|
|
|
|
import org.springframework.security.authentication.TestingAuthenticationToken;
|
|
|
|
import org.springframework.security.authentication.TestingAuthenticationToken;
|
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
|
|
|
|
|
import org.springframework.security.authentication.event.AbstractAuthenticationEvent;
|
|
|
|
import org.springframework.security.authentication.event.AbstractAuthenticationEvent;
|
|
|
|
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent;
|
|
|
|
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
|
|
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
|
|
import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter;
|
|
|
|
|
|
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
|
|
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
|
import org.springframework.security.core.authority.AuthorityUtils;
|
|
|
|
import org.springframework.security.core.userdetails.User;
|
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
|
import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension;
|
|
|
|
import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension;
|
|
|
|
|
|
|
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
|
|
|
import org.springframework.security.web.FilterChainProxy;
|
|
|
|
import org.springframework.security.web.FilterChainProxy;
|
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
|
|
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Tests for {@link SecurityAutoConfiguration}.
|
|
|
|
* Tests for {@link SecurityAutoConfiguration}.
|
|
|
@ -68,6 +67,7 @@ import static org.junit.Assert.fail;
|
|
|
|
* @author Dave Syer
|
|
|
|
* @author Dave Syer
|
|
|
|
* @author Rob Winch
|
|
|
|
* @author Rob Winch
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
|
|
|
|
* @author Madhura Bhave
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class SecurityAutoConfigurationTests {
|
|
|
|
public class SecurityAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
@ -147,120 +147,78 @@ public class SecurityAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testDisableIgnoredStaticApplicationPaths() throws Exception {
|
|
|
|
public void testEventPublisherInjected() throws Exception {
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
|
|
|
|
this.context.register(SecurityAutoConfiguration.class,
|
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
|
|
|
|
TestPropertyValues.of("security.ignored:none").applyTo(this.context);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
// Just the application endpoints now
|
|
|
|
|
|
|
|
assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains())
|
|
|
|
|
|
|
|
.hasSize(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testAuthenticationManagerCreated() throws Exception {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.register(SecurityAutoConfiguration.class,
|
|
|
|
this.context.register(TestAuthenticationManagerConfiguration.class, SecurityAutoConfiguration.class,
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
assertThat(this.context.getBean(AuthenticationManager.class)).isNotNull();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testEventPublisherInjected() throws Exception {
|
|
|
|
|
|
|
|
testAuthenticationManagerCreated();
|
|
|
|
|
|
|
|
pingAuthenticationListener();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void pingAuthenticationListener() {
|
|
|
|
|
|
|
|
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);
|
|
|
|
try {
|
|
|
|
manager.authenticate(new TestingAuthenticationToken("foo", "wrong"));
|
|
|
|
manager.authenticate(new UsernamePasswordAuthenticationToken("foo", "wrong"));
|
|
|
|
|
|
|
|
fail("Expected BadCredentialsException");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (BadCredentialsException e) {
|
|
|
|
|
|
|
|
// expected
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThat(listener.event)
|
|
|
|
assertThat(listener.event)
|
|
|
|
.isInstanceOf(AuthenticationFailureBadCredentialsEvent.class);
|
|
|
|
.isInstanceOf(AuthenticationSuccessEvent.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testOverrideAuthenticationManager() throws Exception {
|
|
|
|
public void testDefaultUsernamePassword() throws Exception {
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.register(TestAuthenticationConfiguration.class,
|
|
|
|
this.context.register(SecurityAutoConfiguration.class);
|
|
|
|
SecurityAutoConfiguration.class,
|
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
assertThat(this.context.getBean(AuthenticationManager.class))
|
|
|
|
UserDetailsService manager = this.context.getBean(UserDetailsService.class);
|
|
|
|
.isEqualTo(this.context.getBean(
|
|
|
|
assertThat(this.outputCapture.toString()).contains("Using default security password:");
|
|
|
|
TestAuthenticationConfiguration.class).authenticationManager);
|
|
|
|
assertThat(manager.loadUserByUsername("user")).isNotNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testDefaultAuthenticationManagerMakesUserDetailsAvailable()
|
|
|
|
public void defaultUserNotCreatedIfAuthenticationManagerBeanPresent() throws Exception {
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.register(UserDetailsSecurityCustomizer.class,
|
|
|
|
this.context.register(TestAuthenticationManagerConfiguration.class,
|
|
|
|
SecurityAutoConfiguration.class,
|
|
|
|
SecurityAutoConfiguration.class,
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
assertThat(this.context.getBean(UserDetailsSecurityCustomizer.class)
|
|
|
|
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
|
|
|
|
.getUserDetails().loadUserByUsername("user")).isNotNull();
|
|
|
|
assertThat(manager)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testOverrideAuthenticationManagerAndInjectIntoSecurityFilter()
|
|
|
|
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
|
|
|
|
this.context.register(TestAuthenticationConfiguration.class,
|
|
|
|
|
|
|
|
SecurityCustomizer.class, SecurityAutoConfiguration.class,
|
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
assertThat(this.context.getBean(AuthenticationManager.class))
|
|
|
|
|
|
|
|
.isEqualTo(this.context.getBean(
|
|
|
|
.isEqualTo(this.context.getBean(
|
|
|
|
TestAuthenticationConfiguration.class).authenticationManager);
|
|
|
|
TestAuthenticationManagerConfiguration.class).authenticationManager);
|
|
|
|
|
|
|
|
assertThat(this.outputCapture.toString())
|
|
|
|
|
|
|
|
.doesNotContain("Using default security password: ");
|
|
|
|
|
|
|
|
TestingAuthenticationToken token = new TestingAuthenticationToken(
|
|
|
|
|
|
|
|
"foo", "bar");
|
|
|
|
|
|
|
|
assertThat(manager.authenticate(token)).isNotNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testOverrideAuthenticationManagerWithBuilderAndInjectIntoSecurityFilter()
|
|
|
|
public void defaultUserNotCreatedIfUserDetailsServiceBeanPresent() throws Exception {
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.register(AuthenticationManagerCustomizer.class,
|
|
|
|
this.context.register(TestUserDetailsServiceConfiguration.class,
|
|
|
|
SecurityCustomizer.class, SecurityAutoConfiguration.class,
|
|
|
|
SecurityAutoConfiguration.class,
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
|
|
|
|
UserDetailsService userDetailsService = this.context.getBean(UserDetailsService.class);
|
|
|
|
"foo", "bar",
|
|
|
|
assertThat(this.outputCapture.toString())
|
|
|
|
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
|
|
|
|
.doesNotContain("Using default security password: ");
|
|
|
|
assertThat(this.context.getBean(AuthenticationManager.class).authenticate(user))
|
|
|
|
assertThat(userDetailsService.loadUserByUsername("foo")).isNotNull();
|
|
|
|
.isNotNull();
|
|
|
|
|
|
|
|
pingAuthenticationListener();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testOverrideAuthenticationManagerWithBuilderAndInjectBuilderIntoSecurityFilter()
|
|
|
|
public void defaultUserNotCreatedIfAuthenticationProviderBeanPresent() throws Exception {
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.register(AuthenticationManagerCustomizer.class,
|
|
|
|
this.context.register(TestAuthenticationProviderConfiguration.class,
|
|
|
|
WorkaroundSecurityCustomizer.class, SecurityAutoConfiguration.class,
|
|
|
|
SecurityAutoConfiguration.class,
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
|
|
|
|
AuthenticationProvider provider = this.context.getBean(AuthenticationProvider.class);
|
|
|
|
"foo", "bar",
|
|
|
|
assertThat(this.outputCapture.toString())
|
|
|
|
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
|
|
|
|
.doesNotContain("Using default security password: ");
|
|
|
|
assertThat(this.context.getBean(AuthenticationManager.class).authenticate(user))
|
|
|
|
TestingAuthenticationToken token = new TestingAuthenticationToken(
|
|
|
|
.isNotNull();
|
|
|
|
"foo", "bar");
|
|
|
|
|
|
|
|
assertThat(provider.authenticate(token)).isNotNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -279,41 +237,11 @@ public class SecurityAutoConfigurationTests {
|
|
|
|
assertThat(this.context.getBean(JpaTransactionManager.class)).isNotNull();
|
|
|
|
assertThat(this.context.getBean(JpaTransactionManager.class)).isNotNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testDefaultUsernamePassword() throws Exception {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
|
|
|
|
this.context.register(SecurityAutoConfiguration.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
String password = this.outputCapture.toString()
|
|
|
|
|
|
|
|
.split("Using default security password: ")[1].split("\n")[0].trim();
|
|
|
|
|
|
|
|
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
|
|
|
|
|
|
|
|
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
|
|
|
|
|
|
|
|
"user", password);
|
|
|
|
|
|
|
|
assertThat(manager.authenticate(token)).isNotNull();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testCustomAuthenticationDoesNotCreateDefaultUser() throws Exception {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
|
|
|
|
this.context.register(AuthenticationManagerCustomizer.class,
|
|
|
|
|
|
|
|
SecurityAutoConfiguration.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
|
|
|
|
|
|
|
|
assertThat(this.outputCapture.toString())
|
|
|
|
|
|
|
|
.doesNotContain("Using default security password: ");
|
|
|
|
|
|
|
|
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
|
|
|
|
|
|
|
|
"foo", "bar");
|
|
|
|
|
|
|
|
assertThat(manager.authenticate(token)).isNotNull();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testSecurityEvaluationContextExtensionSupport() {
|
|
|
|
public void testSecurityEvaluationContextExtensionSupport() {
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
this.context.register(AuthenticationManagerCustomizer.class,
|
|
|
|
this.context.register(SecurityAutoConfiguration.class);
|
|
|
|
SecurityAutoConfiguration.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
assertThat(this.context.getBean(SecurityEvaluationContextExtension.class))
|
|
|
|
assertThat(this.context.getBean(SecurityEvaluationContextExtension.class))
|
|
|
|
.isNotNull();
|
|
|
|
.isNotNull();
|
|
|
@ -376,76 +304,35 @@ public class SecurityAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
protected static class TestAuthenticationConfiguration {
|
|
|
|
protected static class TestAuthenticationManagerConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
private AuthenticationManager authenticationManager;
|
|
|
|
private AuthenticationManager authenticationManager;
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public AuthenticationManager myAuthenticationManager() {
|
|
|
|
public AuthenticationManager myAuthenticationManager() {
|
|
|
|
this.authenticationManager = (
|
|
|
|
AuthenticationProvider authenticationProvider = new TestingAuthenticationProvider();
|
|
|
|
authentication) -> new TestingAuthenticationToken("foo", "bar");
|
|
|
|
this.authenticationManager = new ProviderManager(Collections.singletonList(authenticationProvider));
|
|
|
|
return this.authenticationManager;
|
|
|
|
return this.authenticationManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
protected static class SecurityCustomizer extends WebSecurityConfigurerAdapter {
|
|
|
|
protected static class TestUserDetailsServiceConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
final AuthenticationManager authenticationManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected SecurityCustomizer(AuthenticationManager authenticationManager) {
|
|
|
|
|
|
|
|
this.authenticationManager = authenticationManager;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
|
|
|
protected static class WorkaroundSecurityCustomizer
|
|
|
|
|
|
|
|
extends WebSecurityConfigurerAdapter {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final AuthenticationManagerBuilder builder;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
|
|
|
private AuthenticationManager authenticationManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected WorkaroundSecurityCustomizer(AuthenticationManagerBuilder builder) {
|
|
|
|
|
|
|
|
this.builder = builder;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void configure(HttpSecurity http) throws Exception {
|
|
|
|
|
|
|
|
this.authenticationManager = (authentication) -> this.builder.getOrBuild()
|
|
|
|
|
|
|
|
.authenticate(authentication);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
|
|
|
@Order(-1)
|
|
|
|
|
|
|
|
protected static class AuthenticationManagerCustomizer
|
|
|
|
|
|
|
|
extends GlobalAuthenticationConfigurerAdapter {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Bean
|
|
|
|
public void init(AuthenticationManagerBuilder auth) throws Exception {
|
|
|
|
public InMemoryUserDetailsManager myUserDetailsService() {
|
|
|
|
auth.inMemoryAuthentication().withUser("foo").password("bar").roles("USER");
|
|
|
|
return new InMemoryUserDetailsManager(User.withUsername("foo").password("bar").roles("USER").build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
protected static class UserDetailsSecurityCustomizer
|
|
|
|
protected static class TestAuthenticationProviderConfiguration {
|
|
|
|
extends WebSecurityConfigurerAdapter {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private UserDetailsService userDetails;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void configure(HttpSecurity http) throws Exception {
|
|
|
|
|
|
|
|
this.userDetails = http.getSharedObject(UserDetailsService.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UserDetailsService getUserDetails() {
|
|
|
|
@Bean
|
|
|
|
return this.userDetails;
|
|
|
|
public AuthenticationProvider myauthenticationProvider() {
|
|
|
|
|
|
|
|
return new TestingAuthenticationProvider();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|