当前位置: 首页>>代码示例>>Java>>正文


Java RequiresRoles.value方法代码示例

本文整理汇总了Java中org.apache.shiro.authz.annotation.RequiresRoles.value方法的典型用法代码示例。如果您正苦于以下问题:Java RequiresRoles.value方法的具体用法?Java RequiresRoles.value怎么用?Java RequiresRoles.value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.authz.annotation.RequiresRoles的用法示例。


在下文中一共展示了RequiresRoles.value方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assertAuthorized

import org.apache.shiro.authz.annotation.RequiresRoles; //导入方法依赖的package包/类
/**
 * Ensures that the calling <code>Subject</code> has the Annotation's specified roles, and if not, throws an
 * <code>AuthorizingException</code> indicating that access is denied.
 *
 * @param a the RequiresRoles annotation to use to check for one or more roles
 * @throws org.apache.shiro.authz.AuthorizationException
 *          if the calling <code>Subject</code> does not have the role(s) necessary to
 *          proceed.
 */
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]);
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:32,代码来源:RoleAnnotationHandler.java

示例2: intercept

import org.apache.shiro.authz.annotation.RequiresRoles; //导入方法依赖的package包/类
@Override
public Object intercept(AnnotationInterceptChain chain, Response response, Request request, RequiresRoles requiresRoles) throws Throwable {
    String[] roles = requiresRoles.value();
    Subject subject = SecurityUtils.getSubject();
    if (roles.length == 1) {
        subject.checkRole(roles[0]);
        return chain.intercept();
    }
    if (Logical.AND.equals(requiresRoles.logical())) {
        subject.checkRoles(Arrays.asList(roles));
        return chain.intercept();
    }
    if (Logical.OR.equals(requiresRoles.logical())) {
        // Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
        boolean hasAtLeastOneRole = false;
        for (String role : roles) if (subject.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) subject.checkRole(roles[0]);
    }
    return chain.intercept();
}
 
开发者ID:Teddy-Zhu,项目名称:SilentGo,代码行数:22,代码来源:RequiresRolesAnnotationResolver.java

示例3: assertAuthorized

import org.apache.shiro.authz.annotation.RequiresRoles; //导入方法依赖的package包/类
@Override
   public void assertAuthorized() throws AuthorizationException {
	//if (!(annotation instanceof RequiresRoles)) return;
       RequiresRoles rrAnnotation = (RequiresRoles) annotation;
       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]);
       }
}
 
开发者ID:gumutianqi,项目名称:jfinal-plus,代码行数:23,代码来源:RoleAuthzHandler.java

示例4: assertAuthorized

import org.apache.shiro.authz.annotation.RequiresRoles; //导入方法依赖的package包/类
@Override
public void assertAuthorized() throws AuthorizationException {
    //if (!(annotation instanceof RequiresRoles)) return;
    RequiresRoles rrAnnotation = (RequiresRoles) annotation;
    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]);
    }
}
 
开发者ID:GojaFramework,项目名称:goja,代码行数:23,代码来源:RoleAuthzHandler.java


注:本文中的org.apache.shiro.authz.annotation.RequiresRoles.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。