Coverage Report - org.apache.shiro.authz.Permission
 
Classes in this File Line Coverage Branch Coverage Complexity
Permission
N/A
N/A
1
 
 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;
 20  
 
 21  
 /**
 22  
  * A Permission represents the ability to perform an action or access a resource.  A Permission is the most
 23  
  * granular, or atomic, unit in a system's security policy and is the cornerstone upon which fine-grained security
 24  
  * models are built.
 25  
  * <p/>
 26  
  * It is important to understand a Permission instance only represents functionality or access - it does not grant it.
 27  
  * Granting access to an application functionality or a particular resource is done by the application's security
 28  
  * configuration, typically by assigning Permissions to users, roles and/or groups.
 29  
  * <p/>
 30  
  * Most typical systems are what the Shiro team calls <em>role-based</em> in nature, where a role represents
 31  
  * common behavior for certain user types.  For example, a system might have an <em>Aministrator</em> role, a
 32  
  * <em>User</em> or <em>Guest</em> roles, etc.
 33  
  * <p/>
 34  
  * But if you have a dynamic security model, where roles can be created and deleted at runtime, you can't hard-code
 35  
  * role names in your code.  In this environment, roles themselves aren't aren't very useful.  What matters is what
 36  
  * <em>permissions</em> are assigned to these roles.
 37  
  * <p/>
 38  
  * Under this paradigm, permissions are immutable and reflect an application's raw functionality
 39  
  * (opening files, accessing a web URL, creating users, etc).  This is what allows a system's security policy
 40  
  * to be dynamic: because Permissions represent raw functionality and only change when the application's
 41  
  * source code changes, they are immutable at runtime - they represent 'what' the system can do.  Roles, users, and
 42  
  * groups are the 'who' of the application.  Determining 'who' can do 'what' then becomes a simple exercise of
 43  
  * associating Permissions to roles, users, and groups in some way.
 44  
  * <p/>
 45  
  * Most applications do this by associating a named role with permissions (i.e. a role 'has a' collection of
 46  
  * Permissions) and then associate users with roles (i.e. a user 'has a' collection of roles) so that by transitive
 47  
  * association, the user 'has' the permissions in their roles.  There are numerous variations on this theme
 48  
  * (permissions assigned directly to users, or assigned to groups, and users added to groups and these groups in turn
 49  
  * have roles, etc, etc).  When employing a permission-based security model instead of a role-based one, users, roles,
 50  
  * and groups can all be created, configured and/or deleted at runtime.  This enables  an extremely powerful security
 51  
  * model.
 52  
  * <p/>
 53  
  * A benefit to Shiro is that, although it assumes most systems are based on these types of static role or
 54  
  * dynamic role w/ permission schemes, it does not require a system to model their security data this way - all
 55  
  * Permission checks are relegated to {@link org.apache.shiro.realm.Realm} implementations, and only those
 56  
  * implementations really determine how a user 'has' a permission or not.  The Realm could use the semantics described
 57  
  * here, or it could utilize some other mechanism entirely - it is always up to the application developer.
 58  
  * <p/>
 59  
  * Shiro provides a very powerful default implementation of this interface in the form of the
 60  
  * {@link org.apache.shiro.authz.permission.WildcardPermission WildcardPermission}.  We highly recommend that you
 61  
  * investigate this class before trying to implement your own <code>Permission</code>s.
 62  
  *
 63  
  * @see org.apache.shiro.authz.permission.WildcardPermission WildcardPermission
 64  
  * @since 0.2
 65  
  */
 66  
 public interface Permission {
 67  
 
 68  
     /**
 69  
      * Returns {@code true} if this current instance <em>implies</em> all the functionality and/or resource access
 70  
      * described by the specified {@code Permission} argument, {@code false} otherwise.
 71  
      * <p/>
 72  
      * <p>That is, this current instance must be exactly equal to or a <em>superset</em> of the functionalty
 73  
      * and/or resource access described by the given {@code Permission} argument.  Yet another way of saying this
 74  
      * would be:
 75  
      * <p/>
 76  
      * <p>If &quot;permission1 implies permission2&quot;, i.e. <code>permission1.implies(permission2)</code> ,
 77  
      * then any Subject granted {@code permission1} would have ability greater than or equal to that defined by
 78  
      * {@code permission2}.
 79  
      *
 80  
      * @param p the permission to check for behavior/functionality comparison.
 81  
      * @return {@code true} if this current instance <em>implies</em> all the functionality and/or resource access
 82  
      *         described by the specified {@code Permission} argument, {@code false} otherwise.
 83  
      */
 84  
     boolean implies(Permission p);
 85  
 }