org.mycore.access
Class MCRAccessBaseImpl

java.lang.Object
  extended by org.mycore.access.MCRAccessBaseImpl
All Implemented Interfaces:
MCRAccessInterface
Direct Known Subclasses:
MCRAccessControlSystem

public class MCRAccessBaseImpl
extends Object
implements MCRAccessInterface

This class is a base implementation of the MCRAccessInterface. It will simply allow everything and will do nothing on persistent operations. Feel free to extend this class if your implementation can only support parts of the Interface definition.

Author:
Jens Kupferschmidt

Field Summary
protected static String AccessPermissions
           
protected static Logger LOGGER
          the logger
 
Constructor Summary
MCRAccessBaseImpl()
           
 
Method Summary
 void addRule(String permission, Element rule, String description)
          adds an access rule for an "a priori-permission" like "create-document"
 void addRule(String id, String permission, Element rule, String description)
          adds an access rule for an ID to an access system.
 boolean checkPermission(Element rule)
          determines whether the current user has the permission to perform a certain action.
 boolean checkPermission(String permission)
          determines whether the current user has the permission to perform a certain action.
 boolean checkPermission(String permission, MCRUser user)
          determines whether a given user has the permission to perform a certain action.
 boolean checkPermission(String id, String permission)
          determines whether the current user has the permission to perform a certain action.
 boolean checkPermission(String id, String permission, MCRUser user)
          determines whether a given user has the permission to perform a certain action.
 void createRule(Element rule, String creator, String description)
          create an access rule in the rulestore using an rule string in plain text
 void createRule(String rule, String creator, String description)
          create an access rule in the rulestore using an rule string in plain text
 Collection<String> getAccessPermissionsFromConfiguration()
          just returns the String of Access Permissions configured in property "MCR.AccessPermissions"
 Collection<String> getAllControlledIDs()
          lists all String IDs, a permission is assigned to.
 String getNormalizedRuleString(Element rule)
          generate rule string from xml
 Collection<String> getPermissions()
          lists all a-priori permissions like "create-document".
 Collection<String> getPermissionsForID(String objid)
          lists all permissions defined for the id.
 Element getRule(String permission)
          exports a access rule for a "a priori permission" as JDOM element.
 Element getRule(String objID, String permission)
          exports a access rule as JDOM element.
 String getRuleDescription(String permission)
          returns the prosa description of a defined rule for a "a priori" permission like "create-document".
 String getRuleDescription(String id, String permission)
          returns the prosa description of a defined rule.
 boolean hasRule(String id)
          checks wether a rule with the id is defined.
 boolean hasRule(String id, String permission)
          checks wether a rule with the id and permission is defined.
static MCRAccessInterface instance()
          The method return a singleton instance of MCRAccessInterface.
 void removeAllRules(String id)
          removes all rules of the id.
 void removeRule(String permission)
          removes a rule for an "a priori permission" like "create-document"
 void removeRule(String id, String permission)
          removes a rule.
 void updateRule(String permission, Element rule, String description)
          updates an access rule for an "a priori permission" of an access system like "create-document".
 void updateRule(String id, String permission, Element rule, String description)
          updates an access rule for an ID to an access system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AccessPermissions

protected static final String AccessPermissions

LOGGER

protected static Logger LOGGER
the logger

Constructor Detail

MCRAccessBaseImpl

public MCRAccessBaseImpl()
Method Detail

instance

public static MCRAccessInterface instance()
The method return a singleton instance of MCRAccessInterface.

Returns:
a singleton instance of MCRAccessInterface

addRule

public void addRule(String id,
                    String permission,
                    Element rule,
                    String description)
             throws MCRException
Description copied from interface: MCRAccessInterface
adds an access rule for an ID to an access system. The parameter id serves as an identifier for the concrete underlying rule, e.g. a MCRObjectID.

Specified by:
addRule in interface MCRAccessInterface
Parameters:
id - the ID-String of the object
permission - the access permission for the rule
rule - the access rule
description - a String description of the rule in prosa
Throws:
MCRException - if an error occured

addRule

public void addRule(String permission,
                    Element rule,
                    String description)
             throws MCRException
Description copied from interface: MCRAccessInterface
adds an access rule for an "a priori-permission" like "create-document"

Specified by:
addRule in interface MCRAccessInterface
Parameters:
permission - the access permission for the rule (e.g. "create-document")
rule - the access rule
description - a String description of the rule in prosa
Throws:
MCRException - if an error occured

removeRule

public void removeRule(String id,
                       String permission)
                throws MCRException
