Search in sources :

Example 1 with WorkspaceModel

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);
}
Also used : WorkspaceModel(io.jpom.model.data.WorkspaceModel) NodeModel(io.jpom.model.data.NodeModel)

Example 2 with WorkspaceModel

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);
}
Also used : UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel) WorkspaceModel(io.jpom.model.data.WorkspaceModel) WorkspaceService(io.jpom.service.system.WorkspaceService) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) Service(org.springframework.stereotype.Service) Entity(cn.hutool.db.Entity) UserModel(io.jpom.model.data.UserModel) MethodFeature(io.jpom.permission.MethodFeature) BaseDbService(io.jpom.service.h2db.BaseDbService) Assert(org.springframework.util.Assert) UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel) WorkspaceModel(io.jpom.model.data.WorkspaceModel) MethodFeature(io.jpom.permission.MethodFeature) UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel) HashSet(java.util.HashSet)

Example 3 with WorkspaceModel

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");
}
Also used : WorkspaceModel(io.jpom.model.data.WorkspaceModel) BaseWorkspaceModel(io.jpom.model.BaseWorkspaceModel)

Example 4 with WorkspaceModel

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;
}
Also used : WorkspaceModel(io.jpom.model.data.WorkspaceModel) UserLoginDto(io.jpom.model.dto.UserLoginDto)

Example 5 with WorkspaceModel

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);
}
Also used : UserModel(io.jpom.model.data.UserModel) WorkspaceModel(io.jpom.model.data.WorkspaceModel) JSONObject(com.alibaba.fastjson.JSONObject) UserLoginDto(io.jpom.model.dto.UserLoginDto) NotLogin(io.jpom.common.interceptor.NotLogin) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

WorkspaceModel (io.jpom.model.data.WorkspaceModel)10 UserModel (io.jpom.model.data.UserModel)5 StrUtil (cn.hutool.core.util.StrUtil)3 JSONObject (com.alibaba.fastjson.JSONObject)3 NodeModel (io.jpom.model.data.NodeModel)3 MethodFeature (io.jpom.permission.MethodFeature)3 WorkspaceService (io.jpom.service.system.WorkspaceService)3 Collectors (java.util.stream.Collectors)3 Assert (org.springframework.util.Assert)3 CollUtil (cn.hutool.core.collection.CollUtil)2 Entity (cn.hutool.db.Entity)2 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)2 NotLogin (io.jpom.common.interceptor.NotLogin)2 BaseWorkspaceModel (io.jpom.model.BaseWorkspaceModel)2 UserLoginDto (io.jpom.model.dto.UserLoginDto)2 ClassFeature (io.jpom.permission.ClassFeature)2 NodeService (io.jpom.service.node.NodeService)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 Convert (cn.hutool.core.convert.Convert)1 NetUtil (cn.hutool.core.net.NetUtil)1