|
@@ -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<>();
|
|
|
|
|
|
+
|
|
|
if (!hasPerm(loginUser,userId)) {
|
|
|
putMsg(result, Status.USER_NO_OPERATION_PERM);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
if (userId <= 0) {
|
|
|
throw new IllegalArgumentException("User id should not less than or equals to 0.");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(token)) {
|
|
|
+ token = EncryptionUtils.getMd5(userId + expireTime + System.currentTimeMillis());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
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());
|
|
|
|
|
|
-
|
|
|
int insert = accessTokenMapper.insert(accessToken);
|
|
|
|
|
|
if (insert > 0) {
|