org.apache.jackrabbit.core.security
Class DefaultAccessManager

java.lang.Object
  extended by org.apache.jackrabbit.core.security.AbstractAccessControlManager
      extended by org.apache.jackrabbit.core.security.DefaultAccessManager
All Implemented Interfaces:
AccessControlManager, JackrabbitAccessControlManager, AccessManager

public class DefaultAccessManager
extends AbstractAccessControlManager
implements AccessManager

The DefaultAccessManager controls access by evaluating access control policies for the Subject attached to the Session this manager has been built for.

Please note the following exceptional situations:
This manager allows all privileges for a particular item if

It allows to access all available workspaces if

How access control policies are matched to a particular item is defined by the AccessControlProvider set to this AccessManager.

See Also:
AccessManager, AccessControlManager

Field Summary
 
Fields inherited from interface org.apache.jackrabbit.core.security.AccessManager
READ, REMOVE, WRITE
 
Constructor Summary
DefaultAccessManager()
           
 
Method Summary
 boolean canAccess(String workspaceName)
          Determines whether the subject of the current context is granted access to the given workspace.
 boolean canRead(Path itemPath, ItemId itemId)
          Determines whether the item with the specified itemPath or itemId can be read.
protected  void checkInitialized()
          Check if this manager has been properly initialized.
 void checkPermission(ItemId id, int permissions)
          Determines whether the specified permissions are granted on the item with the specified id (i.e. the target item).
 void checkPermission(Path absPath, int permissions)
          Determines whether the specified permissions are granted on the item with the specified id (i.e. the target item).
protected  void checkPermission(String absPath, int permission)
          Check if the specified privileges are granted at absPath.
protected  void checkValidNodePath(String absPath)
          Tests if the given absPath is absolute and points to an existing node.
 void close()
          Close this access manager.
 JackrabbitAccessControlPolicy[] getApplicablePolicies(Principal principal)
          Returns the applicable policies for the specified principal or an empty array if no additional policies can be applied.
 AccessControlPolicyIterator getApplicablePolicies(String absPath)
          Returns an empty iterator.
 AccessControlPolicy[] getEffectivePolicies(Set<Principal> principals)
          Returns the AccessControlPolicy objects that are in effect for the given Principals.
 AccessControlPolicy[] getEffectivePolicies(String absPath)
           
 JackrabbitAccessControlPolicy[] getPolicies(Principal principal)
          Returns the AccessControlPolicy objects that have been set for the given principal or an empty array if no policy has been set.
 AccessControlPolicy[] getPolicies(String absPath)
          Returns null.
protected  PrivilegeRegistry getPrivilegeRegistry()
           
 Privilege[] getPrivileges(String absPath)
           
 Privilege[] getPrivileges(String absPath, Set<Principal> principals)
          Returns the privileges the given set of Principals has for absolute path absPath, which must be an existing node.
 boolean hasPrivileges(String absPath, Privilege[] privileges)
           
 boolean hasPrivileges(String absPath, Set<Principal> principals, Privilege[] privileges)
          Returns whether the given set of Principals has the specified privileges for absolute path absPath, which must be an existing node.
 void init(AMContext amContext)
          Initialize this access manager.
 void init(AMContext amContext, AccessControlProvider acProvider, WorkspaceAccessManager wspAccessManager)
          Initialize this access manager.
 boolean isGranted(ItemId id, int actions)
          Determines whether the specified permissions are granted on the item with the specified id (i.e. the target item).
 boolean isGranted(Path absPath, int permissions)
          Determines whether the specified permissions are granted on the item with the specified absPath (i.e. the target item, that may or may not yet exist).
 boolean isGranted(Path parentPath, Name childName, int permissions)
          Determines whether the specified permissions are granted on an item represented by the combination of the given parentPath and childName (i.e. the target item, that may or may not yet exist).
 void removePolicy(String absPath, AccessControlPolicy policy)
          Always throws AccessControlException
 void setPolicy(String absPath, AccessControlPolicy policy)
          Always throws AccessControlException
 
Methods inherited from class org.apache.jackrabbit.core.security.AbstractAccessControlManager
getSupportedPrivileges, privilegeFromName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAccessManager

public DefaultAccessManager()
Method Detail

init

public void init(AMContext amContext)
          throws AccessDeniedException,
                 Exception
