Package org.apache.shiro.authz.annotation

Examples of org.apache.shiro.authz.annotation.RequiresPermissions


    boolean requiresPermissions = false;
    List<String> requiredPermissions = null;

    try
    {
      RequiresPermissions annotation = runtimeClass.getAnnotation(RequiresPermissions.class);
      requiresPermissions = (annotation != null);
      requiredPermissions = Arrays.asList(annotation.value());
    }
    catch (NullPointerException e)
    {
      requiresPermissions = false;
    }

    if (requiresPermissions && requiredPermissions != null
        && !ApplicationSecurity.hasAllPermissions(requiredPermissions))
    {
      final String message = String.format("Insufficient permission for %s on %s", userName, viewName);
      logger.warn(message);
      throw new AuthorizationException(message);
    }

    try
    {
      RequiresPermissions annotation = method.getAnnotation(RequiresPermissions.class);
      requiresPermissions = (annotation != null);
      requiredPermissions = Arrays.asList(annotation.value());
    }
    catch (NullPointerException e)
    {
      requiresPermissions = false;
    }
View Full Code Here


    }
   
    final HandlerMethod handlerMethod = (HandlerMethod)handler;
    Method method = handlerMethod.getMethod();
   
    final RequiresPermissions rps = method.getAnnotation(RequiresPermissions.class);
    if (rps == null) {
      return true;
    }
    Logical logical = rps.logical();
    String[] pv = rps.value();
   
    // 假如验证逻辑为OR,并且有些权限不需要做数据权限检查的,直接返回true。
    if (logical.equals(Logical.OR)) {
      for (String p : pv) {
        if (p.split(PART_DIVIDER_TOKEN).length < 3) {
View Full Code Here

    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))
View Full Code Here

TOP

Related Classes of org.apache.shiro.authz.annotation.RequiresPermissions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.