Package ome.security.policy
Class DefaultPolicyService
- java.lang.Object
-
- ome.tools.spring.OnContextRefreshedEventListener
-
- ome.security.policy.DefaultPolicyService
-
- All Implemented Interfaces:
java.util.EventListener
,PolicyService
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
public class DefaultPolicyService extends OnContextRefreshedEventListener implements PolicyService
PolicyService
which is configured with allPolicy
instances which are discovered in the Spring context and only focuses on a small subset ofIObject
types as specified byfilterObject(IObject)
.
-
-
Constructor Summary
Constructors Constructor Description DefaultPolicyService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkRestriction(java.lang.String name, ome.model.IObject obj)
Give each configuredPolicy
instance the chance to throw aSecurityViolation
from itsPolicy.checkRestriction(IObject)
method.protected boolean
filterObject(ome.model.IObject obj)
Limit the objects to whichPolicy
instances are applied.void
handleContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent event)
Loads allPolicy
instances from the context, and uses them to initialize thisPolicyService
.boolean
isRestricted(java.lang.String name, ome.model.IObject obj)
Ask each configuredPolicy
instance with the given name argument if it considers the restriction active for the givenIObject
argument.java.util.Set<java.lang.String>
listActiveRestrictions(ome.model.IObject obj)
Return all identifier strings as would be passed as the first argument toPolicyService.isRestricted(String, IObject)
orPolicyService.checkRestriction(String, IObject)
which considers itself active for the given argument.java.util.Set<java.lang.String>
listAllRestrictions()
Return all configured identifier strings as would be passed as the first argument toPolicyService.isRestricted(String, IObject)
orPolicyService.checkRestriction(String, IObject)
.-
Methods inherited from class ome.tools.spring.OnContextRefreshedEventListener
onApplicationEvent, setApplicationContext
-
-
-
-
Method Detail
-
handleContextRefreshedEvent
public void handleContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent event)
Loads allPolicy
instances from the context, and uses them to initialize thisPolicyService
.- Specified by:
handleContextRefreshedEvent
in classOnContextRefreshedEventListener
-
isRestricted
public boolean isRestricted(java.lang.String name, ome.model.IObject obj)
Description copied from interface:PolicyService
Ask each configuredPolicy
instance with the given name argument if it considers the restriction active for the givenIObject
argument. If any are active, return true.- Specified by:
isRestricted
in interfacePolicyService
- Parameters:
name
- non-null identifier of a class ofPolicy
instances.obj
- non-null "context" for this check.- Returns:
- true if any
Policy
returns true fromPolicy.isRestricted(IObject)
.
-
checkRestriction
public void checkRestriction(java.lang.String name, ome.model.IObject obj)
Description copied from interface:PolicyService
Give each configuredPolicy
instance the chance to throw aSecurityViolation
from itsPolicy.checkRestriction(IObject)
method.- Specified by:
checkRestriction
in interfacePolicyService
- Parameters:
name
- non-null identifier of a class ofPolicy
instances.obj
- non-null "context" for this check.
-
listAllRestrictions
public java.util.Set<java.lang.String> listAllRestrictions()
Description copied from interface:PolicyService
Return all configured identifier strings as would be passed as the first argument toPolicyService.isRestricted(String, IObject)
orPolicyService.checkRestriction(String, IObject)
.- Specified by:
listAllRestrictions
in interfacePolicyService
-
listActiveRestrictions
public java.util.Set<java.lang.String> listActiveRestrictions(ome.model.IObject obj)
Description copied from interface:PolicyService
Return all identifier strings as would be passed as the first argument toPolicyService.isRestricted(String, IObject)
orPolicyService.checkRestriction(String, IObject)
which considers itself active for the given argument.- Specified by:
listActiveRestrictions
in interfacePolicyService
- Parameters:
obj
- non-null context passed to eachPolicy
instance.- Returns:
- a possibly empty string set of identifiers which should be
returned to clients via
Permissions.copyExtendedRestrictions()
.
-
filterObject
protected boolean filterObject(ome.model.IObject obj)
Limit the objects to whichPolicy
instances are applied. This reduces the overhead of creating aHashSet
for every object in a returned graph.- Parameters:
obj
- e.g. the argument tolistActiveRestrictions(IObject)
.- Returns:
- true if the given object should not be restricted.
-
-