本文整理汇总了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]);
}
}
示例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();
}
示例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]);
}
}
示例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]);
}
}