Search in sources :

Example 1 with IAgileSecurity

use of com.jeeagile.core.security.IAgileSecurity in project jeeagile by jeeagile.

the class AgileSecurityInterceptor method checkUserSecurity.

/**
 * 权限校验
 *
 * @param handlerMethod
 */
private void checkUserSecurity(HandlerMethod handlerMethod) {
    try {
        // 获取当前用户安全认证
        IAgileSecurity agileSecurity = AgileSecurityUtil.getAgileSecurity();
        if (agileSecurity == null) {
            throw new AgileAuthException("请设置用户安全接口类《UserSecurity》");
        }
        // 当前线程存放用户信息
        AgileSecurityContext.putCurrentUser(agileSecurity.getUserData());
        // 演示模式拦截
        AgileDemo agileDemo = handlerMethod.getMethodAnnotation(AgileDemo.class);
        if (agileDemo != null && AgileUtil.isDemoEnabled()) {
            throw new AgileDemoException();
        }
        // 如果为超管用户则不在进行权限校验
        if (agileSecurity.getUserData().isSuperAdmin()) {
            return;
        }
        AgileRequiresGuest agileRequiresGuest = handlerMethod.getBeanType().getAnnotation(AgileRequiresGuest.class);
        if (agileRequiresGuest != null) {
            return;
        }
        agileRequiresGuest = handlerMethod.getMethodAnnotation(AgileRequiresGuest.class);
        if (agileRequiresGuest != null) {
            return;
        }
        AgileRequiresAuthentication agileRequiresAuthentication = handlerMethod.getMethodAnnotation(AgileRequiresAuthentication.class);
        if (agileRequiresAuthentication != null && !agileSecurity.checkAuthenticated()) {
            throw new AgileAuthException("用户未验证通过!");
        }
        AgileRequiresUser agileRequiresUser = handlerMethod.getMethodAnnotation(AgileRequiresUser.class);
        if (agileRequiresUser != null) {
            agileSecurity.checkUser();
        }
        AgileRequiresRoles agileRequiresRoles = handlerMethod.getMethodAnnotation(AgileRequiresRoles.class);
        if (agileRequiresRoles != null) {
            agileSecurity.checkRole(agileRequiresRoles);
        }
        AgilePermissionsPrefix agilePermissionsPrefix = handlerMethod.getBeanType().getAnnotation(AgilePermissionsPrefix.class);
        AgileRequiresPermissions agileRequiresPermissions = handlerMethod.getMethodAnnotation(AgileRequiresPermissions.class);
        if (agileRequiresPermissions != null) {
            if (agilePermissionsPrefix != null) {
                agileSecurity.checkPermission(agilePermissionsPrefix, agileRequiresPermissions);
            } else {
                agileSecurity.checkPermission(agileRequiresPermissions);
            }
        }
    } catch (AgileBaseException ex) {
        throw ex;
    } catch (Exception ex) {
        logger.error("用户权限验证异常", ex);
        throw new AgileAuthException("用户权限验证异常!");
    }
}
Also used : IAgileSecurity(com.jeeagile.core.security.IAgileSecurity) AgileBaseException(com.jeeagile.core.exception.AgileBaseException) AgileDemoException(com.jeeagile.core.exception.AgileDemoException) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileDemo(com.jeeagile.frame.annotation.AgileDemo) AgileDemoException(com.jeeagile.core.exception.AgileDemoException) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileBaseException(com.jeeagile.core.exception.AgileBaseException)

Aggregations

AgileAuthException (com.jeeagile.core.exception.AgileAuthException)1 AgileBaseException (com.jeeagile.core.exception.AgileBaseException)1 AgileDemoException (com.jeeagile.core.exception.AgileDemoException)1 IAgileSecurity (com.jeeagile.core.security.IAgileSecurity)1 AgileDemo (com.jeeagile.frame.annotation.AgileDemo)1