com.healthy.security.app.authentication.openid.OpenIdAuthenticationSecurityConfig Maven / Gradle / Ivy
package com.healthy.security.app.authentication.openid;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.security.SocialUserDetailsService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* OpenIdAuthenticationSecurityConfig
*
* @author xiaomingzhang
*/
@Component
public class OpenIdAuthenticationSecurityConfig
extends SecurityConfigurerAdapter {
@Resource
private AuthenticationSuccessHandler healthyAuthenticationSuccessHandler;
@Resource
private AuthenticationFailureHandler healthyAuthenticationFailureHandler;
@Resource
private SocialUserDetailsService socialUserDetailsService;
@Resource
private UsersConnectionRepository usersConnectionRepository;
@Override
public void configure(HttpSecurity http) {
OpenIdAuthenticationFilter openIdAuthenticationFilter = new OpenIdAuthenticationFilter();
openIdAuthenticationFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
openIdAuthenticationFilter.setAuthenticationSuccessHandler(healthyAuthenticationSuccessHandler);
openIdAuthenticationFilter.setAuthenticationFailureHandler(healthyAuthenticationFailureHandler);
OpenIdAuthenticationProvider openIdAuthenticationProvider = new OpenIdAuthenticationProvider();
openIdAuthenticationProvider.setUserDetailsService(socialUserDetailsService);
openIdAuthenticationProvider.setUsersConnectionRepository(usersConnectionRepository);
http.authenticationProvider(openIdAuthenticationProvider).addFilterAfter(openIdAuthenticationFilter,
UsernamePasswordAuthenticationFilter.class);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy