访客接口,对指定用户下线功能-1
This commit is contained in:
1 parent
fe87379564
commit
3ab0cbef40
13 files changed
+309
-21
No files matched your search
@@ -74,10 +74,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -320,9 +317,14 @@ public class PjcloudTokenEndpoint {
|
||||
}).filter(tokenVo -> {
|
||||
// 根据用户名过滤
|
||||
String username = MapUtil.getStr(params, SecurityConstants.DETAILS_USERNAME);
|
||||
// Long userId = MapUtil.getLong(params, SecurityConstants.USER_ID);
|
||||
if (StrUtil.isBlank(username)) {
|
||||
return true;
|
||||
}
|
||||
// if (null==userId) {
|
||||
// return true;
|
||||
// }
|
||||
// return tokenVo.getUserId().equals(userId);
|
||||
return tokenVo.getUsername().contains(username);
|
||||
}).collect(Collectors.toList());
|
||||
result.setRecords(tokenVoList);
|
||||
@@ -330,6 +332,53 @@ public class PjcloudTokenEndpoint {
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动端下线
|
||||
* token查询
|
||||
* @return
|
||||
*/
|
||||
@Inner
|
||||
@PostMapping("/selectTokenByUserId")
|
||||
public R<List<TokenVO>> tokenList(@RequestParam("userId")Long userId,@RequestParam("clientId")String clientId) {
|
||||
// 根据分页参数获取对应数据
|
||||
String key = String.format("%s::%s::*", tenantKeyStrResolver.key(), CacheConstants.PROJECT_OAUTH_ACCESS);
|
||||
Set<String> keys = redisTemplate.keys(key);
|
||||
|
||||
List<TokenVO> tokenVoList = redisTemplate.opsForValue().multiGet(new ArrayList<>(keys)).stream().map(obj -> {
|
||||
OAuth2Authorization authorization = (OAuth2Authorization) obj;
|
||||
TokenVO tokenVo = new TokenVO();
|
||||
tokenVo.setClientId(authorization.getRegisteredClientId());
|
||||
tokenVo.setId(authorization.getId());
|
||||
tokenVo.setUsername(authorization.getPrincipalName());
|
||||
OAuth2Authorization.Token<OAuth2AccessToken> accessToken = authorization.getAccessToken();
|
||||
tokenVo.setAccessToken(accessToken.getToken().getTokenValue());
|
||||
|
||||
String expiresAt = TemporalAccessorUtil.format(accessToken.getToken().getExpiresAt(),
|
||||
DatePattern.NORM_DATETIME_PATTERN);
|
||||
tokenVo.setExpiresAt(expiresAt);
|
||||
|
||||
String issuedAt = TemporalAccessorUtil.format(accessToken.getToken().getIssuedAt(),
|
||||
DatePattern.NORM_DATETIME_PATTERN);
|
||||
tokenVo.setIssuedAt(issuedAt);
|
||||
|
||||
Map<String, Object> attributes = authorization.getAttributes();
|
||||
Authentication authentication = (Authentication) attributes.get(Principal.class.getName());
|
||||
|
||||
if (Objects.isNull(authentication)) {
|
||||
return tokenVo;
|
||||
}
|
||||
|
||||
PjcloudUser pjcloudUser = (PjcloudUser) authentication.getPrincipal();
|
||||
tokenVo.setUserId(pjcloudUser.getId());
|
||||
return tokenVo;
|
||||
}).filter(tokenVo -> {
|
||||
return tokenVo.getUserId().equals(userId) && tokenVo.getClientId().equals(clientId);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return R.ok(tokenVoList);
|
||||
}
|
||||
|
||||
@Inner
|
||||
@GetMapping("/query-token")
|
||||
public R queryToken(String token) {
|
||||
|
||||
Reference in new issue
Block a user