|
|
|
@ -17,6 +17,7 @@
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.api.service.impl; |
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.AccessTokenService; |
|
|
|
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
|
|
|
@ -108,7 +109,7 @@ public class AccessTokenServiceImpl extends BaseServiceImpl implements AccessTok
|
|
|
|
|
* |
|
|
|
|
* @param userId token for user |
|
|
|
|
* @param expireTime token expire time |
|
|
|
|
* @param token token string |
|
|
|
|
* @param token token string (if it is absent, it will be automatically generated) |
|
|
|
|
* @return create result code |
|
|
|
|
*/ |
|
|
|
|
@SuppressWarnings("checkstyle:WhitespaceAround") |
|
|
|
@ -116,14 +117,23 @@ public class AccessTokenServiceImpl extends BaseServiceImpl implements AccessTok
|
|
|
|
|
public Map<String, Object> createToken(User loginUser, int userId, String expireTime, String token) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
// 1. check permission
|
|
|
|
|
if (!hasPerm(loginUser,userId)) { |
|
|
|
|
putMsg(result, Status.USER_NO_OPERATION_PERM); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2. check if user is existed
|
|
|
|
|
if (userId <= 0) { |
|
|
|
|
throw new IllegalArgumentException("User id should not less than or equals to 0."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 3. generate access token if absent
|
|
|
|
|
if (StringUtils.isBlank(token)) { |
|
|
|
|
token = EncryptionUtils.getMd5(userId + expireTime + System.currentTimeMillis()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 4. persist to the database
|
|
|
|
|
AccessToken accessToken = new AccessToken(); |
|
|
|
|
accessToken.setUserId(userId); |
|
|
|
|
accessToken.setExpireTime(DateUtils.stringToDate(expireTime)); |
|
|
|
@ -131,7 +141,6 @@ public class AccessTokenServiceImpl extends BaseServiceImpl implements AccessTok
|
|
|
|
|
accessToken.setCreateTime(new Date()); |
|
|
|
|
accessToken.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
|
|
// insert
|
|
|
|
|
int insert = accessTokenMapper.insert(accessToken); |
|
|
|
|
|
|
|
|
|
if (insert > 0) { |
|
|
|
|