Description copied from interface: AccessManager
Initialize this access manager. An AccessDeniedException will be thrown if the subject of the given context is not granted access to the specified workspace.

Specified by:
init in interface AccessManager
Parameters:
amContext - access manager context
Throws:
AccessDeniedException - if the subject is not granted access to the specified workspace.
Exception - if another error occurs
See Also:
AccessManager.init(AMContext)

init

public void init(AMContext amContext,
                 AccessControlProvider acProvider,
                 WorkspaceAccessManager wspAccessManager)
          throws AccessDeniedException,
                 Exception
Description copied from interface: AccessManager
Initialize this access manager. An AccessDeniedException will be thrown if the subject of the given context is not granted access to the specified workspace.

Specified by:
init in interface AccessManager
Parameters:
amContext - access manager context.
acProvider - The access control provider.
wspAccessManager - The workspace access manager.
Throws:
AccessDeniedException - if the subject is not granted access to the specified workspace.
Exception - if another error occurs
See Also:
AccessManager.init(AMContext, AccessControlProvider, WorkspaceAccessManager)

close

public void close()
           throws Exception
Description copied from interface: AccessManager
Close this access manager. After having closed an access manager, further operations on this object are treated as illegal and throw

Specified by:
close in interface AccessManager
Throws:
Exception - if an error occurs
See Also:
AccessManager.close()

checkPermission

public void checkPermission(ItemId id,
                            int permissions)
                     throws AccessDeniedException,
                            ItemNotFoundException,
                            RepositoryException
Description copied from interface: AccessManager
Determines whether the specified permissions are granted on the item with the specified id (i.e. the target item).

Specified by:
checkPermission in interface AccessManager
Parameters:
id - the id of the target item
permissions - A combination of one or more of the following constants encoded as a bitmask value:
  • READ
  • WRITE
  • REMOVE
Throws:
AccessDeniedException - if permission is denied
ItemNotFoundException - if the target item does not exist
RepositoryException - it an error occurs
See Also:
AccessManager.checkPermission(ItemId, int)

checkPermission

public void checkPermission(Path absPath,
                            int permissions)
                     throws AccessDeniedException,
                            RepositoryException
Description copied from interface: AccessManager
Determines whether the specified permissions are granted on the item with the specified id (i.e. the target item).

Specified by:
checkPermission in interface AccessManager
Parameters:
absPath - Path to an item.
permissions - A combination of one or more of the Permission constants encoded as a bitmask value.
Throws:
AccessDeniedException - if permission is denied
RepositoryException - it another error occurs
See Also:
AccessManager.checkPermission(Path, int)

isGranted

public boolean isGranted(ItemId id,
                         int actions)
                  throws ItemNotFoundException,
                         RepositoryException
Description copied from interface: AccessManager
Determines whether the specified permissions are granted on the item with the specified id (i.e. the target item).

Specified by:
isGranted in interface AccessManager
Parameters:
id - the id of the target item
actions - A combination of one or more of the following constants encoded as a bitmask value:
  • READ
  • WRITE
  • REMOVE
Returns:
true if permission is granted; otherwise false
Throws:
ItemNotFoundException - if the target item does not exist
RepositoryException - if another error occurs
See Also:
AccessManager.isGranted(ItemId, int)

isGranted

public boolean isGranted(Path absPath,
                         int permissions)
                  throws RepositoryException
Description copied from interface: AccessManager
Determines whether the specified permissions are granted on the item with the specified absPath (i.e. the target item, that may or may not yet exist).

Specified by:
isGranted in interface AccessManager
Parameters:
absPath - the absolute path to test
permissions - A combination of one or more of the Permission constants encoded as a bitmask value.
Returns:
true if the specified permissions are granted; otherwise false.
Throws:
RepositoryException - if an error occurs.
See Also:
AccessManager.isGranted(Path, int)

isGranted

public boolean isGranted(Path parentPath,
                         Name childName,
                         int permissions)
                  throws RepositoryException
Description copied from interface: AccessManager
Determines whether the specified permissions are granted on an item represented by the combination of the given parentPath and childName (i.e. the target item, that may or may not yet exist).

Specified by:
isGranted in interface AccessManager
Parameters:
parentPath - Path to an existing parent node.
childName - Name of the child item that may or may not exist yet.
permissions - A combination of one or more of the Permission constants encoded as a bitmask value.
Returns:
true if the specified permissions are granted; otherwise false.
Throws:
RepositoryException - if an error occurs.
See Also:
AccessManager.isGranted(Path, Name, int)

