001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019 package org.apache.shiro.authz.annotation;
020
021 import java.lang.annotation.ElementType;
022 import java.lang.annotation.Retention;
023 import java.lang.annotation.RetentionPolicy;
024 import java.lang.annotation.Target;
025
026 /**
027 * <p>
028 * Requires the current executor's Subject to imply a particular permission in
029 * order to execute the annotated method. If the executor's associated
030 * {@link org.apache.shiro.subject.Subject Subject} determines that the
031 * executor does not imply the specified permission, the method will not be executed.
032 * </p>
033 *
034 * <p>For example, this declaration:
035 * <p/>
036 * <code>@RequiresPermissions( "file:read,write:aFile.txt" )<br/>
037 * void someMethod();</code>
038 * <p/>
039 * indicates the current user must be able to both <tt>read</tt> and <tt>write</tt>
040 * to the file <tt>aFile.txt</tt> in order for the <tt>someMethod()</tt> to execute, otherwise
041 * an {@link org.apache.shiro.authz.AuthorizationException AuthorizationException} will be thrown.
042 *
043 * @author Jeremy Haile
044 * @author Les Hazlewood
045 * @see org.apache.shiro.subject.Subject#checkPermission
046 * @since 0.1
047 */
048 @Target(ElementType.METHOD)
049 @Retention(RetentionPolicy.RUNTIME)
050 public @interface RequiresPermissions {
051
052 /**
053 * The permission string which will be passed to {@link org.apache.shiro.subject.Subject#isPermitted(String)}
054 * to determine if the user is allowed to invoke the code protected by this annotation.
055 */
056 String value();
057
058 }
059