Skip to content

Commit

Permalink
modify general user can't create,delete,update token (#3538)
Browse files Browse the repository at this point in the history
Co-authored-by: qiaozhanwei <qiaozhanwei@analysys.com.cn>
  • Loading branch information
qiaozhanwei and qiaozhanwei committed Aug 18, 2020
1 parent 0505ebf commit b8a9e2e
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public Map<String, Object> queryAccessTokenList(User loginUser, String searchVal
*/
public Map<String, Object> createToken(User loginUser, int userId, String expireTime, String token) {
Map<String, Object> result = new HashMap<>(5);
if(check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)){

if (!hasPerm(loginUser,userId)){
putMsg(result, Status.USER_NO_OPERATION_PERM);
return result;
}

Expand Down Expand Up @@ -140,10 +142,6 @@ public Map<String, Object> generateToken(User loginUser, int userId, String expi
public Map<String, Object> delAccessTokenById(User loginUser, int id) {
Map<String, Object> result = new HashMap<>(5);

if(check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)){
return result;
}

AccessToken accessToken = accessTokenMapper.selectById(id);

if (accessToken == null) {
Expand All @@ -152,8 +150,7 @@ public Map<String, Object> delAccessTokenById(User loginUser, int id) {
return result;
}

if (loginUser.getId() != accessToken.getUserId() &&
loginUser.getUserType() != UserType.ADMIN_USER) {
if (!hasPerm(loginUser,accessToken.getUserId())){
putMsg(result, Status.USER_NO_OPERATION_PERM);
return result;
}
Expand All @@ -176,9 +173,11 @@ public Map<String, Object> delAccessTokenById(User loginUser, int id) {
public Map<String, Object> updateToken(User loginUser, int id, int userId, String expireTime, String token) {
Map<String, Object> result = new HashMap<>(5);

if(check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)){
if (!hasPerm(loginUser,userId)){
putMsg(result, Status.USER_NO_OPERATION_PERM);
return result;
}

AccessToken accessToken = accessTokenMapper.selectById(id);
if (accessToken == null) {
logger.error("access token not exist, access token id {}", id);
Expand Down

0 comments on commit b8a9e2e

Please sign in to comment.