--- C:/Users/Utente/AppData/Local/Temp/JAASRealm.java-revBASE.svn000.tmp.java ven ago 24 17:20:06 2012 +++ C:/work/tomcat7/java/org/apache/catalina/realm/JAASRealm.java ven ago 24 17:18:55 2012 @@ -19,6 +19,11 @@ package org.apache.catalina.realm; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; import java.security.Principal; import java.util.ArrayList; import java.util.Iterator; @@ -27,6 +32,7 @@ import javax.security.auth.Subject; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.login.AccountExpiredException; +import javax.security.auth.login.Configuration; import javax.security.auth.login.CredentialExpiredException; import javax.security.auth.login.FailedLoginException; import javax.security.auth.login.LoginContext; @@ -172,10 +178,28 @@ */ protected boolean useContextClassLoader = true; - + /** + * Path to find a JAAS configuration file, if not set global JVM JAAS configuraion will be used + */ + protected String configfile; + // ------------------------------------------------------------- Properties - + /** + * getter for the configfile member variable + */ + public String getConfigfile() { + return configfile; + } + + /** + * setter for the configfile member variable + */ + public void setConfigfile(String configfile) { + this.configfile = configfile; + } + + /** * setter for the appName member variable */ @@ -278,7 +302,12 @@ "java.security.Principal! Class not added."); } } catch (ClassNotFoundException e) { - log.error("Class "+classNames[i]+" not found! Class not added."); + if (isUseContextClassLoader()) { + log.warn("Class "+classNames[i]+" could not be verified",e); + classNamesList.add(classNames[i]); + } else { + log.error("Class "+classNames[i]+" not found! Class not added."); + } } } } @@ -389,7 +418,8 @@ } try { - loginContext = new LoginContext(appName, callbackHandler); + Configuration config = getConfig(); + loginContext = new LoginContext(appName, null, callbackHandler, config); } catch (Throwable e) { ExceptionUtils.handleThrowable(e); log.error(sm.getString("jaasRealm.unexpectedError"), e); @@ -605,4 +635,49 @@ super.startInternal(); } + + protected Configuration jaasConfiguration; + protected volatile boolean jaasConfigurationLoaded = false; + + /** + * Load custom JAAS Configuration + */ + protected Configuration getConfig() { + try { + if (jaasConfigurationLoaded) { + return jaasConfiguration; + } + synchronized (this) { + if (configfile == null) { + jaasConfigurationLoaded = true; + return null; + } + URL resource = Thread.currentThread().getContextClassLoader().getResource(configfile); + URI uri = resource.toURI(); + Class sunConfigFile = Class.forName("com.sun.security.auth.login.ConfigFile"); + Constructor constructor = sunConfigFile.getConstructor(URI.class); + Configuration config = constructor.newInstance(uri); + this.jaasConfiguration = config; + this.jaasConfigurationLoaded = true; + return this.jaasConfiguration; + } + } catch (URISyntaxException ex) { + throw new RuntimeException(ex); + } catch (NoSuchMethodException ex) { + throw new RuntimeException(ex); + } catch (SecurityException ex) { + throw new RuntimeException(ex); + } catch (InstantiationException ex) { + throw new RuntimeException(ex); + } catch (IllegalAccessException ex) { + throw new RuntimeException(ex); + } catch (IllegalArgumentException ex) { + throw new RuntimeException(ex); + } catch (InvocationTargetException ex) { + throw new RuntimeException(ex.getCause()); + } catch (ClassNotFoundException ex) { + throw new RuntimeException(ex); + } + + } }