代码调整
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.njcn.auth.config;
|
||||
|
||||
import com.njcn.auth.security.sm4.Sm4AuthenticationProvider;
|
||||
import com.njcn.auth.security.provider.Sm4AuthenticationProvider;
|
||||
import com.njcn.auth.security.provider.SmsAuthenticationProvider;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -29,6 +30,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
private final Sm4AuthenticationProvider sm4AuthenticationProvider;
|
||||
|
||||
private final SmsAuthenticationProvider smsAuthenticationProvider;
|
||||
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
@@ -63,21 +66,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户名密码认证授权提供者
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public DaoAuthenticationProvider daoAuthenticationProvider() {
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setUserDetailsService(sysUserDetailsService);
|
||||
provider.setPasswordEncoder(passwordEncoder());
|
||||
provider.setHideUserNotFoundExceptions(false); // 是否隐藏用户不存在异常,默认:true-隐藏;false-抛出异常;
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写父类自定义AuthenticationManager 将provider注入进去
|
||||
* 当然我们也可以考虑不重写 在父类的manager里面注入provider
|
||||
@@ -85,10 +73,24 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Bean
|
||||
@Override
|
||||
protected AuthenticationManager authenticationManager(){
|
||||
return new ProviderManager(sm4AuthenticationProvider);
|
||||
return new ProviderManager(sm4AuthenticationProvider,smsAuthenticationProvider);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户名密码认证授权提供者
|
||||
*/
|
||||
@Bean
|
||||
public DaoAuthenticationProvider daoAuthenticationProvider() {
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setUserDetailsService(sysUserDetailsService);
|
||||
provider.setPasswordEncoder(passwordEncoder());
|
||||
// 是否隐藏用户不存在异常,默认:true-隐藏;false-抛出异常;
|
||||
provider.setHideUserNotFoundExceptions(false);
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码编码器
|
||||
* <p>
|
||||
|
||||
Reference in New Issue
Block a user