Search in sources :

Example 1 with UserDTO

use of com.orion.ops.entity.dto.UserDTO in project orion-ops by lijiahangmax.

the class FileTransferNotifyHandler method handleMessage.

@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
    String id = session.getId();
    Map<String, Object> attributes = session.getAttributes();
    Object auth = attributes.get(AUTH_KEY);
    if (auth != null) {
        return;
    }
    if (!(message instanceof TextMessage)) {
        return;
    }
    // 获取body
    String authToken = ((TextMessage) message).getPayload();
    if (Strings.isEmpty(authToken)) {
        log.info("sftp-Notify 认证失败-body为空 id: {}", id);
        session.close(WsCloseCode.INCORRECT_TOKEN.close());
        return;
    }
    // 获取认证用户
    UserDTO user = passportService.getUserByToken(authToken, null);
    if (user == null) {
        log.info("sftp-Notify 认证失败-未查询到用户 id: {}, authToken: {}", id, authToken);
        session.close(WsCloseCode.INCORRECT_TOKEN.close());
        return;
    }
    // 检查认证用户是否匹配
    Long userId = user.getId();
    Object tokenUserId = attributes.get(USER_ID_KEY);
    boolean valid = userId.equals(tokenUserId);
    if (!valid) {
        log.info("sftp-Notify 认证失败-用户不匹配 id: {}, userId: {}, tokenUserId: {}", id, userId, tokenUserId);
        session.close(WsCloseCode.VALID.close());
        return;
    }
    attributes.put(AUTH_KEY, 1);
    Long machineId = (Long) attributes.get(MACHINE_ID_KEY);
    log.info("sftp-Notify 认证成功 id: {}, userId: {}, machineId: {}", id, userId, machineId);
    transferProcessorManager.authSessionNotify(id, session, userId, machineId);
}
Also used : UserDTO(com.orion.ops.entity.dto.UserDTO)

Example 2 with UserDTO

use of com.orion.ops.entity.dto.UserDTO in project orion-ops by lijiahangmax.

the class CommonController method getMenu.

/**
 * 菜单
 */
@RequestMapping("/menu")
public List<?> getMenu() throws IOException {
    UserDTO user = Currents.getUser();
    String menuFile;
    if (RoleType.ADMINISTRATOR.getType().equals(user.getRoleType())) {
        menuFile = "menu-admin.json";
    } else if (RoleType.DEVELOPER.getType().equals(user.getRoleType())) {
        menuFile = "menu-dev.json";
    } else if (RoleType.OPERATION.getType().equals(user.getRoleType())) {
        menuFile = "menu-opt.json";
    } else {
        throw Exceptions.app();
    }
    InputStream menu = OrionOpsServiceApplication.class.getResourceAsStream("/menu/" + menuFile);
    return JSON.parseArray(new String(StreamReaders.readAllBytes(menu)));
}
Also used : InputStream(java.io.InputStream) UserDTO(com.orion.ops.entity.dto.UserDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with UserDTO

use of com.orion.ops.entity.dto.UserDTO in project orion-ops by lijiahangmax.

the class PassportServiceImpl method logout.

@Override
public void logout() {
    UserDTO user = Currents.getUser();
    if (user == null) {
        return;
    }
    Long id = user.getId();
    Long timestamp = user.getCurrentBindTimestamp();
    // 删除token
    redisTemplate.delete(Strings.format(KeyConst.LOGIN_TOKEN_BIND_KEY, id, timestamp));
    // 删除活跃时间
    userActiveInterceptor.deleteActiveTime(id);
}
Also used : UserDTO(com.orion.ops.entity.dto.UserDTO)

Example 4 with UserDTO

use of com.orion.ops.entity.dto.UserDTO in project orion-ops by lijiahangmax.

the class SftpServiceImpl method upload.

@Override
public void upload(Long machineId, List<FileUploadRequest> requestFiles) {
    UserDTO user = Currents.getUser();
    Long userId = user.getId();
    // 初始化上传信息
    List<FileTransferLogDO> uploadFiles = Lists.newList();
    for (FileUploadRequest requestFile : requestFiles) {
        // 插入明细
        FileTransferLogDO upload = new FileTransferLogDO();
        upload.setUserId(userId);
        upload.setUserName(user.getUsername());
        upload.setFileToken(requestFile.getFileToken());
        upload.setTransferType(SftpTransferType.UPLOAD.getType());
        upload.setMachineId(machineId);
        upload.setRemoteFile(requestFile.getRemotePath());
        upload.setLocalFile(requestFile.getLocalPath());
        upload.setCurrentSize(0L);
        upload.setFileSize(requestFile.getSize());
        upload.setNowProgress(0D);
        upload.setTransferStatus(SftpTransferStatus.WAIT.getStatus());
        uploadFiles.add(upload);
        fileTransferLogDAO.insert(upload);
        // 通知添加
        transferProcessorManager.notifySessionAddEvent(userId, machineId, upload.getFileToken(), upload);
    }
    // 提交上传任务
    for (FileTransferLogDO uploadFile : uploadFiles) {
        IFileTransferProcessor.of(FileTransferHint.transfer(uploadFile)).exec();
    }
    // 设置日志参数
    List<String> remoteFiles = requestFiles.stream().map(FileUploadRequest::getRemotePath).collect(Collectors.toList());
    EventParamsHolder.addParam(EventKeys.MACHINE_ID, machineId);
    EventParamsHolder.addParam(EventKeys.PATHS, remoteFiles);
    EventParamsHolder.addParam(EventKeys.COUNT, requestFiles.size());
}
Also used : FileTransferLogDO(com.orion.ops.entity.domain.FileTransferLogDO) UserDTO(com.orion.ops.entity.dto.UserDTO)

Example 5 with UserDTO

use of com.orion.ops.entity.dto.UserDTO in project orion-ops by lijiahangmax.

the class Currents method isAdministrator.

/**
 * 是否为 管理员
 *
 * @return true 管理员
 */
public static boolean isAdministrator() {
    UserDTO user = UserHolder.get();
    if (user == null) {
        return false;
    }
    Integer roleType = user.getRoleType();
    return RoleType.isAdministrator(roleType);
}
Also used : UserDTO(com.orion.ops.entity.dto.UserDTO)

Aggregations

UserDTO (com.orion.ops.entity.dto.UserDTO)25 Date (java.util.Date)6 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)3 FileTransferLogDO (com.orion.ops.entity.domain.FileTransferLogDO)3 Const (com.orion.ops.consts.Const)2 MessageConst (com.orion.ops.consts.MessageConst)2 EventKeys (com.orion.ops.consts.event.EventKeys)2 EventParamsHolder (com.orion.ops.consts.event.EventParamsHolder)2 SystemEnvAttr (com.orion.ops.consts.system.SystemEnvAttr)2 CommandTemplateDO (com.orion.ops.entity.domain.CommandTemplateDO)2 MachineInfoDO (com.orion.ops.entity.domain.MachineInfoDO)2 UserInfoDO (com.orion.ops.entity.domain.UserInfoDO)2 LoginBindDTO (com.orion.ops.entity.dto.LoginBindDTO)2 Currents (com.orion.ops.utils.Currents)2 PathBuilders (com.orion.ops.utils.PathBuilders)2 Valid (com.orion.ops.utils.Valid)2 Strings (com.orion.utils.Strings)2 Converts (com.orion.utils.convert.Converts)2 Files1 (com.orion.utils.io.Files1)2 List (java.util.List)2