|
|
|
@ -75,13 +75,18 @@ public class AccessTokenService extends BaseService {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* create token |
|
|
|
|
* |
|
|
|
|
* @param loginUser |
|
|
|
|
* @param userId token for user |
|
|
|
|
* @param expireTime token expire time |
|
|
|
|
* @param token token string |
|
|
|
|
* @return create result code |
|
|
|
|
*/ |
|
|
|
|
public Map<String, Object> createToken(int userId, String expireTime, String token) { |
|
|
|
|
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)){ |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (userId <= 0) { |
|
|
|
|
throw new IllegalArgumentException("User id should not less than or equals to 0."); |
|
|
|
@ -107,12 +112,17 @@ public class AccessTokenService extends BaseService {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* generate token |
|
|
|
|
* |
|
|
|
|
* @param loginUser |
|
|
|
|
* @param userId token for user |
|
|
|
|
* @param expireTime token expire time |
|
|
|
|
* @return token string |
|
|
|
|
*/ |
|
|
|
|
public Map<String, Object> generateToken(int userId, String expireTime) { |
|
|
|
|
public Map<String, Object> generateToken(User loginUser, int userId, String expireTime) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(5); |
|
|
|
|
if(check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)){ |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
String token = EncryptionUtils.getMd5(userId + expireTime + String.valueOf(System.currentTimeMillis())); |
|
|
|
|
result.put(Constants.DATA_LIST, token); |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
@ -128,6 +138,10 @@ public class AccessTokenService extends BaseService {
|
|
|
|
|
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) { |
|
|
|
@ -149,15 +163,20 @@ public class AccessTokenService extends BaseService {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* update token by id |
|
|
|
|
* |
|
|
|
|
* @param loginUser |
|
|
|
|
* @param id token id |
|
|
|
|
* @param userId token for user |
|
|
|
|
* @param expireTime token expire time |
|
|
|
|
* @param token token string |
|
|
|
|
* @return update result code |
|
|
|
|
*/ |
|
|
|
|
public Map<String, Object> updateToken(int id,int userId, String expireTime, String token) { |
|
|
|
|
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)){ |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
AccessToken accessToken = accessTokenMapper.selectById(id); |
|
|
|
|
if (accessToken == null) { |
|
|
|
|
logger.error("access token not exist, access token id {}", id); |
|
|
|
|