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);
}
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)));
}
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);
}
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());
}
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);
}
Aggregations