Keel 2.1RC2

org.keel.services.authorization.defaultauth
Class DBAuthorizationManager

java.lang.Object
  extended byorg.keel.core.container.AbstractKeelServiceable
      extended byorg.keel.services.authorization.defaultauth.DBAuthorizationManager
All Implemented Interfaces:
AuthorizationManager, Configurable, LogEnabled, Serviceable, ThreadSafe

public class DBAuthorizationManager
extends AbstractKeelServiceable
implements AuthorizationManager, LogEnabled, ThreadSafe, Configurable

This class is an implementation of the AuthorizationManager to authorize services based on database security tables. This class is a keel service based on the AuthorizationManager role. Each service which is Securable obtains this service from the KeelContainer in the setAuthorizationManager() lifecycle method..

Author:
Santanu Dutt TODO: Use cache service to cache permissions, rather then working them out from the database. Have some means (Restartable?) to clear cache at runtime, forcing new info to be re-read. Maybe this needs to be an AuthorizationManager API change, to have a "clearCache()" method

Field Summary
private  AuthorizationManager bypassAm
           
private  Logger log
           
private  boolean rootBypass
           
 
Fields inherited from class org.keel.core.container.AbstractKeelServiceable
 
Fields inherited from interface org.keel.services.authorization.AuthorizationManager
ROLE
 
Constructor Summary
DBAuthorizationManager()
           
 
Method Summary
 boolean allowed(java.lang.Object service, Context c)
          Same as allowed(Principal), but if the SecurityManager is Contextualizable, it can determine the principal(s) on it's own
 boolean allowed(java.lang.Object component, UserEnvironment ue)
          If we don't specify an operation, determine if the user is allowed to do *anything* with this component.
 boolean allowed(Operation o, Context c)
          If the instance of this SecurityManager is Contextualizable, then we can determine the principal(s) by getting the UserEnvironment from the context.
 boolean allowed(Operation o, UserEnvironment ue)
          Is the specified operation allowed for the given principal? First check all the groups, then check for specific user permission if none of the groups this user belongs to are permitted this operation.
private  boolean checkInstanceSecurable(Operation o, UserEnvironment ue)
           
