[seam-commits] Seam SVN: r7549 - trunk/src/main/org/jboss/seam/security/management.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Mar 12 21:11:48 EDT 2008


Author: shane.bryzak at jboss.com
Date: 2008-03-12 21:11:48 -0400 (Wed, 12 Mar 2008)
New Revision: 7549

Modified:
   trunk/src/main/org/jboss/seam/security/management/IdentityStore.java
   trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java
   trunk/src/main/org/jboss/seam/security/management/LdapIdentityStore.java
Log:
deterministic feature sets for identity stores

Modified: trunk/src/main/org/jboss/seam/security/management/IdentityStore.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/management/IdentityStore.java	2008-03-12 22:19:25 UTC (rev 7548)
+++ trunk/src/main/org/jboss/seam/security/management/IdentityStore.java	2008-03-13 01:11:48 UTC (rev 7549)
@@ -10,6 +10,58 @@
  */
 public interface IdentityStore
 {     
+   public class FeatureSet 
+   {
+      public static final int FEATURE_CREATE_USER = 1;
+      public static final int FEATURE_DELETE_USER = 2;
+      public static final int FEATURE_ENABLE_USER = 4;
+      public static final int FEATURE_DISABLE_USER = 8;      
+      public static final int FEATURE_CHANGE_PASSWORD = 16;
+      
+      public static final int FEATURE_CREATE_ROLE = 32;
+      public static final int FEATURE_DELETE_ROLE = 64;
+      public static final int FEATURE_GRANT_ROLE = 128;
+      public static final int FEATURE_REVOKE_ROLE = 256;
+      
+      public static final int FEATURE_ALL_USER = FEATURE_CREATE_USER | 
+          FEATURE_DELETE_USER | 
+          FEATURE_ENABLE_USER |
+          FEATURE_DISABLE_USER |
+          FEATURE_CHANGE_PASSWORD;
+      
+      public static final int FEATURE_ALL_ROLE = FEATURE_CREATE_ROLE |
+          FEATURE_DELETE_ROLE |
+          FEATURE_GRANT_ROLE |
+          FEATURE_REVOKE_ROLE;
+          
+      public static final int FEATURE_ALL = FEATURE_ALL_USER | FEATURE_ALL_ROLE;
+      
+      private int features;
+      
+      public FeatureSet(int features)
+      {
+         this.features = features;
+      }
+      
+      public FeatureSet addFeature(int feature)
+      {
+         features |= feature;
+         return this;
+      }
+      
+      public int getFeatures()
+      {
+         return features;
+      }
+      
+      public boolean supports(int feature)
+      {
+         return (features & feature) == feature;
+      }
+   }
+   
+   boolean supportsFeature(int feature);
+   
    boolean createUser(String username, String password);
    boolean deleteUser(String name);   
    boolean enableUser(String name);

Modified: trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java	2008-03-12 22:19:25 UTC (rev 7548)
+++ trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java	2008-03-13 01:11:48 UTC (rev 7549)
@@ -36,12 +36,29 @@
    public static final String EVENT_ACCOUNT_CREATED = "org.jboss.seam.security.management.accountCreated"; 
    public static final String EVENT_ACCOUNT_AUTHENTICATED = "org.jboss.seam.security.management.accountAuthenticated";
    
+   protected FeatureSet featureSet = new FeatureSet(FeatureSet.FEATURE_ALL);
+   
    private String entityManagerName = "entityManager";
    
    private Class<? extends UserAccount> accountClass;
    
    private Map<String,Set<String>> roleCache;
    
+   public int getFeatures()
+   {
+      return featureSet.getFeatures();
+   }
+   
+   public void setFeatures(int features)
+   {
+      featureSet = new FeatureSet(features);
+   }
+   
+   public boolean supportsFeature(int feature)
+   {
+      return featureSet.supports(feature);
+   }
+   
    @Create
    public void init()
    {

Modified: trunk/src/main/org/jboss/seam/security/management/LdapIdentityStore.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/management/LdapIdentityStore.java	2008-03-12 22:19:25 UTC (rev 7548)
+++ trunk/src/main/org/jboss/seam/security/management/LdapIdentityStore.java	2008-03-13 01:11:48 UTC (rev 7549)
@@ -31,6 +31,8 @@
 @BypassInterceptors
 public class LdapIdentityStore implements IdentityStore
 {
+   protected FeatureSet featureSet = new FeatureSet(FeatureSet.FEATURE_ALL);
+   
    private String serverAddress = "localhost";
    
    private int serverPort = 389;
@@ -52,7 +54,7 @@
    private boolean roleAttributeIsDN = true;   
    
    private String roleNameAttribute = "cn";
-   
+      
    public String getServerAddress()
    {
       return serverAddress;
@@ -163,6 +165,21 @@
       this.roleNameAttribute = roleNameAttribute;
    }
    
+   public int getFeatures()
+   {
+      return featureSet.getFeatures();
+   }
+   
+   public void setFeatures(int features)
+   {
+      featureSet = new FeatureSet(features);
+   }
+   
+   public boolean supportsFeature(int feature)
+   {
+      return featureSet.supports(feature);
+   }
+   
    protected final InitialLdapContext initialiseContext()
       throws NamingException
    {
@@ -251,8 +268,19 @@
 
    public boolean deleteRole(String role) 
    {
-      // TODO Auto-generated method stub
-      return false;
+      InitialLdapContext ctx = null;      
+      try
+      {
+         ctx = initialiseContext();
+                 
+         String roleDN = String.format("%s=%s,%s", getRoleNameAttribute(), role, roleContextDN);          
+         ctx.destroySubcontext(roleDN);         
+         return true;
+      }
+      catch (NamingException ex)
+      {
+         throw new IdentityManagementException("Failed to create role", ex);
+      }
    }
 
    public boolean deleteUser(String name) 




More information about the seam-commits mailing list