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 */
019package org.apache.shiro.authz.annotation;
020
021import java.lang.annotation.ElementType;
022import java.lang.annotation.Retention;
023import java.lang.annotation.RetentionPolicy;
024import 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>&#64;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 * @see org.apache.shiro.subject.Subject#checkPermission
044 * @since 0.1
045 */
046@Target({ElementType.TYPE, ElementType.METHOD})
047@Retention(RetentionPolicy.RUNTIME)
048public @interface RequiresPermissions {
049
050    /**
051     * The permission string which will be passed to {@link org.apache.shiro.subject.Subject#isPermitted(String)}
052     * to determine if the user is allowed to invoke the code protected by this annotation.
053     */
054    String[] value();
055    
056    /**
057     * The logical operation for the permission checks in case multiple roles are specified. AND is the default
058     * @since 1.1.0
059     */
060    Logical logical() default Logical.AND; 
061
062}
063