[seam-commits] Seam SVN: r10925 - in modules/trunk/security/src/main/java/org/jboss/seam/security: permission and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon May 18 04:49:55 EDT 2009
Author: shane.bryzak at jboss.com
Date: 2009-05-18 04:49:55 -0400 (Mon, 18 May 2009)
New Revision: 10925
Added:
modules/trunk/security/src/main/java/org/jboss/seam/security/management/IdentityStoreEntityClasses.java
Modified:
modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java
modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStoreConfig.java
modules/trunk/security/src/main/java/org/jboss/seam/security/permission/JpaPermissionStore.java
Log:
some hackish configuration stuff
Added: modules/trunk/security/src/main/java/org/jboss/seam/security/management/IdentityStoreEntityClasses.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/management/IdentityStoreEntityClasses.java (rev 0)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/management/IdentityStoreEntityClasses.java 2009-05-18 08:49:55 UTC (rev 10925)
@@ -0,0 +1,16 @@
+package org.jboss.seam.security.management;
+
+import javax.context.ApplicationScoped;
+
+/**
+ * FIXME - a hack until we get some proper bean configuration
+ *
+ * @author Shane Bryzak
+ *
+ */
+ at ApplicationScoped
+public interface IdentityStoreEntityClasses
+{
+ Class<?> getUserEntityClass();
+ Class<?> getRoleEntityClass();
+}
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java 2009-05-18 08:49:13 UTC (rev 10924)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java 2009-05-18 08:49:55 UTC (rev 10925)
@@ -11,7 +11,6 @@
import java.util.List;
import java.util.Set;
-import javax.annotation.Named;
import javax.context.RequestScoped;
import javax.inject.Current;
import javax.inject.Initializer;
@@ -35,7 +34,6 @@
*
* @author Shane Bryzak
*/
- at Named("identityStore")
@RequestScoped
public class JpaIdentityStore implements IdentityStore, Serializable
{
@@ -46,7 +44,7 @@
protected FeatureSet featureSet;
@PersistenceContext EntityManager entityManager;
-
+
JpaIdentityStoreConfig config;
Manager manager;
@@ -77,7 +75,7 @@
featureSet.enableAll();
}
- if (config.userEntityClass == null)
+ if (config.getUserEntityClass() == null)
{
log.error("Error in JpaIdentityStore configuration - userClass must be configured.");
return;
@@ -88,7 +86,7 @@
{
try
{
- if (config.userEntityClass == null)
+ if (config.getUserEntityClass() == null)
{
throw new IdentityManagementException("Could not create account, userClass not set");
}
@@ -98,21 +96,21 @@
throw new IdentityManagementException("Could not create account, already exists");
}
- Object user = config.userEntityClass.newInstance();
+ Object user = config.getUserEntityClass().newInstance();
- config.userPrincipalProperty.setValue(user, username);
+ config.getUserPrincipalProperty().setValue(user, username);
- if (config.userFirstNameProperty.isSet()) config.userFirstNameProperty.setValue(user, firstname);
- if (config.userLastNameProperty.isSet()) config.userLastNameProperty.setValue(user, lastname);
+ if (config.getUserFirstNameProperty().isSet()) config.getUserFirstNameProperty().setValue(user, firstname);
+ if (config.getUserLastNameProperty().isSet()) config.getUserLastNameProperty().setValue(user, lastname);
if (password == null)
{
- if (config.userEnabledProperty.isSet()) config.userEnabledProperty.setValue(user, false);
+ if (config.getUserEnabledProperty().isSet()) config.getUserEnabledProperty().setValue(user, false);
}
else
{
setUserPassword(user, password);
- if (config.userEnabledProperty.isSet()) config.userEnabledProperty.setValue(user, true);
+ if (config.getUserEnabledProperty().isSet()) config.getUserEnabledProperty().setValue(user, true);
}
manager.fireEvent(new PrePersistUserEvent(user));
@@ -138,15 +136,15 @@
protected void setUserPassword(Object user, String password)
{
- if (config.passwordSaltProperty.isSet())
+ if (config.getPasswordSaltProperty().isSet())
{
byte[] salt = generateUserSalt(user);
- config.passwordSaltProperty.setValue(user, BinTools.bin2hex(salt));
- config.userPasswordProperty.setValue(user, generatePasswordHash(password, salt));
+ config.getPasswordSaltProperty().setValue(user, BinTools.bin2hex(salt));
+ config.getUserPasswordProperty().setValue(user, generatePasswordHash(password, salt));
}
else
{
- config.userPasswordProperty.setValue(user, generatePasswordHash(password, getUserAccountSalt(user)));
+ config.getUserPasswordProperty().setValue(user, generatePasswordHash(password, getUserAccountSalt(user)));
}
}
@@ -157,7 +155,7 @@
protected String getUserAccountSalt(Object user)
{
// By default, we'll use the user's username as the password salt
- return config.userPrincipalProperty.getValue(user).toString();
+ return config.getUserPrincipalProperty().getValue(user).toString();
}
/**
@@ -188,12 +186,12 @@
@SuppressWarnings("unchecked")
public boolean grantRole(String username, String role)
{
- if (config.roleEntityClass == null) return false;
+ if (config.getRoleEntityClass() == null) return false;
Object user = lookupUser(username);
if (user == null)
{
- if (config.userPasswordProperty.isSet())
+ if (config.getUserPasswordProperty().isSet())
{
// If no userPasswordProperty is set, it means that authentication is being performed
// by another identity store and this one is just managing roles
@@ -220,10 +218,10 @@
throw new NoSuchRoleException("Could not grant role, role '" + role + "' does not exist");
}
- Collection<?> userRoles = (Collection<?>) config.userRolesProperty.getValue(user);
+ Collection<?> userRoles = (Collection<?>) config.getUserRolesProperty().getValue(user);
if (userRoles == null)
{
- Type propType = config.userRolesProperty.getPropertyType();
+ Type propType = config.getUserRolesProperty().getPropertyType();
Class<?> collectionType;
if (propType instanceof Class && Collection.class.isAssignableFrom((Class<?>) propType))
@@ -250,30 +248,30 @@
userRoles = new ArrayList<Object>();
}
- config.userRolesProperty.setValue(user, userRoles);
+ config.getUserRolesProperty().setValue(user, userRoles);
}
- else if (((Collection<?>) config.userRolesProperty.getValue(user)).contains(roleToGrant))
+ else if (((Collection<?>) config.getUserRolesProperty().getValue(user)).contains(roleToGrant))
{
return false;
}
- if (config.xrefEntityClass == null)
+ if (config.getXrefEntityClass() == null)
{
// If this is a Many-To-Many relationship, simply add the role
- ((Collection<Object>) config.userRolesProperty.getValue(user)).add(roleToGrant);
+ ((Collection<Object>) config.getUserRolesProperty().getValue(user)).add(roleToGrant);
}
else
{
// Otherwise we need to insert a cross-reference entity instance
try
{
- Object xref = config.xrefEntityClass.newInstance();
- config.xrefUserProperty.setValue(xref, user);
- config.xrefRoleProperty.setValue(xref, roleToGrant);
+ Object xref = config.getXrefEntityClass().newInstance();
+ config.getXrefUserProperty().setValue(xref, user);
+ config.getXrefRoleProperty().setValue(xref, roleToGrant);
manager.fireEvent(new PrePersistUserRoleEvent(xref));
- ((Collection<Object>) config.userRolesProperty.getValue(user)).add(entityManager.merge(xref));
+ ((Collection<Object>) config.getUserRolesProperty().getValue(user)).add(entityManager.merge(xref));
}
catch (Exception ex)
{
@@ -300,17 +298,17 @@
boolean success = false;
- if (config.xrefEntityClass == null)
+ if (config.getXrefEntityClass() == null)
{
- success = ((Collection<?>) config.userRolesProperty.getValue(user)).remove(roleToRevoke);
+ success = ((Collection<?>) config.getUserRolesProperty().getValue(user)).remove(roleToRevoke);
}
else
{
- Collection<?> roles = ((Collection<?>) config.userRolesProperty.getValue(user));
+ Collection<?> roles = ((Collection<?>) config.getUserRolesProperty().getValue(user));
for (Object xref : roles)
{
- if (config.xrefRoleProperty.getValue(xref).equals(roleToRevoke))
+ if (config.getXrefRoleProperty().getValue(xref).equals(roleToRevoke))
{
success = roles.remove(xref);
break;
@@ -324,7 +322,7 @@
@SuppressWarnings("unchecked")
public boolean addRoleToGroup(String role, String group)
{
- if (!config.roleGroupsProperty.isSet()) return false;
+ if (!config.getRoleGroupsProperty().isSet()) return false;
Object targetRole = lookupRole(role);
if (targetRole == null)
@@ -338,14 +336,14 @@
throw new NoSuchRoleException("Could not grant role, group '" + group + "' does not exist");
}
- Collection<?> roleGroups = (Collection<?>) config.roleGroupsProperty.getValue(targetRole);
+ Collection<?> roleGroups = (Collection<?>) config.getRoleGroupsProperty().getValue(targetRole);
if (roleGroups == null)
{
// This should either be a Set, or a List...
Class<?> rawType = null;
- if (config.roleGroupsProperty.getPropertyType() instanceof ParameterizedType)
+ if (config.getRoleGroupsProperty().getPropertyType() instanceof ParameterizedType)
{
- rawType = (Class<?>) ((ParameterizedType) config.roleGroupsProperty.getPropertyType()).getRawType();
+ rawType = (Class<?>) ((ParameterizedType) config.getRoleGroupsProperty().getPropertyType()).getRawType();
}
else
{
@@ -361,21 +359,21 @@
roleGroups = new ArrayList<Object>();
}
- config.roleGroupsProperty.setValue(targetRole, roleGroups);
+ config.getRoleGroupsProperty().setValue(targetRole, roleGroups);
}
- else if (((Collection<?>) config.roleGroupsProperty.getValue(targetRole)).contains(targetGroup))
+ else if (((Collection<?>) config.getRoleGroupsProperty().getValue(targetRole)).contains(targetGroup))
{
return false;
}
- ((Collection<Object>) config.roleGroupsProperty.getValue(targetRole)).add(targetGroup);
+ ((Collection<Object>) config.getRoleGroupsProperty().getValue(targetRole)).add(targetGroup);
return true;
}
public boolean removeRoleFromGroup(String role, String group)
{
- if (!config.roleGroupsProperty.isSet()) return false;
+ if (!config.getRoleGroupsProperty().isSet()) return false;
Object roleToRemove = lookupRole(role);
if (role == null)
@@ -389,7 +387,7 @@
throw new NoSuchRoleException("Could not remove role from group, no such group '" + group + "'");
}
- boolean success = ((Collection<?>) config.roleGroupsProperty.getValue(roleToRemove)).remove(targetGroup);
+ boolean success = ((Collection<?>) config.getRoleGroupsProperty().getValue(roleToRemove)).remove(targetGroup);
return success;
}
@@ -398,7 +396,7 @@
{
try
{
- if (config.roleEntityClass == null)
+ if (config.getRoleEntityClass() == null)
{
throw new IdentityManagementException("Could not create role, roleClass not set");
}
@@ -408,8 +406,8 @@
throw new IdentityManagementException("Could not create role, already exists");
}
- Object instance = config.roleEntityClass.newInstance();
- config.roleNameProperty.setValue(instance, role);
+ Object instance = config.getRoleEntityClass().newInstance();
+ config.getRoleNameProperty().setValue(instance, role);
entityManager.persist(instance);
return true;
@@ -435,9 +433,9 @@
throw new NoSuchRoleException("Could not delete role, role '" + role + "' does not exist");
}
- if (config.xrefEntityClass != null)
+ if (config.getXrefEntityClass() != null)
{
- entityManager.createQuery("delete " + config.xrefEntityClass.getName() + " where role = :role")
+ entityManager.createQuery("delete " + config.getXrefEntityClass().getName() + " where role = :role")
.setParameter("role", roleToDelete)
.executeUpdate();
}
@@ -462,10 +460,10 @@
public boolean enableUser(String name)
{
- if (!config.userEnabledProperty.isSet())
+ if (!config.getUserEnabledProperty().isSet())
{
log.debug("Can not enable user, no @UserEnabled property configured in userClass " +
- config.userEntityClass.getName());
+ config.getUserEntityClass().getName());
return false;
}
@@ -476,21 +474,21 @@
}
// Can't enable an already-enabled user, return false
- if (((Boolean) config.userEnabledProperty.getValue(user)) == true)
+ if (((Boolean) config.getUserEnabledProperty().getValue(user)) == true)
{
return false;
}
- config.userEnabledProperty.setValue(user, true);
+ config.getUserEnabledProperty().setValue(user, true);
return true;
}
public boolean disableUser(String name)
{
- if (!config.userEnabledProperty.isSet())
+ if (!config.getUserEnabledProperty().isSet())
{
log.debug("Can not disable user, no @UserEnabled property configured in userClass " +
- config.userEntityClass.getName());
+ config.getUserEntityClass().getName());
return false;
}
@@ -501,12 +499,12 @@
}
// Can't disable an already-disabled user, return false
- if (((Boolean) config.userEnabledProperty.getValue(user)) == false)
+ if (((Boolean) config.getUserEnabledProperty().getValue(user)) == false)
{
return false;
}
- config.userEnabledProperty.setValue(user, false);
+ config.getUserEnabledProperty().setValue(user, false);
return true;
}
@@ -536,8 +534,8 @@
public boolean isUserEnabled(String name)
{
Object user = lookupUser(name);
- return user != null && (!config.userEnabledProperty.isSet() ||
- (((Boolean) config.userEnabledProperty.getValue(user))) == true);
+ return user != null && (!config.getUserEnabledProperty().isSet() ||
+ (((Boolean) config.getUserEnabledProperty().getValue(user))) == true);
}
public List<String> getGrantedRoles(String name)
@@ -550,20 +548,20 @@
List<String> roles = new ArrayList<String>();
- Collection<?> userRoles = (Collection<?>) config.userRolesProperty.getValue(user);
+ Collection<?> userRoles = (Collection<?>) config.getUserRolesProperty().getValue(user);
if (userRoles != null)
{
for (Object role : userRoles)
{
- if (config.xrefEntityClass == null)
+ if (config.getXrefEntityClass() == null)
{
- roles.add((String) config.roleNameProperty.getValue(role));
+ roles.add((String) config.getRoleNameProperty().getValue(role));
}
else
{
- Object xref = config.roleNameProperty.getValue(role);
- Object userRole = config.xrefRoleProperty.getValue(xref);
- roles.add((String) config.roleNameProperty.getValue(userRole));
+ Object xref = config.getRoleNameProperty().getValue(role);
+ Object userRole = config.getXrefRoleProperty().getValue(xref);
+ roles.add((String) config.getRoleNameProperty().getValue(userRole));
}
}
}
@@ -581,14 +579,14 @@
List<String> groups = new ArrayList<String>();
- if (config.roleGroupsProperty.isSet())
+ if (config.getRoleGroupsProperty().isSet())
{
- Collection<?> roleGroups = (Collection<?>) config.roleGroupsProperty.getValue(role);
+ Collection<?> roleGroups = (Collection<?>) config.getRoleGroupsProperty().getValue(role);
if (roleGroups != null)
{
for (Object group : roleGroups)
{
- groups.add((String) config.roleNameProperty.getValue(group));
+ groups.add((String) config.getRoleNameProperty().getValue(group));
}
}
}
@@ -605,12 +603,12 @@
}
Set<String> roles = new HashSet<String>();
- Collection<?> userRoles = (Collection<?>) config.userRolesProperty.getValue(user);
+ Collection<?> userRoles = (Collection<?>) config.getUserRolesProperty().getValue(user);
if (userRoles != null)
{
for (Object role : userRoles)
{
- addRoleAndMemberships((String) config.roleNameProperty.getValue(role), roles);
+ addRoleAndMemberships((String) config.getRoleNameProperty().getValue(role), roles);
}
}
@@ -623,15 +621,15 @@
{
Object instance = lookupRole(role);
- if (config.roleGroupsProperty.isSet())
+ if (config.getRoleGroupsProperty().isSet())
{
- Collection<?> groups = (Collection<?>) config.roleGroupsProperty.getValue(instance);
+ Collection<?> groups = (Collection<?>) config.getRoleGroupsProperty().getValue(instance);
if (groups != null)
{
for (Object group : groups)
{
- addRoleAndMemberships((String) config.roleNameProperty.getValue(group), roles);
+ addRoleAndMemberships((String) config.getRoleNameProperty().getValue(group), roles);
}
}
}
@@ -640,12 +638,12 @@
public String generatePasswordHash(String password, byte[] salt)
{
- if (config.passwordSaltProperty.isSet())
+ if (config.getPasswordSaltProperty().isSet())
{
try
{
return getPasswordHash().createPasswordKey(password.toCharArray(), salt,
- config.userPasswordProperty.getAnnotation().iterations());
+ config.getUserPasswordProperty().getAnnotation().iterations());
}
catch (GeneralSecurityException ex)
{
@@ -665,7 +663,7 @@
@Deprecated
protected String generatePasswordHash(String password, String salt)
{
- String algorithm = config.userPasswordProperty.getAnnotation().hash();
+ String algorithm = config.getUserPasswordProperty().getAnnotation().hash();
if (algorithm == null || "".equals(algorithm))
{
@@ -698,17 +696,17 @@
public boolean authenticate(String username, String password)
{
Object user = lookupUser(username);
- if (user == null || (config.userEnabledProperty.isSet() &&
- ((Boolean) config.userEnabledProperty.getValue(user) == false)))
+ if (user == null || (config.getUserEnabledProperty().isSet() &&
+ ((Boolean) config.getUserEnabledProperty().getValue(user) == false)))
{
return false;
}
String passwordHash = null;
- if (config.passwordSaltProperty.isSet())
+ if (config.getPasswordSaltProperty().isSet())
{
- String encodedSalt = (String) config.passwordSaltProperty.getValue(user);
+ String encodedSalt = (String) config.getPasswordSaltProperty().getValue(user);
if (encodedSalt == null)
{
throw new IdentityManagementException("A @PasswordSalt property was found on entity " + user +
@@ -723,7 +721,7 @@
}
- boolean success = passwordHash.equals(config.userPasswordProperty.getValue(user));
+ boolean success = passwordHash.equals(config.getUserPasswordProperty().getValue(user));
if (success)
{
@@ -738,8 +736,8 @@
try
{
Object user = entityManager.createQuery(
- "select u from " + config.userEntityClass.getName() + " u where " + config.userPrincipalProperty.getName() +
- " = :username")
+ "select u from " + config.getUserEntityClass().getName() + " u where " +
+ config.getUserPrincipalProperty().getName() + " = :username")
.setParameter("username", username)
.getSingleResult();
@@ -753,17 +751,17 @@
public String getUserName(Object user)
{
- return (String) config.userPrincipalProperty.getValue(user);
+ return (String) config.getUserPrincipalProperty().getValue(user);
}
public String getRoleName(Object role)
{
- return (String) config.roleNameProperty.getValue(role);
+ return (String) config.getRoleNameProperty().getValue(role);
}
public boolean isRoleConditional(String role)
{
- return config.roleConditionalProperty.isSet() ? (Boolean) config.roleConditionalProperty.getValue(
+ return config.getRoleConditionalProperty().isSet() ? (Boolean) config.getRoleConditionalProperty().getValue(
lookupRole(role)) : false;
}
@@ -772,7 +770,7 @@
try
{
Object value = entityManager.createQuery(
- "select r from " + config.roleEntityClass.getName() + " r where " + config.roleNameProperty.getName() +
+ "select r from " + config.getRoleEntityClass().getName() + " r where " + config.getRoleNameProperty().getName() +
" = :role")
.setParameter("role", role)
.getSingleResult();
@@ -789,7 +787,8 @@
public List<String> listUsers()
{
return (List<String>) entityManager.createQuery(
- "select u." + config.userPrincipalProperty.getName() + " from " + config.userEntityClass.getName() + " u")
+ "select u." + config.getUserPrincipalProperty().getName() + " from " +
+ config.getUserEntityClass().getName() + " u")
.getResultList();
}
@@ -797,8 +796,8 @@
public List<String> listUsers(String filter)
{
return (List<String>) entityManager.createQuery(
- "select u." + config.userPrincipalProperty.getName() + " from " + config.userEntityClass.getName() +
- " u where lower(" + config.userPrincipalProperty.getName() + ") like :username")
+ "select u." + config.getUserPrincipalProperty().getName() + " from " + config.getUserEntityClass().getName() +
+ " u where lower(" + config.getUserPrincipalProperty().getName() + ") like :username")
.setParameter("username", "%" + (filter != null ? filter.toLowerCase() : "") +
"%")
.getResultList();
@@ -808,8 +807,8 @@
public List<String> listRoles()
{
return (List<String>) entityManager.createQuery(
- "select r." + config.roleNameProperty.getName() + " from " +
- config.roleEntityClass.getName() + " r").getResultList();
+ "select r." + config.getRoleNameProperty().getName() + " from " +
+ config.getRoleEntityClass().getName() + " r").getResultList();
}
public List<Principal> listMembers(String role)
@@ -834,20 +833,20 @@
{
Object roleEntity = lookupRole(role);
- if (config.xrefEntityClass == null)
+ if (config.getXrefEntityClass() == null)
{
return (List<String>) entityManager.createQuery("select u." +
- config.userPrincipalProperty.getName() +
- " from " + config.userEntityClass.getName() + " u where :role member of u." +
- config.userRolesProperty.getName())
+ config.getUserPrincipalProperty().getName() +
+ " from " + config.getUserEntityClass().getName() + " u where :role member of u." +
+ config.getUserRolesProperty().getName())
.setParameter("role", roleEntity)
.getResultList();
}
else
{
List<?> xrefs = entityManager.createQuery("select x from " +
- config.xrefEntityClass.getName() + " x where x." +
- config.xrefRoleProperty.getName() + " = :role")
+ config.getXrefEntityClass().getName() + " x where x." +
+ config.getXrefRoleProperty().getName() + " = :role")
.setParameter("role", roleEntity)
.getResultList();
@@ -855,8 +854,8 @@
for (Object xref : xrefs)
{
- Object user = config.xrefUserProperty.getValue(xref);
- members.add(config.userPrincipalProperty.getValue(user).toString());
+ Object user = config.getXrefUserProperty().getValue(xref);
+ members.add(config.getUserPrincipalProperty().getValue(user).toString());
}
return members;
@@ -867,14 +866,14 @@
@SuppressWarnings("unchecked")
private List<String> listRoleMembers(String role)
{
- if (config.roleGroupsProperty.isSet())
+ if (config.getRoleGroupsProperty().isSet())
{
Object roleEntity = lookupRole(role);
return (List<String>) entityManager.createQuery("select r." +
- config.roleNameProperty.getName() +
- " from " + config.roleEntityClass.getName() + " r where :role member of r." +
- config.roleGroupsProperty.getName())
+ config.getRoleNameProperty().getName() +
+ " from " + config.getRoleEntityClass().getName() + " r where :role member of r." +
+ config.getRoleGroupsProperty().getName())
.setParameter("role", roleEntity)
.getResultList();
}
@@ -888,15 +887,15 @@
StringBuilder roleQuery = new StringBuilder();
roleQuery.append("select r.");
- roleQuery.append(config.roleNameProperty.getName());
+ roleQuery.append(config.getRoleNameProperty().getName());
roleQuery.append(" from ");
- roleQuery.append(config.roleEntityClass.getName());
+ roleQuery.append(config.getRoleEntityClass().getName());
roleQuery.append(" r");
- if (config.roleConditionalProperty.isSet())
+ if (config.getRoleConditionalProperty().isSet())
{
roleQuery.append(" where r.");
- roleQuery.append(config.roleConditionalProperty.getName());
+ roleQuery.append(config.getRoleConditionalProperty().getName());
roleQuery.append(" = false");
}
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStoreConfig.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStoreConfig.java 2009-05-18 08:49:13 UTC (rev 10924)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStoreConfig.java 2009-05-18 08:49:55 UTC (rev 10925)
@@ -5,6 +5,7 @@
import java.util.Collection;
import javax.context.ApplicationScoped;
+import javax.inject.Current;
import javax.inject.Initializer;
import org.jboss.seam.security.annotations.management.PasswordSalt;
@@ -28,55 +29,57 @@
@ApplicationScoped
public class JpaIdentityStoreConfig
{
- Class<?> userEntityClass;
- Class<?> roleEntityClass;
- Class<?> xrefEntityClass;
- TypedBeanProperty xrefUserProperty;
- TypedBeanProperty xrefRoleProperty;
+ private Class<?> userEntityClass;
+ private Class<?> roleEntityClass;
+ private Class<?> xrefEntityClass;
+ private TypedBeanProperty xrefUserProperty;
+ private TypedBeanProperty xrefRoleProperty;
- AnnotatedBeanProperty<UserPrincipal> userPrincipalProperty;
- AnnotatedBeanProperty<UserPassword> userPasswordProperty;
- AnnotatedBeanProperty<PasswordSalt> passwordSaltProperty;
- AnnotatedBeanProperty<UserRoles> userRolesProperty;
- AnnotatedBeanProperty<UserEnabled> userEnabledProperty;
- AnnotatedBeanProperty<UserFirstName> userFirstNameProperty;
- AnnotatedBeanProperty<UserLastName> userLastNameProperty;
- AnnotatedBeanProperty<RoleName> roleNameProperty;
- AnnotatedBeanProperty<RoleGroups> roleGroupsProperty;
- AnnotatedBeanProperty<RoleConditional> roleConditionalProperty;
+ private AnnotatedBeanProperty<UserPrincipal> userPrincipalProperty;
+ private AnnotatedBeanProperty<UserPassword> userPasswordProperty;
+ private AnnotatedBeanProperty<PasswordSalt> passwordSaltProperty;
+ private AnnotatedBeanProperty<UserRoles> userRolesProperty;
+ private AnnotatedBeanProperty<UserEnabled> userEnabledProperty;
+ private AnnotatedBeanProperty<UserFirstName> userFirstNameProperty;
+ private AnnotatedBeanProperty<UserLastName> userLastNameProperty;
+ private AnnotatedBeanProperty<RoleName> roleNameProperty;
+ private AnnotatedBeanProperty<RoleGroups> roleGroupsProperty;
+ private AnnotatedBeanProperty<RoleConditional> roleConditionalProperty;
+
+ @Current IdentityStoreEntityClasses entityClasses;
@Initializer
public void initProperties()
{
- userPrincipalProperty = new AnnotatedBeanProperty<UserPrincipal>(userEntityClass, UserPrincipal.class);
- userPasswordProperty = new AnnotatedBeanProperty<UserPassword>(userEntityClass, UserPassword.class);
- passwordSaltProperty = new AnnotatedBeanProperty<PasswordSalt>(userEntityClass, PasswordSalt.class);
- userRolesProperty = new AnnotatedBeanProperty<UserRoles>(userEntityClass, UserRoles.class);
- userEnabledProperty = new AnnotatedBeanProperty<UserEnabled>(userEntityClass, UserEnabled.class);
- userFirstNameProperty = new AnnotatedBeanProperty<UserFirstName>(userEntityClass, UserFirstName.class);
- userLastNameProperty = new AnnotatedBeanProperty<UserLastName>(userEntityClass, UserLastName.class);
+ userPrincipalProperty = new AnnotatedBeanProperty<UserPrincipal>(getUserEntityClass(), UserPrincipal.class);
+ userPasswordProperty = new AnnotatedBeanProperty<UserPassword>(getUserEntityClass(), UserPassword.class);
+ passwordSaltProperty = new AnnotatedBeanProperty<PasswordSalt>(getUserEntityClass(), PasswordSalt.class);
+ userRolesProperty = new AnnotatedBeanProperty<UserRoles>(getUserEntityClass(), UserRoles.class);
+ userEnabledProperty = new AnnotatedBeanProperty<UserEnabled>(getUserEntityClass(), UserEnabled.class);
+ userFirstNameProperty = new AnnotatedBeanProperty<UserFirstName>(getUserEntityClass(), UserFirstName.class);
+ userLastNameProperty = new AnnotatedBeanProperty<UserLastName>(getUserEntityClass(), UserLastName.class);
if (!userPrincipalProperty.isSet())
{
- throw new IdentityManagementException("Invalid userClass " + userEntityClass.getName() +
+ throw new IdentityManagementException("Invalid userClass " + getUserEntityClass().getName() +
" - required annotation @UserPrincipal not found on any Field or Method.");
}
if (!userRolesProperty.isSet())
{
- throw new IdentityManagementException("Invalid userClass " + userEntityClass.getName() +
+ throw new IdentityManagementException("Invalid userClass " + getUserEntityClass().getName() +
" - required annotation @UserRoles not found on any Field or Method.");
}
- if (roleEntityClass != null)
+ if (getRoleEntityClass() != null)
{
- roleNameProperty = new AnnotatedBeanProperty<RoleName>(roleEntityClass, RoleName.class);
- roleGroupsProperty = new AnnotatedBeanProperty<RoleGroups>(roleEntityClass, RoleGroups.class);
- roleConditionalProperty = new AnnotatedBeanProperty<RoleConditional>(roleEntityClass, RoleConditional.class);
+ roleNameProperty = new AnnotatedBeanProperty<RoleName>(getRoleEntityClass(), RoleName.class);
+ roleGroupsProperty = new AnnotatedBeanProperty<RoleGroups>(getRoleEntityClass(), RoleGroups.class);
+ roleConditionalProperty = new AnnotatedBeanProperty<RoleConditional>(getRoleEntityClass(), RoleConditional.class);
if (!roleNameProperty.isSet())
{
- throw new IdentityManagementException("Invalid roleClass " + roleEntityClass.getName() +
+ throw new IdentityManagementException("Invalid roleClass " + getRoleEntityClass().getName() +
" - required annotation @RoleName not found on any Field or Method.");
}
@@ -94,11 +97,11 @@
// If the @UserRoles property isn't a collection of <roleClass>, then assume the relationship
// is going through a cross-reference table
- if (!genType.equals(roleEntityClass))
+ if (!genType.equals(getRoleEntityClass()))
{
xrefEntityClass = (Class<?>) genType;
- xrefUserProperty = new TypedBeanProperty(xrefEntityClass, userEntityClass);
- xrefRoleProperty = new TypedBeanProperty(xrefEntityClass, roleEntityClass);
+ xrefUserProperty = new TypedBeanProperty(xrefEntityClass, getUserEntityClass());
+ xrefRoleProperty = new TypedBeanProperty(xrefEntityClass, getRoleEntityClass());
if (!xrefUserProperty.isSet())
{
@@ -118,6 +121,11 @@
public Class<?> getUserEntityClass()
{
+ if (userEntityClass == null)
+ {
+ userEntityClass = entityClasses.getUserEntityClass();
+ }
+
return userEntityClass;
}
@@ -128,6 +136,11 @@
public Class<?> getRoleEntityClass()
{
+ if (roleEntityClass == null)
+ {
+ roleEntityClass = entityClasses.getRoleEntityClass();
+ }
+
return roleEntityClass;
}
@@ -135,4 +148,62 @@
{
this.roleEntityClass = roleEntityClass;
}
+
+ public Class<?> getXrefEntityClass()
+ {
+ return xrefEntityClass;
+ }
+
+ public TypedBeanProperty getXrefUserProperty()
+ {
+ return xrefUserProperty;
+ }
+
+ public TypedBeanProperty getXrefRoleProperty()
+ {
+ return xrefRoleProperty;
+ }
+
+ public AnnotatedBeanProperty<UserPrincipal> getUserPrincipalProperty()
+ {
+ return userPrincipalProperty;
+ }
+
+ public AnnotatedBeanProperty<UserPassword> getUserPasswordProperty()
+ {
+ return userPasswordProperty;
+ }
+
+ public AnnotatedBeanProperty<PasswordSalt> getPasswordSaltProperty() {
+ return passwordSaltProperty;
+ }
+
+ public AnnotatedBeanProperty<UserRoles> getUserRolesProperty() {
+ return userRolesProperty;
+ }
+
+ public AnnotatedBeanProperty<UserEnabled> getUserEnabledProperty() {
+ return userEnabledProperty;
+ }
+
+ public AnnotatedBeanProperty<UserFirstName> getUserFirstNameProperty() {
+ return userFirstNameProperty;
+ }
+
+ public AnnotatedBeanProperty<UserLastName> getUserLastNameProperty() {
+ return userLastNameProperty;
+ }
+
+ public AnnotatedBeanProperty<RoleName> getRoleNameProperty() {
+ return roleNameProperty;
+ }
+
+ public AnnotatedBeanProperty<RoleGroups> getRoleGroupsProperty() {
+ return roleGroupsProperty;
+ }
+
+ public AnnotatedBeanProperty<RoleConditional> getRoleConditionalProperty() {
+ return roleConditionalProperty;
+ }
+
}
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/JpaPermissionStore.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/JpaPermissionStore.java 2009-05-18 08:49:13 UTC (rev 10924)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/JpaPermissionStore.java 2009-05-18 08:49:55 UTC (rev 10925)
@@ -27,6 +27,7 @@
import org.jboss.seam.security.SimplePrincipal;
import org.jboss.seam.security.management.IdentityManager;
import org.jboss.seam.security.management.JpaIdentityStore;
+import org.jboss.seam.security.management.JpaIdentityStoreConfig;
import org.jboss.seam.security.permission.PermissionMetadata.ActionSet;
import org.jboss.seam.security.util.AnnotatedBeanProperty;
@@ -527,15 +528,16 @@
boolean recipientIsRole = recipient instanceof Role;
JpaIdentityStore identityStore = manager.getInstanceByType(JpaIdentityStore.class);
+ JpaIdentityStoreConfig config = manager.getInstanceByType(JpaIdentityStoreConfig.class);
if (identityStore != null)
{
if (recipientIsRole && roleProperty.isSet() &&
- roleProperty.getPropertyType().equals(identityStore.getRoleEntityClass()))
+ roleProperty.getPropertyType().equals(config.getRoleEntityClass()))
{
return identityStore.lookupRole(recipient.getName());
}
- else if (userProperty.getPropertyType().equals(identityStore.getUserEntityClass()))
+ else if (userProperty.getPropertyType().equals(config.getUserEntityClass()))
{
return identityStore.lookupUser(recipient.getName());
}
@@ -547,8 +549,10 @@
protected Principal resolvePrincipal(Object principal, boolean isUser)
{
identityManager.getRoleIdentityStore();
- JpaIdentityStore identityStore = null;
+ JpaIdentityStore identityStore = manager.getInstanceByType(JpaIdentityStore.class);
+ JpaIdentityStoreConfig config = manager.getInstanceByType(JpaIdentityStoreConfig.class);
+
if (principal instanceof String)
{
return isUser ? new SimplePrincipal((String) principal) : new Role((String) principal,
@@ -557,12 +561,12 @@
if (identityStore != null)
{
- if (isUser && identityStore.getUserEntityClass().isAssignableFrom(principal.getClass()))
+ if (isUser && config.getUserEntityClass().isAssignableFrom(principal.getClass()))
{
return new SimplePrincipal(identityStore.getUserName(principal));
}
- if (!isUser && identityStore.getRoleEntityClass().isAssignableFrom(principal.getClass()))
+ if (!isUser && config.getRoleEntityClass().isAssignableFrom(principal.getClass()))
{
String name = identityStore.getRoleName(principal);
return new Role(name, identityStore.isRoleConditional(name));
@@ -605,7 +609,7 @@
createPermissionQuery(null, targets, null, Discrimination.either) :
createPermissionQuery(target, null, null, Discrimination.either);
- List userPermissions = permissionQuery.getResultList();
+ List<?> userPermissions = permissionQuery.getResultList();
Map<String,Principal> principalCache = new HashMap<String,Principal>();
@@ -675,7 +679,7 @@
permissionQuery = targets != null ?
createPermissionQuery(null, targets, null, Discrimination.role) :
createPermissionQuery(target, null, null, Discrimination.role);
- List rolePermissions = permissionQuery.getResultList();
+ List<?> rolePermissions = permissionQuery.getResultList();
for (Object permission : rolePermissions)
{
@@ -752,22 +756,22 @@
return manager.getInstanceByType(EntityManager.class);
}
- public Class getUserPermissionClass()
+ public Class<?> getUserPermissionClass()
{
return userPermissionClass;
}
- public void setUserPermissionClass(Class userPermissionClass)
+ public void setUserPermissionClass(Class<?> userPermissionClass)
{
this.userPermissionClass = userPermissionClass;
}
- public Class getRolePermissionClass()
+ public Class<?> getRolePermissionClass()
{
return rolePermissionClass;
}
- public void setRolePermissionClass(Class rolePermissionClass)
+ public void setRolePermissionClass(Class<?> rolePermissionClass)
{
this.rolePermissionClass = rolePermissionClass;
}
More information about the seam-commits
mailing list