canRead

public boolean canRead(Path itemPath,
                       ItemId itemId)
                throws RepositoryException
Description copied from interface: AccessManager
Determines whether the item with the specified itemPath or itemId can be read. Either of the two parameters may be null.
Note, that this method should only be called for persisted items as NEW items may not be visible to the permission evaluation. For new items AccessManager.isGranted(Path, int) should be used instead.

If this method is called with both Path and ItemId it is left to the evaluation, which parameter is used.

Specified by:
canRead in interface AccessManager
Parameters:
itemPath - The path to the item or null if itemId should be used to determine the READ permission.
itemId - Id of the item to be tested or null if the itemPath should be used to determine the permission.
Returns:
true if the item can be read; otherwise false.
Throws:
RepositoryException - if the item is NEW and only an itemId is specified or if another error occurs.
See Also:
AccessManager.canRead(org.apache.jackrabbit.spi.Path,org.apache.jackrabbit.core.id.ItemId)

canAccess

public boolean canAccess(String workspaceName)
                  throws RepositoryException
Description copied from interface: AccessManager
Determines whether the subject of the current context is granted access to the given workspace. Note that an implementation is free to test for the existance of a workspace with the specified name. In this case the expected return value is false, if no such workspace exists.

Specified by:
canAccess in interface AccessManager
Parameters:
workspaceName - name of workspace
Returns:
true if the subject of the current context is granted access to the given workspace; otherwise false.
Throws:
RepositoryException - if an error occurs.
See Also:
AccessManager.canAccess(String)

hasPrivileges

public boolean hasPrivileges(String absPath,
                             Privilege[] privileges)
                      throws PathNotFoundException,
                             RepositoryException
Specified by:
hasPrivileges in interface AccessControlManager
Throws:
PathNotFoundException
RepositoryException
See Also:
AccessControlManager.hasPrivileges(String, Privilege[])

getPrivileges

public Privilege[] getPrivileges(String absPath)
                          throws PathNotFoundException,
                                 RepositoryException
Specified by:
getPrivileges in interface AccessControlManager
Throws:
PathNotFoundException
RepositoryException
See Also:
AccessControlManager.getPrivileges(String)

getPolicies

public AccessControlPolicy[] getPolicies(String absPath)
                                  throws PathNotFoundException,
                                         AccessDeniedException,
                                         RepositoryException
Description copied from class: AbstractAccessControlManager
Returns null.

Specified by:
getPolicies in interface AccessControlManager
Overrides:
getPolicies in class AbstractAccessControlManager
Parameters:
absPath - Path to an existing node.
Returns:
always returns null.
Throws:
PathNotFoundException
AccessDeniedException
RepositoryException
See Also:
AccessControlManager.getPolicies(String)

getEffectivePolicies

public AccessControlPolicy[] getEffectivePolicies(String absPath)
                                           throws PathNotFoundException,
                                                  AccessDeniedException,
                                                  RepositoryException
Specified by:
getEffectivePolicies in interface AccessControlManager
Throws:
PathNotFoundException
AccessDeniedException
RepositoryException
See Also:
AccessControlManager.getEffectivePolicies(String)

getApplicablePolicies

public AccessControlPolicyIterator getApplicablePolicies(String absPath)
                                                  throws PathNotFoundException,
                                                         AccessDeniedException,
                                                         RepositoryException
Description copied from class: AbstractAccessControlManager
Returns an empty iterator.

Specified by:
getApplicablePolicies in interface AccessControlManager
Overrides:
getApplicablePolicies in class AbstractAccessControlManager
Parameters:
absPath - Path to an existing node.
Returns:
always returns an empty iterator.
Throws:
PathNotFoundException
AccessDeniedException
RepositoryException
See Also:
AccessControlManager.getApplicablePolicies(String)

setPolicy

public void setPolicy(String absPath,
                      AccessControlPolicy policy)
               throws PathNotFoundException,
                      AccessControlException,
                      AccessDeniedException,
                      RepositoryException
Description copied from class: AbstractAccessControlManager
Always throws AccessControlException

Specified by:
setPolicy in interface AccessControlManager
Overrides:
setPolicy in class AbstractAccessControlManager
Throws:
PathNotFoundException
AccessControlException
AccessDeniedException
RepositoryException
See Also:
AccessControlManager.setPolicy(String, AccessControlPolicy)

