Class AbstractCachingSecurityService
- java.lang.Object
-
- ca.bc.gov.open.cpf.plugin.impl.security.AbstractCachingSecurityService
-
- All Implemented Interfaces:
SecurityService
- Direct Known Subclasses:
AuthorizationServiceUserSecurityService
,MockSecurityService
,WorkerSecurityService
public abstract class AbstractCachingSecurityService extends Object implements SecurityService
-
-
Constructor Summary
Constructors Constructor Description AbstractCachingSecurityService(Module module, String username)
AbstractCachingSecurityService(Module module, String consumerKey, String userClass, String username)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canAccessResource(String resourceClass, String resourceId)
Check to see if the user can access the resource.boolean
canAccessResource(String resourceClass, String resourceId, String actionName)
Check to see if the user can perform the action on the resource.boolean
canPerformAction(String actionName)
Check to see if the user is can perform the named action.void
close()
String
getConsumerKey()
Get the consumer key of the user.String
getModuleName()
Map<String,Object>
getUserAttributes()
Get the additional attributes about the user.String
getUserClass()
Get the classification (type) of user account.String
getUsername()
Get the login username of the user.boolean
isInGroup(String groupName)
Check to see if the user is a member of the named group.protected Boolean
loadActionPermission(String actionName)
protected Boolean
loadGroupPermission(String groupName)
protected Boolean
loadResourceAccessPermission(String resourceClass, String resourceId, String actionName)
protected Map<String,Object>
loadUserAttributes()
protected void
setActionPermission(String actionName, Boolean actionPermission)
protected void
setConsumerKey(String userId)
protected void
setGroupPermission(String groupName, Boolean groupPermission)
protected void
setResourceAccessPermission(String resourceClass, String resourceId, String actionName, Boolean accessPermission)
protected void
setUserAttributes(Map<String,Object> userAttributes)
protected void
setUserClass(String userClass)
protected void
setUsername(String username)
String
toString()
-
-
-
Method Detail
-
canAccessResource
public boolean canAccessResource(String resourceClass, String resourceId)
Description copied from interface:SecurityService
Check to see if the user can access the resource.
public void execute() { String resourceClass = "report"; String resourceId = "demo"; if (securityService.canAccessResource(resourceClass, resourceId)) { // Perform the request } else { throw new SecurityException("User cannot access the demo report"); } }
- Specified by:
canAccessResource
in interfaceSecurityService
- Parameters:
resourceClass
- The type of resource.resourceId
- The resource identifier.- Returns:
- True if the user can access the resource, false otherwise.
-
canAccessResource
public boolean canAccessResource(String resourceClass, String resourceId, String actionName)
Description copied from interface:SecurityService
Check to see if the user can perform the action on the resource.
public void execute() { String resourceClass = "report"; String resourceId = "demo"; String actionName = "view"; if (securityService.canAccessResource(resourceClass, resourceId, actionName)) { // Perform the request } else { throw new SecurityException("User cannot perform the view action on the demo report"); } }
- Specified by:
canAccessResource
in interfaceSecurityService
- Parameters:
resourceClass
- The type of resource.resourceId
- The resource identifier.actionName
- The action name.- Returns:
- True if the user can perform the action on the resource, false otherwise.
-
canPerformAction
public boolean canPerformAction(String actionName)
Description copied from interface:SecurityService
Check to see if the user is can perform the named action.
public void execute() { if (securityService.canPerformAction("view")) { // Perform the request } else { throw new SecurityException("User cannot perform the view action"); } }
- Specified by:
canPerformAction
in interfaceSecurityService
- Parameters:
actionName
- The action name.- Returns:
- True if the user can perform the named action, false otherwise.
-
close
public void close()
-
getConsumerKey
public String getConsumerKey()
Description copied from interface:SecurityService
Get the consumer key of the user.
- Specified by:
getConsumerKey
in interfaceSecurityService
- Returns:
- The user's consumer key.
-
getModuleName
public String getModuleName()
-
getUserAttributes
public Map<String,Object> getUserAttributes()
Description copied from interface:SecurityService
Get the additional attributes about the user.
- Specified by:
getUserAttributes
in interfaceSecurityService
- Returns:
- The additional attributes about the user.
-
getUserClass
public String getUserClass()
Description copied from interface:SecurityService
Get the classification (type) of user account.
- Specified by:
getUserClass
in interfaceSecurityService
- Returns:
- The classification (type) of user account.
-
getUsername
public String getUsername()
Description copied from interface:SecurityService
Get the login username of the user.
- Specified by:
getUsername
in interfaceSecurityService
- Returns:
- The login username of the user.
-
isInGroup
public boolean isInGroup(String groupName)
Description copied from interface:SecurityService
Check to see if the user is a member of the named group.
public void execute() { if (securityService.isInGroup("DEMO_PARTNER")) { // Perform the request } else { throw new SecurityException("User is not a member of the DEMO_PARTNER_GROUP"); } }
- Specified by:
isInGroup
in interfaceSecurityService
- Parameters:
groupName
- The group name.- Returns:
- True if the user is a member of the group, false otherwise.
-
loadResourceAccessPermission
protected Boolean loadResourceAccessPermission(String resourceClass, String resourceId, String actionName)
-
setActionPermission
protected void setActionPermission(String actionName, Boolean actionPermission)
-
setConsumerKey
protected void setConsumerKey(String userId)
-
setResourceAccessPermission
protected void setResourceAccessPermission(String resourceClass, String resourceId, String actionName, Boolean accessPermission)
-
setUserClass
protected void setUserClass(String userClass)
-
setUsername
protected void setUsername(String username)
-
-