use of io.jpom.model.data.WorkspaceModel in project Jpom by dromara.
the class NodeService method unLock.
/**
* 解锁分配工作空间
*
* @param id 节点ID
* @param workspaceId 工作空间
*/
public void unLock(String id, String workspaceId) {
NodeModel nodeModel = super.getByKey(id);
Assert.notNull(nodeModel, "没有对应对节点");
//
WorkspaceModel workspaceModel = workspaceService.getByKey(workspaceId);
Assert.notNull(workspaceModel, "没有对应对工作空间");
NodeModel nodeModel1 = new NodeModel();
nodeModel1.setId(id);
nodeModel1.setWorkspaceId(workspaceId);
nodeModel1.setUnLockType(StrUtil.EMPTY);
nodeModel1.setOpenStatus(1);
super.update(nodeModel1);
}
use of io.jpom.model.data.WorkspaceModel in project Jpom by dromara.
the class UserBindWorkspaceService method updateUserWorkspace.
/**
* 更新用户的工作空间信息
*
* @param userId 用户ID
* @param workspace 工作空间信息
*/
public void updateUserWorkspace(String userId, List<String> workspace) {
Assert.notEmpty(workspace, "没有任何工作空间信息");
List<UserBindWorkspaceModel> list = new HashSet<>(workspace).stream().filter(s -> {
s = StrUtil.removeSuffix(s, SYSTEM_USER);
s = StrUtil.removeSuffix(s, SSH_COMMAND_NOT_LIMITED);
MethodFeature[] values = MethodFeature.values();
for (MethodFeature value : values) {
s = StrUtil.removeSuffix(s, StrUtil.DASHED + value.name());
}
return workspaceService.exists(new WorkspaceModel(s));
}).map(s -> {
UserBindWorkspaceModel userBindWorkspaceModel = new UserBindWorkspaceModel();
userBindWorkspaceModel.setWorkspaceId(s);
userBindWorkspaceModel.setUserId(userId);
userBindWorkspaceModel.setId(UserBindWorkspaceModel.getId(userId, s));
return userBindWorkspaceModel;
}).collect(Collectors.toList());
// 删除之前的数据
UserBindWorkspaceModel userBindWorkspaceModel = new UserBindWorkspaceModel();
userBindWorkspaceModel.setUserId(userId);
super.del(super.dataBeanToEntity(userBindWorkspaceModel));
// 重新入库
super.insert(list);
}
use of io.jpom.model.data.WorkspaceModel in project Jpom by dromara.
the class WorkspaceService method checkInitDefault.
/**
* 检查初始化 默认的工作空间
*/
public void checkInitDefault() {
WorkspaceModel workspaceModel = super.getByKey(Const.WORKSPACE_DEFAULT_ID);
if (workspaceModel != null) {
return;
}
WorkspaceModel defaultWorkspace = new WorkspaceModel();
defaultWorkspace.setId(Const.WORKSPACE_DEFAULT_ID);
defaultWorkspace.setName("默认");
defaultWorkspace.setDescription("系统默认的工作空间,不能删除");
super.insert(defaultWorkspace);
DefaultSystemLog.getLog().info("init created default workspace");
}
use of io.jpom.model.data.WorkspaceModel in project Jpom by dromara.
the class LoginControl method createToken.
private UserLoginDto createToken(UserModel userModel) {
// 判断工作空间
List<WorkspaceModel> bindWorkspaceModels = userBindWorkspaceService.listUserWorkspaceInfo(userModel);
Assert.notEmpty(bindWorkspaceModels, "当前账号没有绑定任何工作空间,请联系管理员处理");
setSessionAttribute(LoginInterceptor.SESSION_NAME, userModel);
UserLoginDto userLoginDto = userService.getUserJwtId(userModel);
// UserLoginDto userLoginDto = new UserLoginDto(JwtUtil.builder(userModel, jwtId), jwtId);
userLoginDto.setBindWorkspaceModels(bindWorkspaceModels);
return userLoginDto;
}
use of io.jpom.model.data.WorkspaceModel in project Jpom by dromara.
the class InstallController method installSubmit.
/**
* 初始化提交
*
* @param userName 系统管理员登录名
* @param userPwd 系统管理员的登录密码
* @return json
* @api {post} install_submit.json 初始化提交
* @apiGroup index
* @apiUse defResultJson
* @apiParam {String} userName 系统管理员登录名
* @apiParam {String} userPwd 设置的登录密码 sha1 后传入
* @apiSuccess {JSON} data.tokenData token 相关信息
* @apiSuccess {String} data.mfaKey 二次验证的key
* @apiSuccess {String} data.url 二次验证的二维码相关字符串用户快速扫码导入
*/
@PostMapping(value = "install_submit.json", produces = MediaType.APPLICATION_JSON_VALUE)
@NotLogin
public String installSubmit(@ValidatorConfig(value = { @ValidatorItem(value = ValidatorRule.NOT_EMPTY, msg = "登录名不能为空"), @ValidatorItem(value = ValidatorRule.NOT_BLANK, range = UserModel.USER_NAME_MIN_LEN + ":" + Const.ID_MAX_LEN, msg = "登录名长度范围" + UserModel.USER_NAME_MIN_LEN + "-" + Const.ID_MAX_LEN), @ValidatorItem(value = ValidatorRule.WORD, msg = "登录名不能包含汉字并且不能包含特殊字符") }) String userName, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空") String userPwd) {
//
Assert.state(!userService.canUse(), "系统已经初始化过啦,请勿重复初始化");
boolean systemOccupyUserName = StrUtil.equalsAnyIgnoreCase(userName, UserModel.DEMO_USER, JpomApplication.SYSTEM_ID, UserModel.SYSTEM_ADMIN);
Assert.state(!systemOccupyUserName, "当前登录名已经被系统占用啦");
// 创建用户
UserModel userModel = new UserModel();
userModel.setName(UserModel.SYSTEM_OCCUPY_NAME);
userModel.setId(userName);
userModel.setSalt(userService.generateSalt());
userModel.setPassword(SecureUtil.sha1(userPwd + userModel.getSalt()));
userModel.setSystemUser(1);
userModel.setParent(UserModel.SYSTEM_ADMIN);
try {
BaseServerController.resetInfo(userModel);
userService.insert(userModel);
} catch (Exception e) {
DefaultSystemLog.getLog().error("初始化用户失败", e);
return JsonMessage.getString(400, "初始化失败:" + e.getMessage());
}
// 自动登录
setSessionAttribute(LoginInterceptor.SESSION_NAME, userModel);
UserLoginDto userLoginDto = userService.getUserJwtId(userModel);
List<WorkspaceModel> bindWorkspaceModels = userBindWorkspaceService.listUserWorkspaceInfo(userModel);
userLoginDto.setBindWorkspaceModels(bindWorkspaceModels);
// 二次验证信息
JSONObject jsonObject = new JSONObject();
String tfaKey = TwoFactorAuthUtils.generateTFAKey();
jsonObject.put("mfaKey", tfaKey);
jsonObject.put("url", TwoFactorAuthUtils.generateOtpAuthUrl(userName, tfaKey));
jsonObject.put("tokenData", userLoginDto);
return JsonMessage.getString(200, "初始化成功", jsonObject);
}
Aggregations