[seam-commits] Seam SVN: r12807 - in modules/security/trunk: impl/src/main/java/org/jboss/seam/security/management and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed May 26 07:55:08 EDT 2010


Author: shane.bryzak at jboss.com
Date: 2010-05-26 07:55:06 -0400 (Wed, 26 May 2010)
New Revision: 12807

Modified:
   modules/security/trunk/api/src/main/java/org/jboss/seam/security/management/IdentityManager.java
   modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java
   modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java
Log:
rewrite AnnotatedBeanProperty stuff


Modified: modules/security/trunk/api/src/main/java/org/jboss/seam/security/management/IdentityManager.java
===================================================================
--- modules/security/trunk/api/src/main/java/org/jboss/seam/security/management/IdentityManager.java	2010-05-26 09:33:30 UTC (rev 12806)
+++ modules/security/trunk/api/src/main/java/org/jboss/seam/security/management/IdentityManager.java	2010-05-26 11:55:06 UTC (rev 12807)
@@ -2,6 +2,7 @@
 
 import java.util.List;
 
+import org.picketlink.idm.api.Credential;
 import org.picketlink.idm.api.Group;
 import org.picketlink.idm.api.IdentityType;
 import org.picketlink.idm.api.Role;
@@ -13,7 +14,7 @@
  */
 public interface IdentityManager
 {  
-   boolean createUser(String username, String password);
+   boolean createUser(String username, Credential credential);
    
    boolean deleteUser(String username);
    
@@ -21,7 +22,7 @@
    
    boolean disableUser(String username);
    
-   boolean changePassword(String username, String password);
+   boolean changePassword(String username, Credential credential);
    
    boolean isUserEnabled(String username);
    
@@ -35,14 +36,22 @@
      
    boolean userExists(String username);
    
-   boolean roleExists(String username);
+   boolean roleTypeExists(String roleType);
    
-   List<String> getUsers();
+   boolean createGroup(Group group);
    
-   List<String> getUsers(String filter);
+   boolean deleteGroup(Group group);
    
-   List<String> getRoles();
+   boolean addToGroup(String username, Group group);
    
+   boolean removeFromGroup(String username, Group group);
+   
+   List<String> findUsers();
+   
+   List<String> findUsers(String filter);
+   
+   List<String> getRoleTypes();
+   
    List<String> getGrantableRoles();
    
    /**

Modified: modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java
===================================================================
--- modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java	2010-05-26 09:33:30 UTC (rev 12806)
+++ modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java	2010-05-26 11:55:06 UTC (rev 12807)
@@ -12,7 +12,6 @@
 import org.jboss.seam.security.annotations.management.IdentityProperty;
 import org.jboss.seam.security.annotations.management.PropertyType;
 import org.jboss.seam.security.util.AnnotatedBeanProperty;
-import org.jboss.seam.security.util.AnnotatedBeanProperty.AttributeValue;
 import org.picketlink.idm.api.Credential;
 import org.picketlink.idm.api.Group;
 import org.picketlink.idm.api.IdentityType;
@@ -36,26 +35,20 @@
    
    private static final String DEFAULT_RELATIONSHIP_TYPE_MEMBERSHIP = "MEMBERSHIP";
    private static final String DEFAULT_RELATIONSHIP_TYPE_ROLE = "ROLE";
-   
-   private static final AttributeValue NAME_ATTRIBUTE = new AttributeValue("value", PropertyType.NAME);
-   private static final AttributeValue VALUE_ATTRIBUTE = new AttributeValue("value", PropertyType.VALUE);
-   private static final AttributeValue TYPE_ATTRIBUTE = new AttributeValue("value", PropertyType.TYPE);
-   private static final AttributeValue RELATIONSHIP_FROM_ATTRIBUTE = new AttributeValue("value", PropertyType.RELATIONSHIP_FROM);
-   private static final AttributeValue RELATIONSHIP_TO_ATTRIBUTE = new AttributeValue("value", PropertyType.RELATIONSHIP_TO);
-   
+      
    private Logger log = LoggerFactory.getLogger(JpaIdentityStore.class);
    
    // The following entity classes are configurable
    private Class<?> identityObjectEntity;
-   private Class<?> identityObjectRelationshipEntity;
-   private Class<?> identityObjectCredentialEntity;
-   private Class<?> identityObjectAttributeEntity;
-   private Class<?> identityRoleTypeEntity;
+   private Class<?> relationshipEntity;
+   private Class<?> credentialEntity;
+   private Class<?> attributeEntity;
+   private Class<?> roleTypeEntity;
    
    // The following entity classes may be determined automatically
-   private Class<?> identityObjectTypeEntity;
-   private Class<?> identityObjectRelationshipTypeEntity;
-   private Class<?> identityObjectCredentialTypeEntity;
+   private Class<?> identityTypeEntity;
+   private Class<?> relationshipTypeEntity;
+   private Class<?> credentialTypeEntity;
    
    
    private AnnotatedBeanProperty<IdentityProperty> identityNameProperty;
@@ -80,6 +73,23 @@
    private String relationshipTypeMembership = DEFAULT_RELATIONSHIP_TYPE_MEMBERSHIP;
    private String relationshipTypeRole = DEFAULT_RELATIONSHIP_TYPE_ROLE;
    
+   private class EntityProperty extends AnnotatedBeanProperty<IdentityProperty> 
+   {
+      private PropertyType pt;      
+      
+      public EntityProperty(Class<?> cls, Class<IdentityProperty> annotationClass, PropertyType pt)
+      {
+         super();
+         this.pt = pt;
+         scan(cls, annotationClass);                 
+      }
+   
+      public boolean isMatch(IdentityProperty p)
+      {
+         return p.value().equals(pt);  
+      }           
+   }
+   
    @Inject
    public void init()
    {
@@ -89,56 +99,61 @@
                "Error initializing JpaIdentityStore - identityObjectEntity not set");
       }
       
-      if (identityObjectRelationshipEntity == null)
+      if (relationshipEntity == null)
       {
          throw new IdentityManagementException(
                "Error initializing JpaIdentityStore - identityObjectRelationshipEntity not set");
       }
       
-      identityNameProperty = new AnnotatedBeanProperty<IdentityProperty>(
-            identityObjectEntity, IdentityProperty.class, NAME_ATTRIBUTE);
-      identityTypeProperty = new AnnotatedBeanProperty<IdentityProperty>(
-            identityObjectEntity, IdentityProperty.class, TYPE_ATTRIBUTE);
+      identityNameProperty = new EntityProperty(identityObjectEntity, 
+            IdentityProperty.class, PropertyType.NAME);
       
+      identityTypeProperty = new EntityProperty(identityObjectEntity, 
+            IdentityProperty.class, PropertyType.TYPE);
+      
       if (!String.class.equals(identityTypeProperty.getPropertyType()))
       {
          // If the identity type property isn't a String, it must be a related entity
-         identityObjectTypeEntity = (Class<?>) identityTypeProperty.getPropertyType();         
-         identityTypeNameProperty = new AnnotatedBeanProperty<IdentityProperty>(
-               identityObjectTypeEntity, IdentityProperty.class, NAME_ATTRIBUTE);
+         identityTypeEntity = (Class<?>) identityTypeProperty.getPropertyType();
+         
+         identityTypeNameProperty = new EntityProperty(identityTypeEntity, 
+               IdentityProperty.class, PropertyType.NAME);
       }
       
-      relationshipNameProperty = new AnnotatedBeanProperty<IdentityProperty>(
-            identityObjectRelationshipEntity, IdentityProperty.class, NAME_ATTRIBUTE);
-      relationshipFromProperty = new AnnotatedBeanProperty<IdentityProperty>(
-            identityObjectRelationshipEntity, IdentityProperty.class, RELATIONSHIP_FROM_ATTRIBUTE);
-      relationshipToProperty = new AnnotatedBeanProperty<IdentityProperty>(
-            identityObjectRelationshipEntity, IdentityProperty.class, RELATIONSHIP_TO_ATTRIBUTE);
-      relationshipTypeProperty = new AnnotatedBeanProperty<IdentityProperty>(
-            identityObjectRelationshipEntity, IdentityProperty.class, TYPE_ATTRIBUTE);
+      relationshipNameProperty = new EntityProperty(relationshipEntity, 
+            IdentityProperty.class, PropertyType.NAME);
       
+      relationshipFromProperty = new EntityProperty(relationshipEntity, 
+            IdentityProperty.class, PropertyType.RELATIONSHIP_FROM);
+      
+      relationshipToProperty = new EntityProperty(relationshipEntity, 
+            IdentityProperty.class, PropertyType.RELATIONSHIP_TO);
+      
+      relationshipTypeProperty = new EntityProperty(relationshipEntity, 
+            IdentityProperty.class, PropertyType.TYPE);
+      
       if (!String.class.equals(relationshipTypeProperty.getPropertyType()))
       {
-         identityObjectRelationshipTypeEntity = (Class<?>) relationshipTypeProperty.getPropertyType(); 
-         relationshipTypeNameProperty = new AnnotatedBeanProperty<IdentityProperty>(
-               identityObjectRelationshipTypeEntity, IdentityProperty.class, NAME_ATTRIBUTE);
+         relationshipTypeEntity = (Class<?>) relationshipTypeProperty.getPropertyType(); 
+         relationshipTypeNameProperty = new EntityProperty(relationshipTypeEntity, 
+               IdentityProperty.class, PropertyType.NAME);
       }
       
       // If a credential entity has been configured, scan it
-      if (identityObjectCredentialEntity != null)
+      if (credentialEntity != null)
       {
-         credentialTypeProperty = new AnnotatedBeanProperty<IdentityProperty>(
-               identityObjectCredentialEntity, IdentityProperty.class, TYPE_ATTRIBUTE);
+         credentialTypeProperty = new EntityProperty(credentialEntity, 
+               IdentityProperty.class, PropertyType.TYPE);
          
          if (!String.class.equals(credentialTypeProperty.getPropertyType()))
          {
-            identityObjectCredentialTypeEntity = (Class<?>) credentialTypeProperty.getPropertyType();
-            credentialTypeNameProperty = new AnnotatedBeanProperty<IdentityProperty>(
-                  identityObjectCredentialTypeEntity, IdentityProperty.class, NAME_ATTRIBUTE);
+            credentialTypeEntity = (Class<?>) credentialTypeProperty.getPropertyType();
+            credentialTypeNameProperty = new EntityProperty(credentialTypeEntity, 
+                  IdentityProperty.class, PropertyType.NAME);
          }
          
-         credentialValueProperty = new AnnotatedBeanProperty<IdentityProperty>(
-               identityObjectCredentialEntity, IdentityProperty.class, VALUE_ATTRIBUTE);
+         credentialValueProperty = new EntityProperty(credentialEntity, 
+               IdentityProperty.class, PropertyType.VALUE);
       }
       // otherwise assume that the credential value is stored in the identityObjectEntity
       else
@@ -162,42 +177,42 @@
    
    public Class<?> getIdentityObjectRelationshipEntity()
    {
-      return identityObjectRelationshipEntity;
+      return relationshipEntity;
    }
    
    public void setIdentityObjectRelationshipEntity(Class<?> identityObjectRelationshipEntity)
    {
-      this.identityObjectRelationshipEntity = identityObjectRelationshipEntity;
+      this.relationshipEntity = identityObjectRelationshipEntity;
    }
    
    public Class<?> getIdentityObjectCredentialEntity()
    {
-      return identityObjectCredentialEntity;
+      return credentialEntity;
    }
    
    public void setIdentityObjectCredentialEntity(Class<?> identityObjectCredentialEntity)
    {
-      this.identityObjectCredentialEntity = identityObjectCredentialEntity;
+      this.credentialEntity = identityObjectCredentialEntity;
    }
    
    public Class<?> getIdentityObjectAttributeEntity()
    {
-      return identityObjectAttributeEntity;
+      return attributeEntity;
    }
    
    public void setIdentityObjectAttributeEntity(Class<?> identityObjectAttributeEntity)
    {
-      this.identityObjectAttributeEntity = identityObjectAttributeEntity;
+      this.attributeEntity = identityObjectAttributeEntity;
    }
    
    public Class<?> getIdentityRoleTypeEntity()
    {
-      return identityRoleTypeEntity;
+      return roleTypeEntity;
    }
    
    public void setIdentityRoleTypeEntity(Class<?> identityRoleTypeEntity)
    {
-      this.identityRoleTypeEntity = identityRoleTypeEntity;
+      this.roleTypeEntity = identityRoleTypeEntity;
    }
    
    public String getUserIdentityType()

Modified: modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java
===================================================================
--- modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java	2010-05-26 09:33:30 UTC (rev 12806)
+++ modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java	2010-05-26 11:55:06 UTC (rev 12807)
@@ -5,8 +5,6 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.Map;
 
 /**
  * A convenience class for working with an annotated property (either a field or method) of
@@ -14,7 +12,7 @@
  *  
  * @author Shane Bryzak
  */
-public class AnnotatedBeanProperty<T extends Annotation>
+public abstract class AnnotatedBeanProperty<T extends Annotation>
 {
    private Field propertyField;
    private Method propertyGetter;
@@ -26,35 +24,23 @@
    private boolean isFieldProperty;
    private boolean set = false;
    
-   public static class AttributeValue
+   protected AnnotatedBeanProperty() 
    {
-      private String name;
-      private Object value;
-      
-      public AttributeValue(String name, Object value)
-      {
-         this.name = name;
-         this.value = value;
-      }
-      
-      public String getName()
-      {
-         return name;
-      }
-      
-      public Object getValue()
-      {
-         return value;
-      }
+      // noop      
    }
    
-   public AnnotatedBeanProperty(Class<?> cls, Class<T> annotationClass, AttributeValue... attributes)
+   public AnnotatedBeanProperty(Class<?> cls, Class<T> annotationClass)
    {            
+      scan(cls, annotationClass);
+   }
+   
+   protected void scan(Class<?> cls, Class<T> annotationClass)
+   {
       // First check declared fields
       for (Field f : cls.getDeclaredFields())
       {
          if (f.isAnnotationPresent(annotationClass) && 
-               attributesMatch(f.getAnnotation(annotationClass), attributes)) 
+               isMatch(f.getAnnotation(annotationClass))) 
          {
             setupFieldProperty(f);
             this.annotation = f.getAnnotation(annotationClass);            
@@ -66,8 +52,8 @@
       // Then check public fields, in case it's inherited
       for (Field f : cls.getFields())
       {
-         if (f.isAnnotationPresent(annotationClass) && 
-               attributesMatch(f.getAnnotation(annotationClass), attributes)) 
+         if (f.isAnnotationPresent(annotationClass) &&
+               isMatch(f.getAnnotation(annotationClass))) 
          {
             this.annotation = f.getAnnotation(annotationClass);
             setupFieldProperty(f);
@@ -79,8 +65,8 @@
       // Then check public methods (we ignore private methods)
       for (Method m : cls.getMethods())
       {
-         if (m.isAnnotationPresent(annotationClass) && 
-               attributesMatch(m.getAnnotation(annotationClass), attributes))
+         if (m.isAnnotationPresent(annotationClass) &&
+               isMatch(m.getAnnotation(annotationClass)))
          {
             this.annotation = m.getAnnotation(annotationClass);
             String methodName = m.getName();
@@ -108,34 +94,10 @@
                      "Method: " + m + " in class: " + cls);
             }
          }
-      }      
+      }   
    }
    
-   private boolean attributesMatch(T annotation, AttributeValue[] attributes)
-   {
-      Class<?> cls = annotation.getClass();
-      for (AttributeValue attrib : attributes)
-      {
-         try
-         {
-            Field f = cls.getField(attrib.getName());
-            if (!f.get(annotation).equals(attrib.getValue()))
-            {
-               return false;
-            }
-         }
-         catch (IllegalAccessException e)
-         {
-            return false;
-         }
-         catch (NoSuchFieldException e)
-         {
-            return false;
-         }         
-      }
-      
-      return true;
-   }
+   protected abstract boolean isMatch(T annotation);
 
    private void setupFieldProperty(Field propertyField)
    {



More information about the seam-commits mailing list