org.jboss.seam.security.permission
Class JpaPermissionStore

java.lang.Object
  extended by org.jboss.seam.security.permission.JpaPermissionStore
All Implemented Interfaces:
Serializable, PermissionStore

@Name(value="org.jboss.seam.security.jpaPermissionStore")
@Install(precedence=0,
         value=false)
@Scope(value=APPLICATION)
@BypassInterceptors
public class JpaPermissionStore
extends Object
implements PermissionStore, Serializable

A permission store implementation that uses JPA as its persistence mechanism.

Author:
Shane Bryzak
See Also:
Serialized Form

Constructor Summary
JpaPermissionStore()
           
 
Method Summary
 void clearPermissions(Object target)
           
protected  javax.persistence.Query createPermissionQuery(Object target, Set targets, Principal recipient, org.jboss.seam.security.permission.JpaPermissionStore.Discrimination discrimination)
          Creates a Query that returns a list of permission records for the specified parameters.
 Expressions.ValueExpression getEntityManager()
           
 Class getRolePermissionClass()
           
 Class getUserPermissionClass()
           
 boolean grantPermission(Permission permission)
           
 boolean grantPermissions(List<Permission> permissions)
           
 void init()
           
protected  void initProperties()
           
 List<String> listAvailableActions(Object target)
           
 List<Permission> listPermissions(Object target)
           
protected  List<Permission> listPermissions(Object target, Set<Object> targets, String action)
           
 List<Permission> listPermissions(Object target, String action)
          Returns a list of all user and role permissions for a specific permission target and action.
 List<Permission> listPermissions(Set<Object> targets, String action)
          Returns a list of all user and role permissions for the specified action for all specified target objects
protected  Principal resolvePrincipal(Object principal, boolean isUser)
           
protected  Object resolvePrincipalEntity(Principal recipient)
          If the user or role properties in the entity class refer to other entities, then this method uses the JpaIdentityStore (if available) to lookup that user or role entity.
 boolean revokePermission(Permission permission)
           
 boolean revokePermissions(List<Permission> permissions)
           
 void setEntityManager(Expressions.ValueExpression expression)
           
 void setRolePermissionClass(Class rolePermissionClass)
           
 void setUserPermissionClass(Class userPermissionClass)
           
protected  boolean updatePermissionActions(Object target, Principal recipient, String[] actions, boolean set)
          This is where the bulk of the actual work happens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JpaPermissionStore

public JpaPermissionStore()
Method Detail

init

@Create
public void init()

initProperties

protected void initProperties()

createPermissionQuery

protected javax.persistence.Query createPermissionQuery(Object target,
                                                        Set targets,
                                                        Principal recipient,
                                                        org.jboss.seam.security.permission.JpaPermissionStore.Discrimination discrimination)
Creates a Query that returns a list of permission records for the specified parameters.

Parameters:
target - The target of the permission, may be null
targets - A set of permission targets, may be null
recipient - The permission recipient, may be null
discrimination - A discrimination (either user, role or both), required
Returns:
Query The query generated for the provided parameters

grantPermission

public boolean grantPermission(Permission permission)
Specified by:
grantPermission in interface PermissionStore

revokePermission

public boolean revokePermission(Permission permission)
Specified by:
revokePermission in interface PermissionStore

updatePermissionActions

protected boolean updatePermissionActions(Object target,
                                          Principal recipient,
                                          String[] actions,
                                          boolean set)
This is where the bulk of the actual work happens.

Parameters:
target - The target object to update permissions for
recipient - The recipient to update permissions for
actions - The actions that will be updated
set - true if the specified actions are to be granted, false if they are to be revoked
Returns:
true if the operation is successful

grantPermissions

public boolean grantPermissions(List<Permission> permissions)
Specified by:
grantPermissions in interface PermissionStore

revokePermissions

public boolean revokePermissions(List<Permission> permissions)
Specified by:
revokePermissions in interface PermissionStore

resolvePrincipalEntity

protected Object resolvePrincipalEntity(Principal recipient)
If the user or role properties in the entity class refer to other entities, then this method uses the JpaIdentityStore (if available) to lookup that user or role entity. Otherwise it simply returns the name of the recipient.

Parameters:
recipient -
Returns:
The entity or name representing the permission recipient

resolvePrincipal

protected Principal resolvePrincipal(Object principal,
                                     boolean isUser)

listPermissions

public List<Permission> listPermissions(Set<Object> targets,
                                        String action)
Returns a list of all user and role permissions for the specified action for all specified target objects

Specified by:
listPermissions in interface PermissionStore

listPermissions

public List<Permission> listPermissions(Object target,
                                        String action)
Returns a list of all user and role permissions for a specific permission target and action.

Specified by:
listPermissions in interface PermissionStore

listPermissions

protected List<Permission> listPermissions(Object target,
                                           Set<Object> targets,
                                           String action)

listPermissions

public List<Permission> listPermissions(Object target)
Specified by:
listPermissions in interface PermissionStore

listAvailableActions

public List<String> listAvailableActions(Object target)
Specified by:
listAvailableActions in interface PermissionStore

getEntityManager

public Expressions.ValueExpression getEntityManager()

setEntityManager

public void setEntityManager(Expressions.ValueExpression expression)

getUserPermissionClass

public Class getUserPermissionClass()

setUserPermissionClass

public void setUserPermissionClass(Class userPermissionClass)

getRolePermissionClass

public Class getRolePermissionClass()

setRolePermissionClass

public void setRolePermissionClass(Class rolePermissionClass)

clearPermissions

public void clearPermissions(Object target)
Specified by:
clearPermissions in interface PermissionStore


Copyright © 2011 Seam Framework. All Rights Reserved.