mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
✨ Introducing new features. 增加APP手机登录或者社区账号登录逻辑
This commit is contained in:
1 parent
8b0e4ccbe5
commit
28c2affaa7
1 file changed
+58
+58
@@ -0,0 +1,58 @@
|
||||
package com.pig4cloud.pigx.common.security.service;
|
||||
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteUserService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class PigxMobileUserDetailServiceImpl implements PigxUserDetailsService {
|
||||
|
||||
private final UserDetailsService pigxDefaultUserDetailsServiceImpl;
|
||||
private final RemoteUserService remoteUserService;
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public UserDetails loadUserByUsername(String phone) {
|
||||
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
|
||||
if (cache != null && cache.get(phone) != null) {
|
||||
return cache.get(phone, PigxUser.class);
|
||||
}
|
||||
|
||||
R<UserInfo> result = remoteUserService.social(phone, SecurityConstants.FROM_IN);
|
||||
|
||||
UserDetails userDetails = getUserDetails(result);
|
||||
if (cache != null) {
|
||||
cache.put(phone, userDetails);
|
||||
}
|
||||
return getUserDetails(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUser(PigxUser pigxUser) {
|
||||
return pigxDefaultUserDetailsServiceImpl.loadUserByUsername(pigxUser.getUsername());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支持所有的 mobile 类型
|
||||
*
|
||||
* @param clientId 目标客户端
|
||||
* @param grantType 授权类型
|
||||
* @return true/false
|
||||
*/
|
||||
@Override
|
||||
public boolean support(String clientId, String grantType) {
|
||||
return SecurityConstants.GRANT_MOBILE.equals(grantType) && !clientId.equals("app");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user