本文整理汇总了Java中org.apache.shiro.authz.annotation.Logical类的典型用法代码示例。如果您正苦于以下问题:Java Logical类的具体用法?Java Logical怎么用?Java Logical使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Logical类属于org.apache.shiro.authz.annotation包,在下文中一共展示了Logical类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: permitted
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
public PermissionInfo permitted() {
Subject currentUser = SecurityUtils.getSubject();
if (TYPE.ROLE.equals(this.type)) {
// role based
if (Logical.AND.equals(this.logical)) {
isPermitted = currentUser.hasAllRoles(Arrays.asList(roles));
return this;
}
isPermitted = ArrayUtils.contains(currentUser.hasRoles(Arrays.asList(roles)), true);
return this;
}
// permission based
if (Logical.AND.equals(this.logical)) {
isPermitted = currentUser.isPermittedAll(permissions);
return this;
}
isPermitted = ArrayUtils.contains(currentUser.isPermitted(permissions), true);
return this;
}
示例2: isAccessAllowed
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
public boolean isAccessAllowed(String[] roles, Logical logical) {
Subject subject = SecurityUtils.getSubject();
if (!subject.isAuthenticated() && !subject.isRemembered()) {
return false;
}
String accountId = subject.getSession().getAttribute(TcSessionKey.S_ACCOUNT_ID).toString();
checkNotNull(accountId);
TcP<List<ToRole>> tcP = tcAuthenticationApi.findRoles(accountId);
List<String> actualRoles = tcP.orElseGet(Lists::newArrayList).stream()
.map(ToRole::getId)
.collect(Collectors.toList());
ArrayList<String> expectRoles = Lists.newArrayList(roles);
if (Logical.AND.equals(logical)) {
// contains all in expect roles.
int expectRolesSize = expectRoles.size();
return CollectionUtils.retainAll(expectRoles, actualRoles).size() == expectRolesSize;
} else {
// contains in both roles.
return CollectionUtils.retainAll(expectRoles, actualRoles).size() != 0;
}
}
示例3: assertAuthorized
import org.apache.shiro.authz.annotation.Logical; //导入依赖的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]);
}
}
示例4: assertAuthorized
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
/**
* Ensures that the calling <code>Subject</code> has the Annotation's specified permissions, and if not, throws an
* <code>AuthorizingException</code> indicating access is denied.
*
* @param a the RequiresPermission annotation being inspected to check for one or more permissions
* @throws org.apache.shiro.authz.AuthorizationException
* if the calling <code>Subject</code> does not have the permission(s) necessary to
* continue access or execution.
*/
public void assertAuthorized(Annotation a) throws AuthorizationException {
if (!(a instanceof RequiresPermissions)) return;
RequiresPermissions rpAnnotation = (RequiresPermissions) a;
String[] perms = getAnnotationValue(a);
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]);
}
}
示例5: intercept
import org.apache.shiro.authz.annotation.Logical; //导入依赖的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();
}
示例6: assertAuthorized
import org.apache.shiro.authz.annotation.Logical; //导入依赖的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]);
}
}
示例7: assertAuthorized
import org.apache.shiro.authz.annotation.Logical; //导入依赖的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]);
}
}
示例8: authorize
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
@Override
public AuthorizeResult authorize() {
try {
String[] perms = requiresPermissions.value();
Subject subject = SecurityUtils.getSubject();
if (perms.length == 1) {
subject.checkPermission(perms[0]);
return AuthorizeResult.ok();
}
if (Logical.AND.equals(requiresPermissions.logical())) {
subject.checkPermissions(perms);
return AuthorizeResult.ok();
}
if (Logical.OR.equals(requiresPermissions.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]);
}
return AuthorizeResult.ok();
} catch (AuthorizationException e) {
return AuthorizeResult.fail(AuthorizeResult.ERROR_CODE_UNAUTHORIZATION);
}
}
示例9: authorize
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
@Override
public AuthorizeResult authorize() {
String[] roles = requiresRoles.value();
try {
if (roles.length == 1) {
SecurityUtils.getSubject().checkRole(roles[0]);
return AuthorizeResult.ok();
}
if (Logical.AND.equals(requiresRoles.logical())) {
SecurityUtils.getSubject().checkRoles(Arrays.asList(roles));
return AuthorizeResult.ok();
}
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 (SecurityUtils.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) SecurityUtils.getSubject().checkRole(roles[0]);
}
return AuthorizeResult.ok();
} catch (AuthorizationException e) {
return AuthorizeResult.fail(AuthorizeResult.ERROR_CODE_UNAUTHORIZATION);
}
}
示例10: create
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
@RequiresPermissions("admin:authority:sysrole:create")
@RequiresRoles(value={"Administrator","Supervisor"},logical=Logical.OR)
@RequestMapping(value = "/create", method = RequestMethod.POST, produces="application/json;charset=UTF-8")
@ResponseBody
@LogAudit
@Override
@ApiOperation(value = "创建角色", httpMethod = "POST", response = Map.class, notes = "创建角色",
produces="application/json",consumes="application/json")
public Map<String, Object> create(@RequestBody SysRole o) throws Exception {
return super.create(o);
}
示例11: update
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
@RequiresPermissions("admin:authority:sysrole:update")
@RequiresRoles(value={"Administrator","Supervisor"},logical=Logical.OR)
@RequestMapping(value = "/update", method = RequestMethod.POST, produces="application/json;charset=UTF-8")
@ResponseBody
@LogAudit
@Override
@ApiOperation(value = "更新角色", httpMethod = "POST", response = Map.class, notes = "更新角色",
produces="application/json",consumes="application/json")
public Map<String, Object> update(@RequestBody SysRole o) throws Exception {
return super.update(o);
}
示例12: delete
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
@RequiresPermissions("admin:authority:sysrole:delete")
@RequiresRoles(value={"Administrator","Supervisor"},logical=Logical.OR)
@RequestMapping(value = "/delete", method = RequestMethod.POST, produces="application/json;charset=UTF-8")
@ResponseBody
@LogAudit
@ApiOperation(value = "删除角色", httpMethod = "POST", response = Map.class, notes = "通过主键删除角色",
produces="application/json",consumes="application/json")
public Map<String, Object> delete(@RequestBody SysRole o) throws Exception {
return super.delete(o.getId());
}
示例13: deletes
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
@RequiresPermissions("admin:authority:sysrole:delete")
@RequiresRoles(value={"Administrator","Supervisor"},logical=Logical.OR)
@RequestMapping(value = "/deletes", method = RequestMethod.POST, produces="application/json;charset=UTF-8")
@ResponseBody
@LogAudit
@Override
@ApiOperation(value = "删除角色", httpMethod = "POST", response = Map.class, notes = "通过主键数组删除角色",
produces="application/json",consumes="application/json")
public Map<String, Object> deletes(@RequestBody Integer[] ids) throws Exception {
return super.deletes(ids);
}
示例14: rolePermissionView
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
/**
* 角色资源授权
* @return
* @throws Exception
*/
@RequiresPermissions(value={"admin:authority:sysrole:create","admin:authority:sysrole:update"},logical=Logical.OR)
@RequestMapping(value = "/rolePermissionView", method = RequestMethod.GET)
@ApiOperation(value = "打开角色资源授权页面", httpMethod = "GET", response = Map.class, notes = "打开角色资源授权页面",
consumes="application/x-www-form-urlencoded")
public ModelAndView rolePermissionView() throws Exception {
return new ModelAndView("/action/admin/authority/sysrole/rolePermissionView");
}
示例15: userRoleView
import org.apache.shiro.authz.annotation.Logical; //导入依赖的package包/类
/**
* 用户角色授权
* @return
* @throws Exception
*/
@RequiresPermissions(value={"admin:authority:sysuser:create","admin:authority:sysuser:update"},logical=Logical.OR)
@RequestMapping(value = "/userRoleView", method = RequestMethod.GET)
@ApiOperation(value = "打开用户角色授权页面", httpMethod = "GET", response = Map.class, notes = "打开用户角色授权页面",
consumes="application/x-www-form-urlencoded")
public ModelAndView userRoleView() throws Exception {
return new ModelAndView("/action/admin/authority/sysuser/userRoleView");
}