zoukankan      html  css  js  c++  java
  • Shiro AnnotationHandler注解处理器设计概念

    顶端抽象类AnnotationHandler

    该类是关乎注解的处理类,只涉及到注解的一些行为,符合面向对象的原则

    承上启下抽象类AuthorizingAnnotationHandler

    该类是权限注解处理器类,涉及到注解的行为所以继承了AnnotationHandler,又因为涉及到权限判断所以定义了判断权限的抽象方法,抽象化判断方法,使用子类具体实现判断方法

    具体实现类RoleAnnotationHandler

    提供权限注解的信息和权限判断的方法实现

    public RoleAnnotationHandler() {
            super(RequiresRoles.class);
        }

    具体实现

    public void assertAuthorized(Annotation a) throws AuthorizationException {
        if (!(a instanceof RequiresRoles)) return;
    
        RequiresRoles rrAnnotation = (RequiresRoles) a;
        String[] roles = rrAnnotation.value();
    
        if (roles.length == 1) {
            getSubject().checkRole(roles[0]);
            return;
        }
        if (Logical.AND.equals(rrAnnotation.logical())) {
            getSubject().checkRoles(Arrays.asList(roles));
            return;
        }
        if (Logical.OR.equals(rrAnnotation.logical())) {
            // Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
            boolean hasAtLeastOneRole = false;
            for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true;
            // Cause the exception if none of the role match, note that the exception message will be a bit misleading
            if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]);
        }
    }
  • 相关阅读:
    MapGuide 资源
    mac 安装brew
    mysql 设置外键约束SET FOREIGN_KEY_CHECKS=1
    一文深入讲解redis和couchbase的区别
    mac 显示 sh3.2# 的
    DBA整理的万字详解MySQL性能优化,值得收藏!
    redis和couchbase的比较
    && 运算符的使用
    freeotp 安装及使用过程
    Couchbase vs Redis,究竟哪个更胜一筹?
  • 原文地址:https://www.cnblogs.com/BINGJJFLY/p/9071235.html
Copyright © 2011-2022 走看看