🎨 Improving structure / format of the code.
This commit is contained in:
1 parent
31efcb669a
commit
f1a1291203
2 files changed
+47
-49
No files matched your search
+10
-10
@@ -13,16 +13,16 @@ import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
public enum YesNoEnum {
|
||||
|
||||
YES("1", "是"),
|
||||
NO("0", "否");
|
||||
YES("1", "是"), NO("0", "否");
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String desc;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String desc;
|
||||
}
|
||||
+37
-39
@@ -42,49 +42,47 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
@RequiredArgsConstructor
|
||||
public class PigxDefaultUserDetailsServiceImpl implements PigxUserDetailsService {
|
||||
|
||||
private final RemoteUserService remoteUserService;
|
||||
private final RemoteUserService remoteUserService;
|
||||
|
||||
private final CacheManager cacheManager;
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
/**
|
||||
* 用户密码登录
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return
|
||||
* @throws UsernameNotFoundException
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
|
||||
if (cache != null && cache.get(username) != null) {
|
||||
return cache.get(username, PigxUser.class);
|
||||
}
|
||||
/**
|
||||
* 用户密码登录
|
||||
* @param username 用户名
|
||||
* @return
|
||||
* @throws UsernameNotFoundException
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
|
||||
if (cache != null && cache.get(username) != null) {
|
||||
return cache.get(username, PigxUser.class);
|
||||
}
|
||||
|
||||
R<UserInfo> result = remoteUserService.info(username, SecurityConstants.FROM_IN);
|
||||
UserDetails userDetails = getUserDetails(result);
|
||||
cache.put(username, userDetails);
|
||||
return userDetails;
|
||||
}
|
||||
R<UserInfo> result = remoteUserService.info(username, SecurityConstants.FROM_IN);
|
||||
UserDetails userDetails = getUserDetails(result);
|
||||
cache.put(username, userDetails);
|
||||
return userDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户实体查询
|
||||
*
|
||||
* @param pigxUser user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public UserDetails loadUserByUser(PigxUser pigxUser) {
|
||||
// 避免 C端用户通过接口调用B端接口的安全问题
|
||||
if (UserTypeEnum.TOB.getStatus().equals(pigxUser.getUserType())) {
|
||||
return loadUserByUsername(pigxUser.getUsername());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 通过用户实体查询
|
||||
* @param pigxUser user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public UserDetails loadUserByUser(PigxUser pigxUser) {
|
||||
// 避免 C端用户通过接口调用B端接口的安全问题
|
||||
if (UserTypeEnum.TOB.getStatus().equals(pigxUser.getUserType())) {
|
||||
return loadUserByUsername(pigxUser.getUsername());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user