|
|
@@ -351,13 +351,22 @@ public class UserServiceImpl implements IUserService {
|
|
|
String workSpaceId = signLoginDTO.getWorkspace_id();
|
|
|
String workSpaceName = signLoginDTO.getWorkspace_name();
|
|
|
String clientId = signLoginDTO.getClient_id();
|
|
|
-
|
|
|
Long timestamp = signLoginDTO.getTimestamp();
|
|
|
+ if(!StringUtils.hasText(username)
|
|
|
+ || !StringUtils.hasText(sign)
|
|
|
+ || !StringUtils.hasText(workSpaceId)
|
|
|
+ || !StringUtils.hasText(workSpaceName)
|
|
|
+ || !StringUtils.hasText(clientId)
|
|
|
+ || timestamp == null) {
|
|
|
+ return new HttpResultResponse()
|
|
|
+ .setCode(HttpStatus.UNAUTHORIZED.value())
|
|
|
+ .setMessage("无效的参数");
|
|
|
+ }
|
|
|
|
|
|
if(!CustomConfiguration.parentSysClientId.equals(clientId)) {
|
|
|
return new HttpResultResponse()
|
|
|
.setCode(HttpStatus.UNAUTHORIZED.value())
|
|
|
- .setMessage("invalid clientId");
|
|
|
+ .setMessage("无效的 clientId");
|
|
|
}
|
|
|
|
|
|
long btwTime = System.currentTimeMillis() - timestamp;
|
|
|
@@ -367,22 +376,24 @@ public class UserServiceImpl implements IUserService {
|
|
|
if (isMoreThanFiveMinutes) {
|
|
|
return new HttpResultResponse()
|
|
|
.setCode(HttpStatus.UNAUTHORIZED.value())
|
|
|
- .setMessage("invalid time");
|
|
|
+ .setMessage("请求已过期,请重新发起请求");
|
|
|
}
|
|
|
if (sign != null) {
|
|
|
String dataInput = clientId+timestamp+username+workSpaceId+workSpaceName;
|
|
|
String generatedHash = DigestUtil.sha256Hex(dataInput.toUpperCase()+CustomConfiguration.signKey);
|
|
|
- // Verify the hash
|
|
|
- boolean isMatch = StrUtil.equals(generatedHash, sign);
|
|
|
- if(!isMatch) {
|
|
|
+ if(!StrUtil.equals(generatedHash, sign)) {
|
|
|
return new HttpResultResponse()
|
|
|
.setCode(HttpStatus.UNAUTHORIZED.value())
|
|
|
- .setMessage("invalid sign");
|
|
|
+ .setMessage("签名验证失败");
|
|
|
}
|
|
|
+ } else {
|
|
|
+ return new HttpResultResponse()
|
|
|
+ .setCode(HttpStatus.UNAUTHORIZED.value())
|
|
|
+ .setMessage("无效的签名");
|
|
|
}
|
|
|
//用户入库
|
|
|
QueryWrapper<UserEntity> userWrapper = new QueryWrapper<>();
|
|
|
- userWrapper.lambda().eq(UserEntity::getUserType,UserTypeEnum.SUPER_SYS.getVal())
|
|
|
+ userWrapper.lambda().eq(UserEntity::getUserType,UserTypeEnum.WEB.getVal())
|
|
|
.eq(UserEntity::getClientId,clientId);
|
|
|
UserEntity userEntity = mapper.selectOne(userWrapper);
|
|
|
if(userEntity == null) {
|
|
|
@@ -397,11 +408,16 @@ public class UserServiceImpl implements IUserService {
|
|
|
userEntity.setClientId(clientId);
|
|
|
mapper.insert(userEntity);
|
|
|
} else {
|
|
|
- userEntity.setMqttUsername(mqttPropertyConfiguration.mqttConnectOptions().getUserName());
|
|
|
- userEntity.setMqttPassword(String.valueOf(mqttPropertyConfiguration.mqttConnectOptions().getPassword()));
|
|
|
- userEntity.setUsername(username);
|
|
|
- userEntity.setWorkspaceId(workSpaceId);
|
|
|
- mapper.updateById(userEntity);
|
|
|
+ if(!mqttPropertyConfiguration.mqttConnectOptions().getUserName().equals(userEntity.getMqttUsername())
|
|
|
+ || !String.valueOf(mqttPropertyConfiguration.mqttConnectOptions().getPassword()).equals(userEntity.getMqttPassword())
|
|
|
+ || !username.equals(userEntity.getUsername())
|
|
|
+ || !workSpaceId.equals(userEntity.getWorkspaceId())) {
|
|
|
+ userEntity.setMqttUsername(mqttPropertyConfiguration.mqttConnectOptions().getUserName());
|
|
|
+ userEntity.setMqttPassword(String.valueOf(mqttPropertyConfiguration.mqttConnectOptions().getPassword()));
|
|
|
+ userEntity.setUsername(username);
|
|
|
+ userEntity.setWorkspaceId(workSpaceId);
|
|
|
+ mapper.updateById(userEntity);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//工作空间入库
|
|
|
@@ -412,16 +428,18 @@ public class UserServiceImpl implements IUserService {
|
|
|
workspace = new WorkspaceEntity();
|
|
|
workspace.setWorkspaceId(workSpaceId);
|
|
|
workspace.setWorkspaceName(workSpaceName);
|
|
|
- workspace.setPlatformName("Cloud Api Platform");
|
|
|
+ workspace.setPlatformName("私有云平台");
|
|
|
workspace.setBindCode(RandomUtil.randomString(6));
|
|
|
workspaceMapper.insert(workspace);
|
|
|
} else {
|
|
|
- workspace.setWorkspaceName(workSpaceName);
|
|
|
- workspaceMapper.updateById(workspace);
|
|
|
+ if(StringUtils.hasText(workSpaceName) && !workSpaceName.equals(workspace.getWorkspaceName())) {
|
|
|
+ workspace.setWorkspaceName(workSpaceName);
|
|
|
+ workspaceMapper.updateById(workspace);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
CustomClaim customClaim = new CustomClaim(userEntity.getUserId(),
|
|
|
- username, UserTypeEnum.SUPER_SYS.getVal(),
|
|
|
+ username, UserTypeEnum.WEB.getVal(),
|
|
|
workSpaceId);
|
|
|
|
|
|
// create token
|