org.wamblee.security.authorization
Class DefaultAuthorizationService

java.lang.Object
  extended by org.wamblee.persistence.AbstractPersistent
      extended by org.wamblee.security.authorization.DefaultAuthorizationService
All Implemented Interfaces:
Persistent, AuthorizationService

public class DefaultAuthorizationService
extends AbstractPersistent
implements AuthorizationService

Default implementation of an authorization service. To determine whether access to a resource is allowed, the service consults a number of authorization rules in a fixed order. The first rule that gives a result GRANTED or DENIED determines the result of the evaluation. Rules that return any other result are ignoed. If none of the rules match, than access is denied.

Author:
Erik Brakkee

Constructor Summary
DefaultAuthorizationService()
          Constructs the authorization service.
DefaultAuthorizationService(UserAccessor aAccessor, java.lang.String aName)
          Constructs the service.
 
Method Summary
 void appendRule(AuthorizationRule aRule)
          Appends a new authorization rule to the end.
<T> T
check(T aResource, Operation aOperation)
          Same as AuthorizationService.isAllowed(Object, Operation) but throws a RuntimeException in case access is not allowed.
protected  java.util.List<AuthorizationRule> getMappedRules()
          For OR mapping.
protected  java.lang.String getName()
           
 AuthorizationRule[] getRules()
          Gets the authorization rules.
 void insertRuleAfter(int aIndex, AuthorizationRule aRule)
          Inserts a rule.
 boolean isAllowed(java.lang.Object aResource, Operation aOperation)
          Checks whether an operation is allowed on a resource.
 void removeRule(int aIndex)
          Removes a rule.
protected  void setMappedRules(java.util.List<AuthorizationRule> aRules)
          For OR mapping.
 void setName(java.lang.String aName)
           
 void setUserAccessor(UserAccessor aUserAccessor)
          Sets the user accessor.
 
Methods inherited from class org.wamblee.persistence.AbstractPersistent
getPersistedVersion, getPrimaryKey, setPersistedVersion, setPrimaryKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.wamblee.persistence.Persistent
getPersistedVersion, getPrimaryKey, setPersistedVersion, setPrimaryKey
 

Constructor Detail

DefaultAuthorizationService

public DefaultAuthorizationService(UserAccessor aAccessor,
                                   java.lang.String aName)
Constructs the service.

Parameters:
aAccessor - User accessor.
aName - Name of this instance of the service.

DefaultAuthorizationService

public DefaultAuthorizationService()
Constructs the authorization service.

Method Detail

setUserAccessor

public void setUserAccessor(UserAccessor aUserAccessor)
Sets the user accessor.

Parameters:
aUserAccessor - User accessor.

isAllowed

public boolean isAllowed(java.lang.Object aResource,
                         Operation aOperation)
Description copied from interface: AuthorizationService
Checks whether an operation is allowed on a resource.

Specified by:
isAllowed in interface AuthorizationService
Parameters:
aResource - Resource.
aOperation - Operation.
Returns:
Checks whether the operation is allowed on a resource.

check

public <T> T check(T aResource,
                   Operation aOperation)
Description copied from interface: AuthorizationService
Same as AuthorizationService.isAllowed(Object, Operation) but throws a RuntimeException in case access is not allowed.

Specified by:
check in interface AuthorizationService
Parameters:
aResource - Resource to check.
aOperation - Operation to perform.
Returns:
Resource that was checked.

getName

protected java.lang.String getName()

setName

public void setName(java.lang.String aName)

getRules

public AuthorizationRule[] getRules()
Description copied from interface: AuthorizationService
Gets the authorization rules.

Specified by:
getRules in interface AuthorizationService
Returns:
Rules.

appendRule

public void appendRule(AuthorizationRule aRule)
Description copied from interface: AuthorizationService
Appends a new authorization rule to the end.

Specified by:
appendRule in interface AuthorizationService
Parameters:
aRule - Rule to append.

insertRuleAfter

public void insertRuleAfter(int aIndex,
                            AuthorizationRule aRule)
Description copied from interface: AuthorizationService
Inserts a rule.

Specified by:
insertRuleAfter in interface AuthorizationService
Parameters:
aIndex - Index of the position of the rule after insertion.
aRule - Rule to insert.

removeRule

public void removeRule(int aIndex)
Description copied from interface: AuthorizationService
Removes a rule.

Specified by:
removeRule in interface AuthorizationService

getMappedRules

protected java.util.List<AuthorizationRule> getMappedRules()
For OR mapping.

Returns:
The rules.

setMappedRules

protected void setMappedRules(java.util.List<AuthorizationRule> aRules)
For OR mapping.

Parameters:
aRules - The rules.


Copyright © 2010. All Rights Reserved.