[jboss-cvs] JBossAS SVN: r100312 - projects/security/picketbox/trunk/picketbox/src/main/java/org/picketbox/config.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 2 21:28:43 EST 2010


Author: anil.saldhana at jboss.com
Date: 2010-02-02 21:28:43 -0500 (Tue, 02 Feb 2010)
New Revision: 100312

Modified:
   projects/security/picketbox/trunk/picketbox/src/main/java/org/picketbox/config/PicketBoxConfiguration.java
Log:
make the config file locatable

Modified: projects/security/picketbox/trunk/picketbox/src/main/java/org/picketbox/config/PicketBoxConfiguration.java
===================================================================
--- projects/security/picketbox/trunk/picketbox/src/main/java/org/picketbox/config/PicketBoxConfiguration.java	2010-02-03 02:23:18 UTC (rev 100311)
+++ projects/security/picketbox/trunk/picketbox/src/main/java/org/picketbox/config/PicketBoxConfiguration.java	2010-02-03 02:28:43 UTC (rev 100312)
@@ -21,17 +21,17 @@
  */
 package org.picketbox.config;
 
+import java.io.IOException;
 import java.io.InputStream;
-import java.io.IOException;
-import java.security.PrivilegedActionException;
+import java.net.URL;
 
 import javax.xml.stream.XMLStreamException;
 
+import org.jboss.logging.Logger;
 import org.jboss.security.config.parser.StaxBasedConfigParser;
 import org.picketbox.exceptions.ConfigurationFileNullException;
 import org.picketbox.exceptions.ConfigurationParsingException;
 import org.picketbox.exceptions.ConfigurationStreamNullException;
-
 import org.xml.sax.SAXException;
 
 /**
@@ -41,6 +41,8 @@
  */
 public class PicketBoxConfiguration
 { 
+   private static Logger log = Logger.getLogger(PicketBoxConfiguration.class);
+   
    /**
     * Load a configuration file
     * @param configFileName
@@ -51,16 +53,8 @@
    {
       if(configFileName == null)
          throw new ConfigurationFileNullException("configFileName is null");
-      try
-      {
-         ClassLoader tcl = SecurityActions.getContextClassLoader();
-         InputStream configStream = tcl.getResourceAsStream(configFileName);
-         load(configStream);
-      }
-      catch (PrivilegedActionException e)
-      {
-         throw new RuntimeException(e.getCause());
-      }
+      InputStream configStream = loadStream(configFileName);
+      load(configStream);   
    }
    
    /**
@@ -74,7 +68,8 @@
       if(configStream == null)
          throw new ConfigurationStreamNullException("configStream is null");
       
-      //Parser will parse the stream and update the XMLLoginConfigImpl
+      //Parser will parse the stream and update the JAAS Configuration 
+      // set on JDK Configuration.getConfiguration and is an instance of ApplicationPolicyRegistration
       StaxBasedConfigParser parser = new StaxBasedConfigParser();
       try
       {
@@ -93,4 +88,47 @@
          throw new ConfigurationParsingException(i);
       }
    }
+   
+   private InputStream loadStream(String configFileName)
+   {
+      InputStream configStream = null;
+
+      //Try the TCCL
+      try
+      {
+         ClassLoader tcl = SecurityActions.getContextClassLoader();
+         configStream = tcl.getResourceAsStream(configFileName);  
+      }
+      catch(Exception e)
+      { 
+         if(log.isTraceEnabled())
+            log.error("Exception loading " + configFileName + " as tcl resource",e);
+      }
+      //Try the loading class CL
+      try
+      {
+         if(configStream == null)
+            configStream = getClass().getClassLoader().getResourceAsStream(configFileName);
+      }
+      catch(Exception e)
+      { 
+         if(log.isTraceEnabled())
+            log.error("Exception loading " + configFileName + " as cl resource",e);
+      }
+      //Try the URL stream
+      try
+      {
+         if(configStream == null)
+         {
+            URL url = new URL(configFileName);
+            configStream = url.openStream();
+         }
+      }  
+      catch(Exception e)
+      { 
+         if(log.isTraceEnabled())
+            log.error("Exception loading " + configFileName + " as URL resource",e);
+      }
+      return configStream;
+   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list