[jboss-cvs] JBossAS SVN: r57343 - in branches/JBoss_4_0_4_GA_CP: security/src/main/org/jboss/security/auth/spi testsuite/src/main/org/jboss/test/security/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Oct 1 22:35:51 EDT 2006


Author: ryan.campbell at jboss.com
Date: 2006-10-01 22:35:50 -0400 (Sun, 01 Oct 2006)
New Revision: 57343

Added:
   branches/JBoss_4_0_4_GA_CP/security/src/main/org/jboss/security/auth/spi/RoleMappingLoginModule.java
   branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/security/test/RoleMappingModuleUnitTestCase.java
Modified:
   branches/JBoss_4_0_4_GA_CP/security/src/main/org/jboss/security/auth/spi/Util.java
Log:
ASPATCH-62: JBAS-3338: Role Mapping Login Module that maps application role to declarative role

Copied: branches/JBoss_4_0_4_GA_CP/security/src/main/org/jboss/security/auth/spi/RoleMappingLoginModule.java (from rev 57342, branches/JBoss_4_0_4_JBAS-3323/security/src/main/org/jboss/security/auth/spi/RoleMappingLoginModule.java)

Modified: branches/JBoss_4_0_4_GA_CP/security/src/main/org/jboss/security/auth/spi/Util.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/security/src/main/org/jboss/security/auth/spi/Util.java	2006-10-02 01:51:07 UTC (rev 57342)
+++ branches/JBoss_4_0_4_GA_CP/security/src/main/org/jboss/security/auth/spi/Util.java	2006-10-02 02:35:50 UTC (rev 57343)
@@ -25,7 +25,7 @@
 import java.util.Enumeration;
 import java.util.ArrayList;
 import java.util.StringTokenizer;
-import java.util.HashMap;
+import java.util.HashMap; 
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -348,7 +348,60 @@
 
       return bundle;
    }
+   
+   /** Utility method which loads the given properties file and returns a
+    * Properties object containing the key,value pairs in that file.
+    * The properties files should be in the class path as this method looks
+    * to the thread context class loader (TCL) to locate the resource. If the
+    * TCL is a URLClassLoader the findResource(String) method is first tried.
+    * If this fails or the TCL is not a URLClassLoader getResource(String) is
+    * tried. If not, an absolute path is tried.
+    * @param propertiesName - the name of the properties file resource
+    * @param log - the logger used for trace level messages
+    * @return the loaded properties file if found
+    * @exception java.io.IOException thrown if the properties file cannot be found
+    *    or loaded 
+    */
+   static Properties loadProperties(String propertiesName, Logger log)
+      throws IOException
+   { 
+      ClassLoader loader = Thread.currentThread().getContextClassLoader(); 
+      URL url = null;
+      // First check for local visibility via a URLClassLoader.findResource
+      if( loader instanceof URLClassLoader )
+      {
+         URLClassLoader ucl = (URLClassLoader) loader; 
+         url = ucl.findResource(propertiesName);
+         log.trace("findResource: "+url);
+      } 
+      if( url == null )
+         url = loader.getResource(propertiesName);
+      if( url == null)
+      {
+         url = new URL(propertiesName); 
+      }
 
+      log.trace("Properties file=" + url ); 
+
+      Properties bundle = new Properties();
+      if( url != null )
+      {
+         InputStream is = url.openStream();
+         if (is != null)
+         {
+            bundle.load(is);
+            is.close();
+         }
+         else
+         {
+            throw new IOException("Properties file " + propertiesName + " not avilable");
+         }
+         log.debug("Loaded properties, users="+bundle.keySet());
+      }
+
+      return bundle;
+   }
+
    /** Parse the comma delimited roles names given by value and add them to
     * group. The type of Principal created for each name is determined by
     * the createIdentity method.
@@ -375,5 +428,5 @@
             aslm.log.warn("Failed to create principal for: "+token, e);
          }
       }
-   }
+   } 
 }

Copied: branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/security/test/RoleMappingModuleUnitTestCase.java (from rev 57342, branches/JBoss_4_0_4_JBAS-3323/testsuite/src/main/org/jboss/test/security/test/RoleMappingModuleUnitTestCase.java)




More information about the jboss-cvs-commits mailing list