Description copied from interface: MCRAccessInterface
removes a rule. The parameter id serves as an identifier for the concrete underlying rule, e.g. a MCRObjectID.

Specified by:
removeRule in interface MCRAccessInterface
Parameters:
id - the ID-String of the object
permission - the access permission for the rule
Throws:
MCRException - if an error occured

removeRule

public void removeRule(String permission)
                throws MCRException
Description copied from interface: MCRAccessInterface
removes a rule for an "a priori permission" like "create-document"

Specified by:
removeRule in interface MCRAccessInterface
Parameters:
permission - the access permission for the rule
Throws:
MCRException - if an error occured

removeAllRules

public void removeAllRules(String id)
                    throws MCRException
Description copied from interface: MCRAccessInterface
removes all rules of the id. The parameter id serves as an identifier for the concrete underlying rule, e.g. a MCRObjectID.

Specified by:
removeAllRules in interface MCRAccessInterface
Parameters:
id - the ID-String of the object
Throws:
MCRException - if an errow was occured

updateRule

public void updateRule(String id,
                       String permission,
                       Element rule,
                       String description)
                throws MCRException
Description copied from interface: MCRAccessInterface
updates an access rule for an ID to an access system. The parameter id serves as an identifier for the concrete underlying rule, e.g. a MCRObjectID.

Specified by:
updateRule in interface MCRAccessInterface
Parameters:
id - the ID-String of the object
permission - the access permission for the rule
rule - the access rule
description - a String description of the rule in prosa
Throws:
MCRException - if an errow was occured

updateRule

public void updateRule(String permission,
                       Element rule,
                       String description)
                throws MCRException
Description copied from interface: MCRAccessInterface
updates an access rule for an "a priori permission" of an access system like "create-document".

Specified by:
updateRule in interface MCRAccessInterface
Parameters:
permission - the access permission for the rule
rule - the access rule
description - a String description of the rule in prosa
Throws:
MCRException - if an errow was occured

checkPermission

public boolean checkPermission(String id,
                               String permission)
Description copied from interface: MCRAccessInterface
determines whether the current user has the permission to perform a certain action. All information regarding the current user is capsulated by a MCRSession instance which can be retrieved by
 MCRSession currentSession = MCRSessionMgr.getCurrentSession();
 
The parameter id serves as an identifier for the concrete underlying rule, e.g. a MCRObjectID.

Specified by:
checkPermission in interface MCRAccessInterface
Parameters:
id - the ID-String of the object
permission - the permission/action to be granted, e.g. "read"
Returns:
true if the permission is granted, else false
See Also:
MCRSessionMgr.getCurrentSession(), MCRSession

checkPermission

public boolean checkPermission(String id,
                               String permission,
                               MCRUser user)
Description copied from interface: MCRAccessInterface
determines whether a given user has the permission to perform a certain action. no session data will be checked here. The parameter id serves as an identifier for the concrete underlying rule, e.g. a MCRObjectID.

Specified by:
checkPermission in interface MCRAccessInterface
Parameters:
id - the ID-String of the object
permission - the permission/action to be granted, e.g. "read"
user - the MCRUser, whose permissions are checked
Returns:
true if the permission is granted, else false
See Also:
MCRSessionMgr.getCurrentSession(), MCRSession

checkPermission

public boolean checkPermission(String permission)
Description copied from interface: MCRAccessInterface
determines whether the current user has the permission to perform a certain action. All information regarding the current user is capsulated by a MCRSession instance which can be retrieved by
 MCRSession currentSession = MCRSessionMgr.getCurrentSession();
 
This method is used for checking "a priori permissions" like "create-document" where a String ID does not exist yet

Specified by:
checkPermission in interface MCRAccessInterface
Parameters:
permission - the permission/action to be granted, e.g. "create-document"
Returns:
true if the permission is granted, else false
See Also:
MCRSessionMgr.getCurrentSession(), MCRSession

checkPermission

public boolean checkPermission(String permission,
                               MCRUser user)
Description copied from interface: MCRAccessInterface
determines whether a given user has the permission to perform a certain action. no session data will be checked here. This method is used for checking "a priori permissions" like "create-document" where a String ID does not exist yet

Specified by:
checkPermission in interface MCRAccessInterface
Parameters:
permission - the permission/action to be granted, e.g. "create-document"
user - the MCRUser, whose permissions are checked
Returns:
true if the permission is granted, else false
See Also:
MCRSessionMgr.getCurrentSession(), MCRSession

checkPermission

