JAVA-14884 Update spring-security-social-login under spring-security-modules to remove usage of deprecated WebSecurityConfigurerAdapter (#13011)
This commit is contained in:
parent
447b0d2f03
commit
178aed574e
@ -5,11 +5,12 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
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.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.social.connect.ConnectionFactoryLocator;
|
import org.springframework.social.connect.ConnectionFactoryLocator;
|
||||||
import org.springframework.social.connect.UsersConnectionRepository;
|
import org.springframework.social.connect.UsersConnectionRepository;
|
||||||
import org.springframework.social.connect.mem.InMemoryUsersConnectionRepository;
|
import org.springframework.social.connect.mem.InMemoryUsersConnectionRepository;
|
||||||
@ -23,7 +24,7 @@ import com.baeldung.security.FacebookSignInAdapter;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@ComponentScan(basePackages = { "com.baeldung.security" })
|
@ComponentScan(basePackages = { "com.baeldung.security" })
|
||||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
public class SecurityConfig {
|
||||||
|
|
||||||
@Value("${spring.social.facebook.appSecret}")
|
@Value("${spring.social.facebook.appSecret}")
|
||||||
String appSecret;
|
String appSecret;
|
||||||
@ -37,24 +38,31 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private FacebookConnectionSignup facebookConnectionSignup;
|
private FacebookConnectionSignup facebookConnectionSignup;
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
public AuthenticationManager authManager(HttpSecurity http) throws Exception {
|
||||||
auth.userDetailsService(userDetailsService);
|
return http.getSharedObject(AuthenticationManagerBuilder.class)
|
||||||
|
.userDetailsService(userDetailsService)
|
||||||
|
.and()
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(final HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
// @formatter:off
|
http.csrf()
|
||||||
http
|
.disable()
|
||||||
.csrf().disable()
|
.authorizeRequests()
|
||||||
.authorizeRequests()
|
.antMatchers("/login*", "/signin/**", "/signup/**")
|
||||||
.antMatchers("/login*","/signin/**","/signup/**").permitAll()
|
.permitAll()
|
||||||
.anyRequest().authenticated()
|
.anyRequest()
|
||||||
.and()
|
.authenticated()
|
||||||
.formLogin().loginPage("/login").permitAll()
|
.and()
|
||||||
.and()
|
.formLogin()
|
||||||
.logout();
|
.loginPage("/login")
|
||||||
} // @formatter:on
|
.permitAll()
|
||||||
|
.and()
|
||||||
|
.logout();
|
||||||
|
return http.build();
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
// @Primary
|
// @Primary
|
||||||
|
@ -29,6 +29,6 @@ public class MyUserDetailsService implements UserDetailsService {
|
|||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new UsernameNotFoundException(username);
|
throw new UsernameNotFoundException(username);
|
||||||
}
|
}
|
||||||
return new org.springframework.security.core.userdetails.User(username, user.getPassword(), true, true, true, true, Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")));
|
return new org.springframework.security.core.userdetails.User(username, "{noop}" + user.getPassword(), true, true, true, true, Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user