[jboss-cvs] JBossAS SVN: r66482 - branches/JBoss_4_0_3_SP1_JBAS-4771/security/src/main/org/jboss/security/auth/spi.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 26 06:22:11 EDT 2007


Author: darran.lofthouse at jboss.com
Date: 2007-10-26 06:22:11 -0400 (Fri, 26 Oct 2007)
New Revision: 66482

Modified:
   branches/JBoss_4_0_3_SP1_JBAS-4771/security/src/main/org/jboss/security/auth/spi/Util.java
Log:
JBAS-4771 - Backport addition to security Util class.

Modified: branches/JBoss_4_0_3_SP1_JBAS-4771/security/src/main/org/jboss/security/auth/spi/Util.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-4771/security/src/main/org/jboss/security/auth/spi/Util.java	2007-10-26 09:57:36 UTC (rev 66481)
+++ branches/JBoss_4_0_3_SP1_JBAS-4771/security/src/main/org/jboss/security/auth/spi/Util.java	2007-10-26 10:22:11 UTC (rev 66482)
@@ -11,7 +11,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;
@@ -303,7 +303,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.
@@ -330,5 +383,5 @@
             aslm.log.warn("Failed to create principal for: "+token, e);
          }
       }
-   }
+   } 
 }




More information about the jboss-cvs-commits mailing list