本文整理了Java中org.apache.shiro.subject.Subject.checkPermissions()
方法的一些代码示例,展示了Subject.checkPermissions()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Subject.checkPermissions()
方法的具体详情如下:
包路径:org.apache.shiro.subject.Subject
类名称:Subject
方法名:checkPermissions
[英]Ensures this Subject org.apache.shiro.authz.Permission#implies(org.apache.shiro.authz.Permission) all of the specified permission strings.
If this subject's existing associated permissions do not org.apache.shiro.authz.Permission#implies(org.apache.shiro.authz.Permission) all of the given permissions, an org.apache.shiro.authz.AuthorizationException will be thrown.
[中]确保这个主题的组织。阿帕奇。西罗。奥兹。Permission#表示(org.apache.shiro.authz.Permission)所有指定的权限字符串。
如果此主题的现有关联权限不存在。阿帕奇。西罗。奥兹。权限#意味着(org.apache.shiro.authz.Permission)所有给定的权限,一个组织。阿帕奇。西罗。奥兹。将引发AuthorizationException。
代码示例来源:origin: killbill/killbill
@Override
public void checkCurrentUserPermissions(final List<Permission> permissions, final Logical logical, final TenantContext context) throws SecurityApiException {
final String[] permissionsString = Lists.<Permission, String>transform(permissions, Functions.toStringFunction()).toArray(new String[permissions.size()]);
try {
final Subject subject = SecurityUtils.getSubject();
if (permissionsString.length == 1) {
subject.checkPermission(permissionsString[0]);
} else if (Logical.AND.equals(logical)) {
subject.checkPermissions(permissionsString);
} else if (Logical.OR.equals(logical)) {
boolean hasAtLeastOnePermission = false;
for (final String permission : permissionsString) {
if (subject.isPermitted(permission)) {
hasAtLeastOnePermission = true;
break;
}
}
// Cause the exception if none match
if (!hasAtLeastOnePermission) {
subject.checkPermission(permissionsString[0]);
}
}
} catch (final AuthorizationException e) {
throw new SecurityApiException(e, ErrorCode.SECURITY_NOT_ENOUGH_PERMISSIONS);
}
}
代码示例来源:origin: apache/shiro
getSubject().checkPermissions(perms);
return;
代码示例来源:origin: org.apache.shiro/shiro-core
getSubject().checkPermissions(perms);
return;
代码示例来源:origin: org.sonatype.nexus/nexus-security
/**
* Ensure subject has given permissions.
*
* @throws AuthorizationException
*/
public void ensurePermitted(final Subject subject, final Permission... permissions) {
checkNotNull(subject);
checkNotNull(permissions);
checkArgument(permissions.length != 0);
if (log.isTraceEnabled()) {
log.trace("Ensuring subject '{}' has permissions: {}", subject.getPrincipal(), Arrays.toString(permissions));
}
subject.checkPermissions(Arrays.asList(permissions));
}
代码示例来源:origin: org.seedstack.seed/seed-security-core
@Override
public void checkPermissions(String... stringPermissions) {
Collection<org.apache.shiro.authz.Permission> permissions = new ArrayList<>();
for (String stringPermission : stringPermissions) {
permissions.add(new ScopePermission(stringPermission));
}
try {
SecurityUtils.getSubject().checkPermissions(permissions);
} catch (org.apache.shiro.authz.AuthorizationException e) {
throw new AuthorizationException("Subject doesn't have permissions " + Arrays.toString(stringPermissions),
e);
}
}
代码示例来源:origin: org.kill-bill.billing/killbill-util
@Override
public void checkCurrentUserPermissions(final List<Permission> permissions, final Logical logical, final TenantContext context) throws SecurityApiException {
final String[] permissionsString = Lists.<Permission, String>transform(permissions, Functions.toStringFunction()).toArray(new String[permissions.size()]);
try {
final Subject subject = SecurityUtils.getSubject();
if (permissionsString.length == 1) {
subject.checkPermission(permissionsString[0]);
} else if (Logical.AND.equals(logical)) {
subject.checkPermissions(permissionsString);
} else if (Logical.OR.equals(logical)) {
boolean hasAtLeastOnePermission = false;
for (final String permission : permissionsString) {
if (subject.isPermitted(permission)) {
hasAtLeastOnePermission = true;
break;
}
}
// Cause the exception if none match
if (!hasAtLeastOnePermission) {
subject.checkPermission(permissionsString[0]);
}
}
} catch (final AuthorizationException e) {
throw new SecurityApiException(e, ErrorCode.SECURITY_NOT_ENOUGH_PERMISSIONS);
}
}
代码示例来源:origin: com.ning.billing/killbill-util
@Override
public void checkCurrentUserPermissions(final List<Permission> permissions, final Logical logical, final TenantContext context) throws SecurityApiException {
final String[] permissionsString = Lists.<Permission, String>transform(permissions, Functions.toStringFunction()).toArray(new String[permissions.size()]);
try {
final Subject subject = SecurityUtils.getSubject();
if (permissionsString.length == 1) {
subject.checkPermission(permissionsString[0]);
} else if (Logical.AND.equals(logical)) {
subject.checkPermissions(permissionsString);
} else if (Logical.OR.equals(logical)) {
boolean hasAtLeastOnePermission = false;
for (final String permission : permissionsString) {
if (subject.isPermitted(permission)) {
hasAtLeastOnePermission = true;
break;
}
}
// Cause the exception if none match
if (!hasAtLeastOnePermission) {
subject.checkPermission(permissionsString[0]);
}
}
} catch (AuthorizationException e) {
throw new SecurityApiException(e, ErrorCode.SECURITY_NOT_ENOUGH_PERMISSIONS);
}
}
代码示例来源:origin: bazaarvoice/emodb
/**
* Authorizes the client for the annotated permissions. If any authorizations fail an {@link AuthorizationException}
* will be thrown, otherwise the original request is returned.
*/
@Override
public ContainerRequest filter(ContainerRequest request) {
Subject subject = ThreadContext.getSubject();
String[] permissions = resolvePermissions(request);
if (permissions.length == 1 || _logical == Logical.AND) {
// Shortcut call to check all permissions at once
subject.checkPermissions(permissions);
} else {
// Check each permission until any passes
boolean anyPermitted = false;
int p = 0;
while (!anyPermitted) {
try {
subject.checkPermission(permissions[p]);
anyPermitted = true;
} catch (AuthorizationException e) {
// If this is the last permission then pass the exception along
if (++p == permissions.length) {
throw e;
}
}
}
}
return request;
}
代码示例来源:origin: be.c4j.ee.security.octopus/octopus-core
@Override
public SecurityCheckInfo performCheck(Subject subject, AccessDecisionVoterContext accessContext, Annotation securityAnnotation) {
SecurityCheckInfo result;
RequiresPermissions requiresPermissions = (RequiresPermissions) securityAnnotation;
String[] permissions = requiresPermissions.value();
try {
subject.checkPermissions(permissions);
result = SecurityCheckInfo.allowAccess();
} catch (AuthorizationException ae) {
result = SecurityCheckInfo.withException(
new OctopusUnauthorizedException("Shiro permissions required", infoProducer.getViolationInfo(accessContext))
);
}
return result;
}
代码示例来源:origin: yangfuhai/jboot
subject.checkPermissions(perms);
return AuthorizeResult.ok();
代码示例来源:origin: cn.dreampie/jfinal-shiro
@Override
public void assertAuthorized() throws AuthorizationException {
Subject subject = getSubject();
if (!(annotation instanceof RequiresPermissions))
return;
RequiresPermissions rpAnnotation = (RequiresPermissions) annotation;
String[] perms = rpAnnotation.value();
if (perms.length == 1) {
subject.checkPermission(perms[0]);
return;
}
if (Logical.AND.equals(rpAnnotation.logical())) {
getSubject().checkPermissions(perms);
return;
}
if (Logical.OR.equals(rpAnnotation.logical())) {
// Avoid processing exceptions unnecessarily - "delay" throwing the
// exception by calling hasRole first
boolean hasAtLeastOnePermission = false;
for (String permission : perms)
if (subject.isPermitted(permission))
hasAtLeastOnePermission = true;
// Cause the exception if none of the role match, note that the
// exception message will be a bit misleading
if (!hasAtLeastOnePermission)
subject.checkPermission(perms[0]);
}
}
代码示例来源:origin: Dreampie/jfinal-shiro
@Override
public void assertAuthorized() throws AuthorizationException {
Subject subject = getSubject();
if (!(annotation instanceof RequiresPermissions))
return;
RequiresPermissions rpAnnotation = (RequiresPermissions) annotation;
String[] perms = rpAnnotation.value();
if (perms.length == 1) {
subject.checkPermission(perms[0]);
return;
}
if (Logical.AND.equals(rpAnnotation.logical())) {
getSubject().checkPermissions(perms);
return;
}
if (Logical.OR.equals(rpAnnotation.logical())) {
// Avoid processing exceptions unnecessarily - "delay" throwing the
// exception by calling hasRole first
boolean hasAtLeastOnePermission = false;
for (String permission : perms)
if (subject.isPermitted(permission))
hasAtLeastOnePermission = true;
// Cause the exception if none of the role match, note that the
// exception message will be a bit misleading
if (!hasAtLeastOnePermission)
subject.checkPermission(perms[0]);
}
}
代码示例来源:origin: uk.q3c.krail/krail
getSubject().checkPermissions(perms);
return;
代码示例来源:origin: KrailOrg/krail
getSubject().checkPermissions(perms);
return;
代码示例来源:origin: com.github.sogyf/goja-mvt
@Override
public void assertAuthorized() throws AuthorizationException {
if (!(annotation instanceof RequiresPermissions))
return;
RequiresPermissions rpAnnotation = (RequiresPermissions) annotation;
String[] perms = rpAnnotation.value();
Subject subject = getSubject();
if (perms.length == 1) {
subject.checkPermission(perms[0]);
return;
}
if (Logical.AND.equals(rpAnnotation.logical())) {
getSubject().checkPermissions(perms);
return;
}
if (Logical.OR.equals(rpAnnotation.logical())) {
// Avoid processing exceptions unnecessarily - "delay" throwing the
// exception by calling hasRole first
boolean hasAtLeastOnePermission = false;
for (String permission : perms)
if (getSubject().isPermitted(permission))
hasAtLeastOnePermission = true;
// Cause the exception if none of the role match, note that the
// exception message will be a bit misleading
if (!hasAtLeastOnePermission)
getSubject().checkPermission(perms[0]);
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro
getSubject().checkPermissions(perms);
return;
代码示例来源:origin: cn.jeeweb/jeeweb-common-security
getSubject().checkPermissions(newPerms);
return true;
代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot
getSubject().checkPermissions(newPerms);
return true;
内容来源于网络,如有侵权,请联系作者删除!