mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-22 20:54:26 +08:00
feat(PreAuthenticatedUserDetailsService.java):刷新token再次认证的UserDetailsService根据客户端ID区分用户体系,根据认证方式区分方法调用。
This commit is contained in:
parent
2d9a00c332
commit
ec2cedacbc
@ -120,11 +120,15 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
|
||||
tokenServices.setClientDetailsService(clientDetailsService);
|
||||
tokenServices.setTokenEnhancer(tokenEnhancerChain);
|
||||
|
||||
PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider();
|
||||
|
||||
// 多用户体系下,刷新token再次认证客户端ID和 UserDetailService 的映射Map
|
||||
Map<String, UserDetailsService> clientUserDetailsServiceMap = new HashMap<>();
|
||||
clientUserDetailsServiceMap.put(AuthConstants.ADMIN_CLIENT_ID, sysUserDetailsService);
|
||||
clientUserDetailsServiceMap.put(AuthConstants.APP_CLIENT_ID, memberUserDetailsService);
|
||||
clientUserDetailsServiceMap.put(AuthConstants.WEAPP_CLIENT_ID, memberUserDetailsService);
|
||||
|
||||
// 重写刷新token再次认证的 AuthenticationManager中 的 UserDetailService,根据客户端ID和认证方式获取用户认证信息 UserDetails
|
||||
PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider();
|
||||
provider.setPreAuthenticatedUserDetailsService(new PreAuthenticatedUserDetailsService<>(clientUserDetailsServiceMap));
|
||||
tokenServices.setAuthenticationManager(new ProviderManager(Arrays.asList(provider)));
|
||||
return tokenServices;
|
||||
|
@ -16,7 +16,7 @@ import org.springframework.util.Assert;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* UserDetailsService 工厂类
|
||||
* 刷新token再次认证 UserDetailsService
|
||||
*
|
||||
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
|
||||
* @date 2021/10/2
|
||||
@ -49,6 +49,14 @@ public class PreAuthenticatedUserDetailsService<T extends Authentication> implem
|
||||
default:
|
||||
return memberUserDetailsService.loadUserByUsername(authentication.getName());
|
||||
}
|
||||
} else if (clientId.equals(AuthConstants.WEAPP_CLIENT_ID)) {
|
||||
MemberUserDetailsServiceImpl memberUserDetailsService = (MemberUserDetailsServiceImpl) userDetailsService;
|
||||
switch (authenticationMethodEnum) {
|
||||
case MOBILE:
|
||||
return memberUserDetailsService.loadUserByMobile(authentication.getName());
|
||||
default:
|
||||
return memberUserDetailsService.loadUserByUsername(authentication.getName());
|
||||
}
|
||||
} else if (clientId.equals(AuthConstants.ADMIN_CLIENT_ID)) {
|
||||
switch (authenticationMethodEnum) {
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user