Coverage Report - org.apache.shiro.authz.annotation.RequiresRoles
 
Classes in this File Line Coverage Branch Coverage Complexity
RequiresRoles
N/A
N/A
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.shiro.authz.annotation;
 20  
 
 21  
 import java.lang.annotation.ElementType;
 22  
 import java.lang.annotation.Retention;
 23  
 import java.lang.annotation.RetentionPolicy;
 24  
 import java.lang.annotation.Target;
 25  
 
 26  
 /**
 27  
  * Requires the currently executing {@link org.apache.shiro.subject.Subject Subject} to have all of the 
 28  
  * specified roles. If they do not have the role(s), the method will not be executed and
 29  
  * an {@link org.apache.shiro.authz.AuthorizationException AuthorizationException} is thrown.
 30  
  * <p/>
 31  
  * For example,
 32  
  * <p/>
 33  
  * <code>&#64;RequiresRoles("aRoleName");<br/>
 34  
  * void someMethod();</code>
 35  
  * <p/>
 36  
  * means <tt>someMethod()</tt> could only be executed by subjects who have been assigned the
 37  
  * 'aRoleName' role.
 38  
  *
 39  
  * <p><b>*Usage Note*:</b> Be careful using this annotation if your application has a <em>dynamic</em>
 40  
  * security model where roles can be added and deleted at runtime.  If your application allowed the
 41  
  * annotated role to be deleted during runtime, the method would not be able to
 42  
  * be executed by anyone (at least until a new role with the same name was created again).
 43  
  *
 44  
  * <p>If you require such dynamic functionality, only the
 45  
  * {@link RequiresPermissions RequiresPermissions} annotation makes sense - Permission
 46  
  * types will not change during runtime for an application since permissions directly correspond to how
 47  
  * the application's functionality is programmed (that is, they reflect the application's functionality only, not
 48  
  * <em>who</em> is executing the the functionality).
 49  
  *
 50  
  * @see org.apache.shiro.subject.Subject#hasRole(String)
 51  
  * @since 0.1
 52  
  */
 53  
 @Target({ElementType.TYPE, ElementType.METHOD})
 54  
 @Retention(RetentionPolicy.RUNTIME)
 55  
 public @interface RequiresRoles {
 56  
 
 57  
     /**
 58  
      * A single String role name or multiple comma-delimitted role names required in order for the method
 59  
      * invocation to be allowed.
 60  
      */
 61  
     String[] value();
 62  
     
 63  
     /**
 64  
      * The logical operation for the permission check in case multiple roles are specified. AND is the default
 65  
      * @since 1.1.0
 66  
      */
 67  
     Logical logical() default Logical.AND; 
 68  
 }