public boolean checkPermission(Element rule)
Description copied from interface: MCRAccessInterface
determines whether the current user has the permission to perform a certain action. All information regarding the current user is capsulated by a MCRSession instance which can be retrieved by
 MCRSession currentSession = MCRSessionMgr.getCurrentSession();
 

Specified by:
checkPermission in interface MCRAccessInterface
Parameters:
rule - the jdom-representation of a mycore access rule
Returns:
true if the permission is granted, else false
See Also:
MCRSessionMgr.getCurrentSession(), MCRSession

getRule

public Element getRule(String objID,
                       String permission)
Description copied from interface: MCRAccessInterface
exports a access rule as JDOM element.

Specified by:
getRule in interface MCRAccessInterface
Parameters:
objID - the ID-String of the object
permission - the access permission for the rule
Returns:
the rule as jdom element, or null if no rule is defined

getRule

public Element getRule(String permission)
Description copied from interface: MCRAccessInterface
exports a access rule for a "a priori permission" as JDOM element.

Specified by:
getRule in interface MCRAccessInterface
Parameters:
permission - the access permission for the rule
Returns:
the rule as jdom element, or null if no rule is defined

getRuleDescription

public String getRuleDescription(String permission)
Description copied from interface: MCRAccessInterface
returns the prosa description of a defined rule for a "a priori" permission like "create-document".

Specified by:
getRuleDescription in interface MCRAccessInterface
Parameters:
permission - the access permission for the rule
Returns:
the String of the description

getRuleDescription

public String getRuleDescription(String id,
                                 String permission)
Description copied from interface: MCRAccessInterface
returns the prosa description of a defined rule.

Specified by:
getRuleDescription in interface MCRAccessInterface
Parameters:
id - the ID-String of the object
permission - the access permission for the rule
Returns:
the String of the description

getPermissionsForID

public Collection<String> getPermissionsForID(String objid)
Description copied from interface: MCRAccessInterface
lists all permissions defined for the id. The parameter id serves as an identifier for the concrete underlying rule, e.g. a MCRObjectID.

Specified by:
getPermissionsForID in interface MCRAccessInterface
Returns:
a List of all for id defined permission

getPermissions

public Collection<String> getPermissions()
Description copied from interface: MCRAccessInterface
lists all a-priori permissions like "create-document".

Specified by:
getPermissions in interface MCRAccessInterface
Returns:
a List of all defined permissions

hasRule

public boolean hasRule(String id,
                       String permission)
checks wether a rule with the id and permission is defined. It's the same as calling
    (getRule(id, permission)!=null);
 

Specified by:
hasRule in interface MCRAccessInterface
Parameters:
id - the ID-String of the object
permission - the access permission for the rule
Returns:
false, if getRule(id, permission) would return null, else true
See Also:
getRule(String, String)

hasRule

public boolean hasRule(String id)
checks wether a rule with the id is defined. It's the same as calling
    (getPermissionsForID(id).size()>0);
 

Specified by:
hasRule in interface MCRAccessInterface
Parameters:
id - the ID-String of the object
Returns:
false, if getPermissionsForID(id) would return an empty list, else true
See Also:
getRule(String, String)

getAccessPermissionsFromConfiguration

public Collection<String> getAccessPermissionsFromConfiguration()
just returns the String of Access Permissions configured in property "MCR.AccessPermissions"

Specified by:
getAccessPermissionsFromConfiguration in interface MCRAccessInterface
Returns:
the permissions as List

getAllControlledIDs

public Collection<String> getAllControlledIDs()
Description copied from interface: MCRAccessInterface
lists all String IDs, a permission is assigned to. The parameter id serves as an identifier for the concrete underlying rule, e.g. a MCRObjectID.

Specified by:
getAllControlledIDs in interface MCRAccessInterface
Returns:
a sorted and distinct List of all String IDs

createRule

public void createRule(String rule,
                       String creator,
                       String description)
Description copied from interface: MCRAccessInterface
create an access rule in the rulestore using an rule string in plain text

Specified by:
createRule in interface MCRAccessInterface
Parameters:
rule - the rule string in plain text
description - a String description of the rule in prosa

createRule

public void createRule(Element rule,
                       String creator,
                       String description)
Description copied from interface: MCRAccessInterface
create an access rule in the rulestore using an rule string in plain text

Specified by:
createRule in interface MCRAccessInterface
Parameters:
rule - the rule string as xml
description - a String description of the rule in prosa

getNormalizedRuleString

public String getNormalizedRuleString(Element rule)
Description copied from interface: MCRAccessInterface
generate rule string from xml

Specified by:
getNormalizedRuleString in interface MCRAccessInterface
Returns:
the normalized rule string