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.Documented; 022import java.lang.annotation.ElementType; 023import java.lang.annotation.Retention; 024import java.lang.annotation.RetentionPolicy; 025import java.lang.annotation.Target; 026 027/** 028 * <p> 029 * Requires the current executor's Subject to imply a particular permission in 030 * order to execute the annotated method. If the executor's associated 031 * {@link org.apache.shiro.subject.Subject Subject} determines that the 032 * executor does not imply the specified permission, the method will not be executed. 033 * </p> 034 * 035 * <p>For example, this declaration: 036 * <p/> 037 * <code>@RequiresPermissions( {"file:read", "write:aFile.txt"} )<br/> 038 * void someMethod();</code> 039 * <p/> 040 * indicates the current user must be able to both <tt>read</tt> and <tt>write</tt> 041 * to the file <tt>aFile.txt</tt> in order for the <tt>someMethod()</tt> to execute, otherwise 042 * an {@link org.apache.shiro.authz.AuthorizationException AuthorizationException} will be thrown. 043 * 044 * @see org.apache.shiro.subject.Subject#checkPermission 045 * @since 0.1 046 */ 047@Target({ElementType.TYPE, ElementType.METHOD}) 048@Retention(RetentionPolicy.RUNTIME) 049@Documented 050public @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 * The logical operation for the permission checks in case multiple roles are specified. AND is the default 060 * @since 1.1.0 061 */ 062 Logical logical() default Logical.AND; 063 064} 065