|
|
package cn.mb.cloud.auth.security.social;
|
|
import cn.mb.cloud.auth.security.component.ResourceAuthExceptionEntryPoint;
|
import cn.mb.cloud.auth.security.service.MbCloudUserAuthDetailsService;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
import lombok.Getter;
|
import lombok.Setter;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.security.authentication.AuthenticationEventPublisher;
|
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.AuthenticationSuccessHandler;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* @author jason
|
* 手机号登录配置入口
|
*/
|
@Getter
|
@Setter
|
@Component
|
public class SocialSecurityConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
|
@Autowired
|
private ObjectMapper objectMapper;
|
@Autowired
|
private AuthenticationEventPublisher defaultAuthenticationEventPublisher;
|
private AuthenticationSuccessHandler mobileLoginSuccessHandler;
|
private MbCloudUserAuthDetailsService userDetailsService;
|
|
@Override
|
public void configure(HttpSecurity http) {
|
SocialAuthenticationFilter mobileAuthenticationFilter = new SocialAuthenticationFilter();
|
mobileAuthenticationFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
|
mobileAuthenticationFilter.setAuthenticationSuccessHandler(mobileLoginSuccessHandler);
|
mobileAuthenticationFilter.setEventPublisher(defaultAuthenticationEventPublisher);
|
mobileAuthenticationFilter.setAuthenticationEntryPoint(new ResourceAuthExceptionEntryPoint(objectMapper));
|
|
SocialAuthenticationProvider mobileAuthenticationProvider = new SocialAuthenticationProvider();
|
mobileAuthenticationProvider.setUserDetailsService(userDetailsService);
|
http.authenticationProvider(mobileAuthenticationProvider)
|
.addFilterAfter(mobileAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
|
}
|
}
|