Package org.apache.shiro.authz.annotation

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


      protected Subject getSubject() {
          return subject;
            }
        };

        Annotation requiresRolesAnnotation = new RequiresRoles() {
            public String[] value() {
                return new String[]{"blah", "blah2"};
            }

            public Class<? extends Annotation> annotationType() {
View Full Code Here


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

    boolean requiresRoles = false;
    List<String> requiredRoles = null;

    try
    {
      RequiresRoles annotation = runtimeClass.getAnnotation(RequiresRoles.class);
      requiresRoles = (annotation != null);
      requiredRoles = Arrays.asList(annotation.value());
    }
    catch (NullPointerException e)
    {
      requiresRoles = false;
    }

    if (requiresRoles && requiredRoles != null && !ApplicationSecurity.hasAllRoles(requiredRoles))
    {
      final String message = String.format("Insufficient role membership for %s on %s", userName, viewName);
      logger.warn(message);
      throw new AuthorizationException(message);
    }

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

  public void assertAuthorized() throws AuthorizationException {

    Subject subject = getSubject();

    if (!(annotation instanceof RequiresRoles)) return;
    RequiresRoles rrAnnotation = (RequiresRoles) annotation;
    String[] roles = rrAnnotation.value();

    if (roles.length == 1) {
      subject.checkRole(roles[0]);
      return;
    }
    if (Logical.AND.equals(rrAnnotation.logical())) {
      subject.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 (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]);
View Full Code Here

TOP

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

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.