private  boolean checkInstanceSecurableInstance(Operation o, UserEnvironment ue, java.lang.String instanceName)
          Check permissions for a InstanceSecurable component (e.g.
private  boolean checkInvokationSecurable(Operation o, UserEnvironment ue)
          Check for Invokation-level authorization if all other authorization has been granted.
private  boolean checkSecurable(Operation o, UserEnvironment ue)
          Check permissions for a "regular" Securable component (e.g.
private  boolean compare(Persistent rule, java.lang.Object propValue, UserEnvironment ue)
           
 void configure(Configuration configuration)
          Pass the Configuration to the Configurable class.
 void enableLogging(Logger newLog)
          Provide component with a logger.
private  java.lang.String expandValue(java.lang.String value, UserEnvironment ue)
          Translate a value beginning with "$" to some specific value based on the current user.
private  java.lang.String getComponentName(java.lang.Object component)
          Utility method to get the component name corresponding to a given object
private  PersistentFactory getPersistentFactory()
          Obtains the PersistentFactory to be used when checking authorization
private  PersistentFactory getPersistentFactory(Context c)
          Obtains the PersistentFactory initialized with a specific context
 
Methods inherited from class org.keel.core.container.AbstractKeelServiceable
getService, getService, getService, getService, getServiceManager, getServiceSelector, releaseService, releaseServices, service
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private Logger log

rootBypass

private boolean rootBypass

bypassAm

private AuthorizationManager bypassAm
Constructor Detail

DBAuthorizationManager

public DBAuthorizationManager()
Method Detail

enableLogging

public void enableLogging(Logger newLog)
Description copied from interface: LogEnabled
Provide component with a logger.

Specified by:
enableLogging in interface LogEnabled
Parameters:
newLog - the logger. Must not be null.

allowed

public boolean allowed(Operation o,
                       UserEnvironment ue)
                throws AuthorizationException
Is the specified operation allowed for the given principal? First check all the groups, then check for specific user permission if none of the groups this user belongs to are permitted this operation.

Specified by:
allowed in interface AuthorizationManager
Throws:
AuthorizationException

checkSecurable

private boolean checkSecurable(Operation o,
                               UserEnvironment ue)
                        throws AuthorizationException
Check permissions for a "regular" Securable component (e.g. not one which is Invokation or Instance securable)

Parameters:
o -
ue -
Returns:
Throws:
AuthorizationException

allowed

public boolean allowed(java.lang.Object component,
                       UserEnvironment ue)
                throws AuthorizationException
If we don't specify an operation, determine if the user is allowed to do *anything* with this component. This is used for securing the entire component - e.g. a Model First it checks whether the Groups of which the user is a member are allowed access. If none are, then it checks for specific user access.

Specified by:
allowed in interface AuthorizationManager
Returns:
True if the component is allowed at all, false if it is denied
Throws:
AuthorizationException

allowed

public boolean allowed(java.lang.Object service,
                       Context c)
                throws AuthorizationException
Same as allowed(Principal), but if the SecurityManager is Contextualizable, it can determine the principal(s) on it's own

Specified by:
allowed in interface AuthorizationManager
Returns:
True if the access is granted, false if it is denied
Throws:
AuthorizationException - If an error occurs trying to determine if the access is granted or not.

getPersistentFactory

private PersistentFactory getPersistentFactory()
                                        throws AuthorizationException
Obtains the PersistentFactory to be used when checking authorization

Returns:
A persistent factory initialized with a default context
Throws:
AuthorizationException - if it is not possible to access the factory

checkInvokationSecurable

private boolean checkInvokationSecurable(Operation o,
                                         UserEnvironment ue)
                                  throws AuthorizationException
Check for Invokation-level authorization if all other authorization has been granted.

Parameters:
o - The Operation requested
ue - The UserEnvironment describing the currently logged-in user
Returns:
True if authorization is granted, or if this object is not securable at the invokation level
Throws:
AuthorizationException - If an error occurs during verification of authorization

compare

private boolean compare(Persistent rule,
                        java.lang.Object propValue,
                        UserEnvironment ue)
                 throws PersistenceException,
                        AuthorizationException
Throws:
PersistenceException
AuthorizationException

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Description copied from interface: Configurable
Pass the Configuration to the Configurable class.

Specified by:
configure in interface Configurable
Parameters:
configuration - the class configurations. Must not be null.
Throws:
ConfigurationException - if an error occurs
See Also:
Configurable.configure(org.apache.avalon.framework.configuration.Configuration)

allowed

public boolean allowed(Operation o,
                       Context c)
                throws AuthorizationException
If the instance of this SecurityManager is Contextualizable, then we can determine the principal(s) by getting the UserEnvironment from the context. This is essentially a convenience method for allowed(Operation, UserEnvironment)

Specified by:
allowed in interface AuthorizationManager
Parameters:
o - The Operation object that describes the requested operation
c - The Context we use to determine who the user is making the request
Returns:
True if the operation is allowed, false if not.
Throws:
AuthorizationException - If an error occurs while trying to determine authorization

getPersistentFactory

private PersistentFactory getPersistentFactory(Context c)
                                        throws AuthorizationException
Obtains the PersistentFactory initialized with a specific context

Throws:
AuthorizationException

expandValue

private java.lang.String expandValue(java.lang.String value,
                                     UserEnvironment ue)
                              throws AuthorizationException
Translate a value beginning with "$" to some specific value based on the current user.

Parameters:
value -
Returns:
Either the same value unchanged (if it does not begin with a "$" or is not a recognized special tag value), or the translated value.
Throws:
AuthorizationException

getComponentName

private java.lang.String getComponentName(java.lang.Object component)
Utility method to get the component name corresponding to a given object

Parameters:
component -
Returns:

checkInstanceSecurable

private boolean checkInstanceSecurable(Operation o,
                                       UserEnvironment ue)
                                throws AuthorizationException
Throws:
AuthorizationException

checkInstanceSecurableInstance

private boolean checkInstanceSecurableInstance(Operation o,
                                               UserEnvironment ue,
                                               java.lang.String instanceName)
                                        throws AuthorizationException
Check permissions for a InstanceSecurable component (e.g. not one which is Invokation or Instance securable)

Parameters:
o -
ue -
Returns:
Throws:
AuthorizationException

Keel 2.1RC2

Please see keelframework.org for information about new Keel releases.