private static Properties loadProperties ( String defaultsName , String propertiesName ) throws IOException { Properties bundle = new Properties ( ) ; ClassLoader loader = SecurityActions . getContextClassLoader ( ) ; URL defaultUrl = null ; URL url = null ; // First check for local visibility via a URLClassLoader.findResource if ( loader instanceof URLClassLoader ) { URLClassLoader ucl = ( URLClassLoader ) loader ; defaultUrl = SecurityActions . findResource ( ucl , defaultsName ) ; url = SecurityActions . findResource ( ucl , propertiesName ) ; PicketBoxLogger . LOGGER . traceAttemptToLoadResource ( propertiesName ) ; } // Do a general resource search if ( defaultUrl == null ) { defaultUrl = loader . getResource ( defaultsName ) ; if ( defaultUrl == null ) { try { defaultUrl = new URL ( defaultsName ) ; } catch ( MalformedURLException mue ) { PicketBoxLogger . LOGGER . debugFailureToOpenPropertiesFromURL ( mue ) ; File tmp = new File ( defaultsName ) ; if ( tmp . exists ( ) ) { defaultUrl = tmp . toURI ( ) . toURL ( ) ; } } } } if ( url == null ) { url = loader . getResource ( propertiesName ) ; if ( url == null ) { try { url = new URL ( propertiesName ) ; } catch ( MalformedURLException mue ) { PicketBoxLogger . LOGGER . debugFailureToOpenPropertiesFromURL ( mue ) ; File tmp = new File ( propertiesName ) ; if ( tmp . exists ( ) ) { url = tmp . toURI ( ) . toURL ( ) ; } } } } if ( url == null && defaultUrl == null ) { String propertiesFiles = propertiesName + "/" + defaultsName ; throw PicketBoxMessages . MESSAGES . unableToFindPropertiesFile ( propertiesFiles ) ; } if ( url != null ) { InputStream is = null ; try { is = SecurityActions . openStream ( url ) ; } catch ( PrivilegedActionException e ) { throw new IOException ( e . getLocalizedMessage ( ) ) ; } if ( is != null ) { try { bundle . load ( is ) ; } finally { safeClose ( is ) ; } } else { throw PicketBoxMessages . MESSAGES . unableToLoadPropertiesFile ( propertiesName ) ; } PicketBoxLogger . LOGGER . tracePropertiesFileLoaded ( propertiesName , bundle . keySet ( ) ) ; } else { InputStream is = null ; try { is = defaultUrl . openStream ( ) ; bundle . load ( is ) ; PicketBoxLogger . LOGGER . tracePropertiesFileLoaded ( defaultsName , bundle . keySet ( ) ) ; } catch ( Throwable e ) { PicketBoxLogger . LOGGER . debugFailureToLoadPropertiesFile ( defaultsName , e ) ; } finally { safeClose ( is ) ; } } return bundle ; }
helper method to load digest user property file . Copied from org . jboss . security . auth . spi . Util