Search in sources :

Example 1 with RequireRole

use of com.orion.ops.annotation.RequireRole in project orion-ops by lijiahangmax.

the class SystemController method cleanSystemFile.

/**
 * 清理系统文件
 */
@RequestMapping("/clean-system-file")
@EventLog(EventType.CLEAN_SYSTEM_FILE)
@RequireRole(RoleType.ADMINISTRATOR)
public HttpWrapper<?> cleanSystemFile(@RequestBody SystemFileCleanRequest request) {
    SystemCleanType cleanType = Valid.notNull(SystemCleanType.of(request.getCleanType()));
    systemService.cleanSystemFile(cleanType);
    return HttpWrapper.ok();
}
Also used : SystemCleanType(com.orion.ops.consts.system.SystemCleanType) EventLog(com.orion.ops.annotation.EventLog) RequireRole(com.orion.ops.annotation.RequireRole) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RequireRole

use of com.orion.ops.annotation.RequireRole in project orion-ops by lijiahangmax.

the class RoleInterceptor method preHandle.

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (!(handler instanceof HandlerMethod)) {
        return true;
    }
    RequireRole role = ((HandlerMethod) handler).getMethodAnnotation(RequireRole.class);
    if (role == null) {
        return true;
    }
    UserDTO user = UserHolder.get();
    if (user == null) {
        response.setContentType(StandardContentType.APPLICATION_JSON);
        Servlets.transfer(response, HttpWrapper.of(ResultCode.UNAUTHORIZED).toJsonString().getBytes());
        return false;
    }
    RoleType[] hasRoles = role.value();
    if (Arrays1.isEmpty(hasRoles)) {
        return true;
    }
    for (RoleType roleType : hasRoles) {
        if (roleType.getType().equals(user.getRoleType())) {
            return true;
        }
    }
    response.setContentType(StandardContentType.APPLICATION_JSON);
    Servlets.transfer(response, HttpWrapper.of(ResultCode.NO_PERMISSION).toJsonString().getBytes());
    return false;
}
Also used : RoleType(com.orion.ops.consts.user.RoleType) UserDTO(com.orion.ops.entity.dto.UserDTO) RequireRole(com.orion.ops.annotation.RequireRole) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 3 with RequireRole

use of com.orion.ops.annotation.RequireRole in project orion-ops by lijiahangmax.

the class SystemController method updateSystemOption.

/**
 * 修改系统配置项
 */
@RequestMapping("/update-system-option")
@EventLog(EventType.UPDATE_SYSTEM_OPTION)
@RequireRole(RoleType.ADMINISTRATOR)
public HttpWrapper<?> updateSystemOption(@RequestBody SystemOptionRequest request) {
    SystemConfigKey key = Valid.notNull(SystemConfigKey.of(request.getOption()));
    String value = key.getValue(Valid.notBlank(request.getValue()));
    systemService.updateSystemOption(key.getEnv(), value);
    return HttpWrapper.ok();
}
Also used : SystemConfigKey(com.orion.ops.consts.system.SystemConfigKey) EventLog(com.orion.ops.annotation.EventLog) RequireRole(com.orion.ops.annotation.RequireRole) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with RequireRole

use of com.orion.ops.annotation.RequireRole in project orion-ops by lijiahangmax.

the class ApplicationReleaseController method auditAppRelease.

/**
 * 发布审核
 */
@RequestMapping("/audit")
@RequireRole(RoleType.ADMINISTRATOR)
@EventLog(EventType.AUDIT_RELEASE)
public Integer auditAppRelease(@RequestBody ApplicationReleaseAuditRequest request) {
    Valid.notNull(request.getId());
    AuditStatus status = Valid.notNull(AuditStatus.of(request.getStatus()));
    if (AuditStatus.REJECT.equals(status)) {
        Valid.notBlank(request.getReason());
    }
    return applicationReleaseService.auditAppRelease(request);
}
Also used : AuditStatus(com.orion.ops.consts.AuditStatus) EventLog(com.orion.ops.annotation.EventLog) RequireRole(com.orion.ops.annotation.RequireRole) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RequireRole (com.orion.ops.annotation.RequireRole)4 EventLog (com.orion.ops.annotation.EventLog)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 AuditStatus (com.orion.ops.consts.AuditStatus)1 SystemCleanType (com.orion.ops.consts.system.SystemCleanType)1 SystemConfigKey (com.orion.ops.consts.system.SystemConfigKey)1 RoleType (com.orion.ops.consts.user.RoleType)1 UserDTO (com.orion.ops.entity.dto.UserDTO)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1