mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-13 22:09:00 +08:00
Merge branch 'jdk8-dev'
This commit is contained in:
commit
ca44b061b1
2 files changed
+14
-16
No files matched your search
+1
-1
@@ -47,7 +47,7 @@ public class GlobalExceptionConfiguration implements ErrorWebExceptionHandler {
|
|||||||
return response.writeWith(Mono.fromSupplier(() -> {
|
return response.writeWith(Mono.fromSupplier(() -> {
|
||||||
DataBufferFactory bufferFactory = response.bufferFactory();
|
DataBufferFactory bufferFactory = response.bufferFactory();
|
||||||
try {
|
try {
|
||||||
log.error("Error rquest :{} Error Spring Cloud Gateway : {}", exchange.getRequest().getPath(),
|
log.error("Error request :{} Error Spring Cloud Gateway : {}", exchange.getRequest().getPath(),
|
||||||
ex.getMessage());
|
ex.getMessage());
|
||||||
return bufferFactory.wrap(objectMapper.writeValueAsBytes(R.failed(ex.getMessage())));
|
return bufferFactory.wrap(objectMapper.writeValueAsBytes(R.failed(ex.getMessage())));
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-15
@@ -57,27 +57,23 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户密码登录
|
* 用户密码登录
|
||||||
|
*
|
||||||
* @param username 用户密码登录
|
* @param username 用户密码登录
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public UserDetails loadUserByUsername(String username) {
|
public UserDetails loadUserByUsername(String username) {
|
||||||
if (!remoteAppUserServiceOptional.isPresent()) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS_MINI);
|
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS_MINI);
|
||||||
if (cache != null && cache.get(username) != null) {
|
if (Objects.nonNull(cache) && Objects.nonNull(cache.get(username))) {
|
||||||
return cache.get(username, PigxUser.class);
|
AppUserInfo appUserInfo = cache.get(username, AppUserInfo.class);
|
||||||
|
return getUserDetailsAppUser(R.ok(appUserInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
R<AppUserInfo> info = remoteAppUserServiceOptional.get().info(username);
|
R<AppUserInfo> result = remoteAppUserServiceOptional.get().info(username);
|
||||||
UserDetails userDetailsAppUser = this.getUserDetailsAppUser(info);
|
Optional<AppUserInfo> userInfoOptional = RetOps.of(result).getData();
|
||||||
if (cache != null) {
|
userInfoOptional.ifPresent(userInfo -> Objects.requireNonNull(cache).put(username, userInfo));
|
||||||
cache.put(username, userDetailsAppUser);
|
return getUserDetailsAppUser(result);
|
||||||
}
|
|
||||||
return userDetailsAppUser;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,7 +84,7 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ
|
|||||||
UserDetails getUserDetailsAppUser(R<AppUserInfo> result) {
|
UserDetails getUserDetailsAppUser(R<AppUserInfo> result) {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
return RetOps.of(result)
|
return RetOps.of(result)
|
||||||
.assertSuccess(r -> new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.SERVER_ERROR, "用户信息获取失败",null)))
|
.assertSuccess(r -> new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.SERVER_ERROR, "用户信息获取失败",null)))
|
||||||
.getData()
|
.getData()
|
||||||
.map(this::convertUserDetailsAppUser)
|
.map(this::convertUserDetailsAppUser)
|
||||||
.orElseThrow(() -> new UsernameNotFoundException("用户不存在"));
|
.orElseThrow(() -> new UsernameNotFoundException("用户不存在"));
|
||||||
@@ -97,6 +93,7 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* UserInfo 转 UserDetails
|
* UserInfo 转 UserDetails
|
||||||
|
*
|
||||||
* @param info
|
* @param info
|
||||||
* @return 返回UserDetails对象
|
* @return 返回UserDetails对象
|
||||||
*/
|
*/
|
||||||
@@ -110,7 +107,7 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ
|
|||||||
|
|
||||||
}
|
}
|
||||||
Collection<? extends GrantedAuthority> authorities = AuthorityUtils
|
Collection<? extends GrantedAuthority> authorities = AuthorityUtils
|
||||||
.createAuthorityList(dbAuthsSet.toArray(new String[0]));
|
.createAuthorityList(dbAuthsSet.toArray(new String[0]));
|
||||||
AppUser user = info.getAppUser();
|
AppUser user = info.getAppUser();
|
||||||
// 构造security用户
|
// 构造security用户
|
||||||
|
|
||||||
@@ -127,7 +124,8 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 支持所有的 mobile 类型
|
* 支持所有的 mobile 类型
|
||||||
* @param clientId 目标客户端
|
*
|
||||||
|
* @param clientId 目标客户端
|
||||||
* @param grantType 授权类型
|
* @param grantType 授权类型
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in new issue
Block a user