[jboss-cvs] JBossAS SVN: r70443 - projects/security/security-jboss-sx/trunk/acl/src/main/java/org/jboss/security/acl.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 5 13:54:13 EST 2008


Author: sguilhen at redhat.com
Date: 2008-03-05 13:54:12 -0500 (Wed, 05 Mar 2008)
New Revision: 70443

Modified:
   projects/security/security-jboss-sx/trunk/acl/src/main/java/org/jboss/security/acl/ACLImpl.java
Log:
Fixed NPE that was being thrown by the ACLImpl when checking for permissions.



Modified: projects/security/security-jboss-sx/trunk/acl/src/main/java/org/jboss/security/acl/ACLImpl.java
===================================================================
--- projects/security/security-jboss-sx/trunk/acl/src/main/java/org/jboss/security/acl/ACLImpl.java	2008-03-05 18:03:22 UTC (rev 70442)
+++ projects/security/security-jboss-sx/trunk/acl/src/main/java/org/jboss/security/acl/ACLImpl.java	2008-03-05 18:54:12 UTC (rev 70443)
@@ -112,7 +112,6 @@
       this.resource = resource;
       this.resourceAsString = Util.getResourceAsString(resource);
       this.entries = new ArrayList<ACLEntryImpl>();
-      this.entriesMap = new HashMap<Identity, ACLEntry>();
       if (entries != null)
       {
          for (ACLEntry entry : entries)
@@ -120,9 +119,9 @@
             ACLEntryImpl entryImpl = (ACLEntryImpl) entry;
             entryImpl.setAcl(this);
             this.entries.add(entryImpl);
-            this.entriesMap.put(entryImpl.getIdentity(), entryImpl);
          }
       }
+      this.initEntriesMap();
    }
 
    /**
@@ -143,6 +142,9 @@
     */
    public boolean addEntry(ACLEntry entry)
    {
+      if (this.entriesMap == null)
+         this.initEntriesMap();
+
       // don't add a null entry or an entry that already existSELECT * FROM ACL_ENTRYs.
       if (entry == null || this.entriesMap.get(entry.getIdentity()) != null)
          return false;
@@ -158,6 +160,8 @@
     */
    public boolean removeEntry(ACLEntry entry)
    {
+      if (this.entriesMap == null)
+         this.initEntriesMap();
       this.entriesMap.remove(entry.getIdentity());
       return this.entries.remove(entry);
    }
@@ -169,14 +173,27 @@
    public Collection<? extends ACLEntry> getEntries()
    {
       if (this.entriesMap == null)
+         this.initEntriesMap();
+      return Collections.unmodifiableCollection(this.entries);
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see org.jboss.security.acl.ACL#isGranted(org.jboss.security.acl.ACLPermission, org.jboss.security.identity.Identity)
+    */
+   public boolean isGranted(ACLPermission permission, Identity identity)
+   {
+      if (this.entriesMap == null)
+         this.initEntriesMap();
+
+      // lookup the entry corresponding to the specified identity.
+      ACLEntry entry = this.entriesMap.get(identity);
+      if (entry != null)
       {
-         this.entriesMap = new HashMap<Identity, ACLEntry>();
-         for (ACLEntry entry : this.getEntries())
-         {
-            this.entriesMap.put(entry.getIdentity(), entry);
-         }
+         // check the permission associated with the identity.
+         return entry.checkPermission(permission);
       }
-      return Collections.unmodifiableCollection(this.entries);
+      return false;
    }
 
    /*
@@ -188,6 +205,13 @@
       return this.resource;
    }
 
+   /**
+    * <p>
+    * Sets the resource associated with this {@code ACL}.
+    * </p>
+    * 
+    * @param resource   a reference to the {@code Resource} associated with this {@code ACL}.
+    */
    public void setResource(Resource resource)
    {
       if (this.resource != null)
@@ -195,19 +219,15 @@
       this.resource = resource;
    }
 
-   /*
-    * (non-Javadoc)
-    * @see org.jboss.security.acl.ACL#isGranted(org.jboss.security.acl.ACLPermission, org.jboss.security.identity.Identity)
+   /**
+    * <p>
+    * Initializes the entries map of this {@code ACL} instance.
+    * </p>
     */
-   public boolean isGranted(ACLPermission permission, Identity identity)
+   private void initEntriesMap()
    {
-      // lookup the entry corresponding to the specified identity.
-      ACLEntry entry = this.entriesMap.get(identity);
-      if (entry != null)
-      {
-         // check the permission associated with the identity.
-         return entry.checkPermission(permission);
-      }
-      return false;
+      this.entriesMap = new HashMap<Identity, ACLEntry>();
+      for (ACLEntry entry : this.entries)
+         this.entriesMap.put(entry.getIdentity(), entry);
    }
 }




More information about the jboss-cvs-commits mailing list