removePolicy

public void removePolicy(String absPath,
                         AccessControlPolicy policy)
                  throws PathNotFoundException,
                         AccessControlException,
                         AccessDeniedException,
                         RepositoryException
Description copied from class: AbstractAccessControlManager
Always throws AccessControlException

Specified by:
removePolicy in interface AccessControlManager
Overrides:
removePolicy in class AbstractAccessControlManager
Throws:
PathNotFoundException
AccessControlException
AccessDeniedException
RepositoryException
See Also:
AccessControlManager.removePolicy(String, AccessControlPolicy)

getApplicablePolicies

public JackrabbitAccessControlPolicy[] getApplicablePolicies(Principal principal)
                                                      throws AccessDeniedException,
                                                             AccessControlException,
                                                             UnsupportedRepositoryOperationException,
                                                             RepositoryException
Description copied from interface: JackrabbitAccessControlManager
Returns the applicable policies for the specified principal or an empty array if no additional policies can be applied.

Specified by:
getApplicablePolicies in interface JackrabbitAccessControlManager
Overrides:
getApplicablePolicies in class AbstractAccessControlManager
Parameters:
principal - A principal known to the editing session.
Returns:
array of policies for the specified principal. Note that the policy object returned must reveal the path of the node where they can be applied later on using AccessControlManager.setPolicy(String, javax.jcr.security.AccessControlPolicy).
Throws:
AccessDeniedException - if the session lacks MODIFY_ACCESS_CONTROL privilege.
AccessControlException - if the specified principal does not exist or if another access control related exception occurs.
UnsupportedRepositoryOperationException - if editing access control policies by principal is not supported.
RepositoryException - if another error occurs.
See Also:
JackrabbitAccessControlManager.getApplicablePolicies(Principal)

getPolicies

public JackrabbitAccessControlPolicy[] getPolicies(Principal principal)
                                            throws AccessDeniedException,
                                                   AccessControlException,
                                                   UnsupportedRepositoryOperationException,
                                                   RepositoryException
Description copied from interface: JackrabbitAccessControlManager
Returns the AccessControlPolicy objects that have been set for the given principal or an empty array if no policy has been set. This method reflects the binding state, including transient policy modifications.

Specified by:
getPolicies in interface JackrabbitAccessControlManager
Overrides:
getPolicies in class AbstractAccessControlManager
Parameters:
principal - A valid principal.
Returns:
The policies defined for the given principal or an empty array.
Throws:
AccessDeniedException - if the session lacks READ_ACCESS_CONTROL privilege.
AccessControlException - if the specified principal does not exist or if another access control related exception occurs.
UnsupportedRepositoryOperationException - if editing access control policies by principal is not supported.
RepositoryException - If another error occurs.
See Also:
JackrabbitAccessControlManager.getPolicies(Principal)

getEffectivePolicies

public AccessControlPolicy[] getEffectivePolicies(Set<Principal> principals)
                                           throws AccessDeniedException,
                                                  AccessControlException,
                                                  UnsupportedRepositoryOperationException,
                                                  RepositoryException
Description copied from interface: JackrabbitAccessControlManager
Returns the AccessControlPolicy objects that are in effect for the given Principals. This may be policies set through this API or some implementation specific (default) policies.

Specified by:
getEffectivePolicies in interface JackrabbitAccessControlManager
Parameters:
principals - A set of valid principals.
Returns:
The policies defined for the given principal or an empty array.
Throws:
AccessDeniedException - if the session lacks READ_ACCESS_CONTROL privilege.
AccessControlException - if the specified principal does not exist or if another access control related exception occurs.
UnsupportedRepositoryOperationException - if editing access control policies by principal is not supported.
RepositoryException - If another error occurs.
See Also:
JackrabbitAccessControlManager.getEffectivePolicies(Set)

hasPrivileges

public boolean hasPrivileges(String absPath,
                             Set<Principal> principals,
                             Privilege[] privileges)
                      throws PathNotFoundException,
                             RepositoryException
Description copied from interface: JackrabbitAccessControlManager
Returns whether the given set of Principals has the specified privileges for absolute path absPath, which must be an existing node.

Testing an aggregate privilege is equivalent to testing each non aggregate privilege among the set returned by calling Privilege.getAggregatePrivileges() for that privilege.

