Lines 19-24
Link Here
|
19 |
package org.apache.catalina.realm; |
19 |
package org.apache.catalina.realm; |
20 |
|
20 |
|
21 |
|
21 |
|
|
|
22 |
import java.lang.reflect.Constructor; |
23 |
import java.lang.reflect.InvocationTargetException; |
24 |
import java.net.URI; |
25 |
import java.net.URISyntaxException; |
26 |
import java.net.URL; |
22 |
import java.security.Principal; |
27 |
import java.security.Principal; |
23 |
import java.util.ArrayList; |
28 |
import java.util.ArrayList; |
24 |
import java.util.Iterator; |
29 |
import java.util.Iterator; |
Lines 27-32
Link Here
|
27 |
import javax.security.auth.Subject; |
32 |
import javax.security.auth.Subject; |
28 |
import javax.security.auth.callback.CallbackHandler; |
33 |
import javax.security.auth.callback.CallbackHandler; |
29 |
import javax.security.auth.login.AccountExpiredException; |
34 |
import javax.security.auth.login.AccountExpiredException; |
|
|
35 |
import javax.security.auth.login.Configuration; |
30 |
import javax.security.auth.login.CredentialExpiredException; |
36 |
import javax.security.auth.login.CredentialExpiredException; |
31 |
import javax.security.auth.login.FailedLoginException; |
37 |
import javax.security.auth.login.FailedLoginException; |
32 |
import javax.security.auth.login.LoginContext; |
38 |
import javax.security.auth.login.LoginContext; |
Lines 122-128
Link Here
|
122 |
* |
128 |
* |
123 |
* @author Craig R. McClanahan |
129 |
* @author Craig R. McClanahan |
124 |
* @author Yoav Shapira |
130 |
* @author Yoav Shapira |
125 |
* @version $Id: JAASRealm.java 1361770 2012-07-15 19:38:51Z markt $ |
131 |
* @version $Id$ |
126 |
*/ |
132 |
*/ |
127 |
|
133 |
|
128 |
public class JAASRealm |
134 |
public class JAASRealm |
Lines 173-180
Link Here
|
173 |
protected boolean useContextClassLoader = true; |
179 |
protected boolean useContextClassLoader = true; |
174 |
|
180 |
|
175 |
|
181 |
|
|
|
182 |
|
183 |
/** |
184 |
* Path to find a JAAS configuration file, if not set global JVM JAAS configuraion will be used |
185 |
*/ |
186 |
protected String configfile; |
187 |
|
176 |
// ------------------------------------------------------------- Properties |
188 |
// ------------------------------------------------------------- Properties |
177 |
|
189 |
|
|
|
190 |
/** |
191 |
* getter for the <code>configfile</code> member variable |
192 |
*/ |
193 |
public String getConfigfile() { |
194 |
return configfile; |
195 |
} |
196 |
|
197 |
/** |
198 |
* setter for the <code>configfile</code> member variable |
199 |
*/ |
200 |
public void setConfigfile(String configfile) { |
201 |
this.configfile = configfile; |
202 |
} |
203 |
|
204 |
|
178 |
|
205 |
|
179 |
/** |
206 |
/** |
180 |
* setter for the <code>appName</code> member variable |
207 |
* setter for the <code>appName</code> member variable |
Lines 389-395
Link Here
|
389 |
} |
416 |
} |
390 |
|
417 |
|
391 |
try { |
418 |
try { |
392 |
loginContext = new LoginContext(appName, callbackHandler); |
419 |
Configuration config = getConfig(); |
|
|
420 |
loginContext = new LoginContext(appName, null, callbackHandler, config); |
393 |
} catch (Throwable e) { |
421 |
} catch (Throwable e) { |
394 |
ExceptionUtils.handleThrowable(e); |
422 |
ExceptionUtils.handleThrowable(e); |
395 |
log.error(sm.getString("jaasRealm.unexpectedError"), e); |
423 |
log.error(sm.getString("jaasRealm.unexpectedError"), e); |
Lines 605-608
Link Here
|
605 |
|
633 |
|
606 |
super.startInternal(); |
634 |
super.startInternal(); |
607 |
} |
635 |
} |
|
|
636 |
protected Configuration jaasConfiguration; |
637 |
protected volatile boolean jaasConfigurationLoaded = false; |
638 |
|
639 |
/** |
640 |
* Load custom JAAS Configuration |
641 |
*/ |
642 |
protected Configuration getConfig() { |
643 |
try { |
644 |
if (jaasConfigurationLoaded) { |
645 |
return jaasConfiguration; |
646 |
} |
647 |
synchronized (this) { |
648 |
if (configfile == null) { |
649 |
jaasConfigurationLoaded = true; |
650 |
return null; |
651 |
} |
652 |
URL resource = Thread.currentThread().getContextClassLoader().getResource(configfile); |
653 |
URI uri = resource.toURI(); |
654 |
Class sunConfigFile = Class.forName("com.sun.security.auth.login.ConfigFile"); |
655 |
Constructor<Configuration> constructor = sunConfigFile.getConstructor(URI.class); |
656 |
Configuration config = constructor.newInstance(uri); |
657 |
this.jaasConfiguration = config; |
658 |
this.jaasConfigurationLoaded = true; |
659 |
return this.jaasConfiguration; |
660 |
} |
661 |
} catch (URISyntaxException ex) { |
662 |
throw new RuntimeException(ex); |
663 |
} catch (NoSuchMethodException ex) { |
664 |
throw new RuntimeException(ex); |
665 |
} catch (SecurityException ex) { |
666 |
throw new RuntimeException(ex); |
667 |
} catch (InstantiationException ex) { |
668 |
throw new RuntimeException(ex); |
669 |
} catch (IllegalAccessException ex) { |
670 |
throw new RuntimeException(ex); |
671 |
} catch (IllegalArgumentException ex) { |
672 |
throw new RuntimeException(ex); |
673 |
} catch (InvocationTargetException ex) { |
674 |
throw new RuntimeException(ex.getCause()); |
675 |
} catch (ClassNotFoundException ex) { |
676 |
throw new RuntimeException(ex); |
677 |
} |
678 |
|
679 |
} |
608 |
} |
680 |
} |