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 module hunt.shiro.authz.annotation.RequiresRoles;
20 
21 import hunt.shiro.authz.annotation.Logical;
22 // import java.lang.annotation.ElementType;
23 // import java.lang.annotation.Retention;
24 // import java.lang.annotation.RetentionPolicy;
25 // import java.lang.annotation.Target;
26 
27 /**
28  * Requires the currently executing {@link hunt.shiro.subject.Subject Subject} to have all of the 
29  * specified roles. If they do not have the role(s), the method will not be executed and
30  * an {@link hunt.shiro.authz.AuthorizationException AuthorizationException} is thrown.
31  * <p/>
32  * For example,
33  * <p/>
34  * <code>&#64;RequiresRoles("aRoleName");<br/>
35  * void someMethod();</code>
36  * <p/>
37  * means <tt>someMethod()</tt> could only be executed by subjects who have been assigned the
38  * 'aRoleName' role.
39  *
40  * <p><b>*Usage Note*:</b> Be careful using this annotation if your application has a <em>dynamic</em>
41  * security model where roles can be added and deleted at runtime.  If your application allowed the
42  * annotated role to be deleted during runtime, the method would not be able to
43  * be executed by anyone (at least until a new role with the same name was created again).
44  *
45  * <p>If you require such dynamic functionality, only the
46  * {@link RequiresPermissions RequiresPermissions} annotation makes sense - Permission
47  * types will not change during runtime for an application since permissions directly correspond to how
48  * the application's functionality is programmed (that is, they reflect the application's functionality only, not
49  * <em>who</em> is executing the the functionality).
50  *
51  * @see hunt.shiro.subject.Subject#hasRole(string)
52  */
53 // @Target({ElementType.TYPE, ElementType.METHOD})
54 // @Retention(RetentionPolicy.RUNTIME)
55 // public @interface RequiresRoles {
56 public interface RequiresRoles {
57     /**
58      * A single string role name or multiple comma-delimited 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      */
66     //Logical logical() default Logical.AND; 
67     Logical logical();
68 }