The results reported by the this method reflect the net effect of the currently applied control mechanisms. It does not reflect unsaved access control policies or unsaved access control entries. Changes to access control status caused by these mechanisms only take effect on Session.save() and are only then reflected in the results of the privilege test methods.

Since this method allows to view the privileges of principals other than included in the editing session, this method must throw AccessDeniedException if the session lacks READ_ACCESS_CONTROL privilege for the absPath node.

Specified by:
hasPrivileges in interface JackrabbitAccessControlManager
Parameters:
absPath - an absolute path.
principals - a set of Principals for which is the given privileges are tested.
privileges - an array of Privileges.
Returns:
true if the session has the specified privileges; false otherwise.
Throws:
PathNotFoundException - if no node at absPath exists or the session does not have sufficient access to retrieve a node at that location.
AccessDeniedException - if the session lacks READ_ACCESS_CONTROL privilege for the absPath node.
RepositoryException - if another error occurs.
See Also:
JackrabbitAccessControlManager.hasPrivileges(String, Set, Privilege[])

getPrivileges

public Privilege[] getPrivileges(String absPath,
                                 Set<Principal> principals)
                          throws PathNotFoundException,
                                 RepositoryException
Description copied from interface: JackrabbitAccessControlManager
Returns the privileges the given set of Principals has for absolute path absPath, which must be an existing node.

The returned privileges are those for which JackrabbitAccessControlManager.hasPrivileges(java.lang.String, java.util.Set, javax.jcr.security.Privilege[]) would return true.

The results reported by the this method reflect the net effect of the currently applied control mechanisms. It does not reflect unsaved access control policies or unsaved access control entries. Changes to access control status caused by these mechanisms only take effect on Session.save() and are only then reflected in the results of the privilege test methods.

Since this method allows to view the privileges of principals other than included in the editing session, this method must throw AccessDeniedException if the session lacks READ_ACCESS_CONTROL privilege for the absPath node.

Note that this method does not resolve any group membership, as this is the job of the user manager. nor does it augment the set with the "everyone" principal.

Specified by:
getPrivileges in interface JackrabbitAccessControlManager
Parameters:
absPath - an absolute path.
principals - a set of Principals for which is the privileges are retrieved.
Returns:
an array of Privileges.
Throws:
PathNotFoundException - if no node at absPath exists or the session does not have sufficient access to retrieve a node at that location.
AccessDeniedException - if the session lacks READ_ACCESS_CONTROL privilege for the absPath node.
RepositoryException - if another error occurs.
See Also:
JackrabbitAccessControlManager.getPrivileges(String, Set)

checkInitialized

protected void checkInitialized()
Description copied from class: AbstractAccessControlManager
Check if this manager has been properly initialized.

Specified by:
checkInitialized in class AbstractAccessControlManager
See Also:
AbstractAccessControlManager.checkInitialized()

checkValidNodePath

protected void checkValidNodePath(String absPath)
                           throws PathNotFoundException,
                                  RepositoryException
Description copied from class: AbstractAccessControlManager
Tests if the given absPath is absolute and points to an existing node.

Specified by:
checkValidNodePath in class AbstractAccessControlManager
Parameters:
absPath - Path to an existing node.
Throws:
PathNotFoundException - if no node at absPath exists or the session does not have privilege to retrieve the node.
RepositoryException - If the given absPath is not absolute or if some other error occurs.
See Also:
AbstractAccessControlManager.checkValidNodePath(String)

checkPermission

protected void checkPermission(String absPath,
                               int permission)
                        throws AccessDeniedException,
                               RepositoryException
Description copied from class: AbstractAccessControlManager
Check if the specified privileges are granted at absPath.

Specified by:
checkPermission in class AbstractAccessControlManager
Parameters:
absPath - Path to an existing node.
permission - Permissions to be checked.
Throws:
AccessDeniedException - if the session does not have the specified privileges.
PathNotFoundException - if no node exists at absPath of if the session does not have the permission to READ it.
RepositoryException - If another error occurs.
See Also:
AbstractAccessControlManager.checkPermission(String,int)

getPrivilegeRegistry

protected PrivilegeRegistry getPrivilegeRegistry()
                                          throws RepositoryException
Specified by:
getPrivilegeRegistry in class AbstractAccessControlManager
Returns:
the privilege registry
Throws:
RepositoryException - If another error occurs.
See Also:
AbstractAccessControlManager.getPrivilegeRegistry()


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.