Lines 250-261
Link Here
|
250 |
*/ |
250 |
*/ |
251 |
public void setRoleClassNames(String roleClassNames) { |
251 |
public void setRoleClassNames(String roleClassNames) { |
252 |
this.roleClassNames = roleClassNames; |
252 |
this.roleClassNames = roleClassNames; |
253 |
parseClassNames(roleClassNames, roleClasses); |
|
|
254 |
} |
253 |
} |
255 |
|
254 |
|
256 |
/** |
255 |
/** |
257 |
* Parses a comma-delimited list of class names, and store the class names |
256 |
* Parses a comma-delimited list of class names, and store the class names |
258 |
* in the provided List. Each class must implement <codejava.security.Principal</code>. |
257 |
* in the provided List. Each class must implement <code>java.security.Principal</code>. |
259 |
* |
258 |
* |
260 |
* @param classNamesString a comma-delimited list of fully qualified class names. |
259 |
* @param classNamesString a comma-delimited list of fully qualified class names. |
261 |
* @param classNamesList the list in which the class names will be stored. |
260 |
* @param classNamesList the list in which the class names will be stored. |
Lines 264-275
Link Here
|
264 |
protected void parseClassNames(String classNamesString, List<String> classNamesList) { |
263 |
protected void parseClassNames(String classNamesString, List<String> classNamesList) { |
265 |
classNamesList.clear(); |
264 |
classNamesList.clear(); |
266 |
if (classNamesString == null) return; |
265 |
if (classNamesString == null) return; |
|
|
266 |
|
267 |
ClassLoader loader = this.getClass().getClassLoader(); |
268 |
if (isUseContextClassLoader()) |
269 |
loader = Thread.currentThread().getContextClassLoader(); |
267 |
|
270 |
|
268 |
String[] classNames = classNamesString.split("[ ]*,[ ]*"); |
271 |
String[] classNames = classNamesString.split("[ ]*,[ ]*"); |
269 |
for (int i=0; i<classNames.length; i++) { |
272 |
for (int i=0; i<classNames.length; i++) { |
270 |
if (classNames[i].length()==0) continue; |
273 |
if (classNames[i].length()==0) continue; |
271 |
try { |
274 |
try { |
272 |
Class principalClass = Class.forName(classNames[i]); |
275 |
Class principalClass = Class.forName(classNames[i], false, loader); |
273 |
if (Principal.class.isAssignableFrom(principalClass)) { |
276 |
if (Principal.class.isAssignableFrom(principalClass)) { |
274 |
classNamesList.add(classNames[i]); |
277 |
classNamesList.add(classNames[i]); |
275 |
} else { |
278 |
} else { |
Lines 302-308
Link Here
|
302 |
*/ |
305 |
*/ |
303 |
public void setUserClassNames(String userClassNames) { |
306 |
public void setUserClassNames(String userClassNames) { |
304 |
this.userClassNames = userClassNames; |
307 |
this.userClassNames = userClassNames; |
305 |
parseClassNames(userClassNames, userClasses); |
|
|
306 |
} |
308 |
} |
307 |
|
309 |
|
308 |
|
310 |
|
Lines 323-329
Link Here
|
323 |
* authenticating this username |
325 |
* authenticating this username |
324 |
*/ |
326 |
*/ |
325 |
public Principal authenticate(String username, String credentials) { |
327 |
public Principal authenticate(String username, String credentials) { |
|
|
328 |
ClassLoader ocl = null; |
326 |
|
329 |
|
|
|
330 |
if( !isUseContextClassLoader()) { |
331 |
ocl=Thread.currentThread().getContextClassLoader(); |
332 |
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); |
333 |
} |
334 |
|
327 |
// Establish a LoginContext to use for authentication |
335 |
// Establish a LoginContext to use for authentication |
328 |
try { |
336 |
try { |
329 |
LoginContext loginContext = null; |
337 |
LoginContext loginContext = null; |
Lines 332-345
Link Here
|
332 |
if( log.isDebugEnabled()) |
340 |
if( log.isDebugEnabled()) |
333 |
log.debug(sm.getString("jaasRealm.beginLogin", username, appName)); |
341 |
log.debug(sm.getString("jaasRealm.beginLogin", username, appName)); |
334 |
|
342 |
|
335 |
// What if the LoginModule is in the container class loader ? |
|
|
336 |
ClassLoader ocl = null; |
337 |
|
343 |
|
338 |
if (isUseContextClassLoader()) { |
|
|
339 |
ocl=Thread.currentThread().getContextClassLoader(); |
340 |
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); |
341 |
} |
342 |
|
343 |
try { |
344 |
try { |
344 |
loginContext = new LoginContext |
345 |
loginContext = new LoginContext |
345 |
(appName, new JAASCallbackHandler(this, username, |
346 |
(appName, new JAASCallbackHandler(this, username, |
Lines 347-356
Link Here
|
347 |
} catch (Throwable e) { |
348 |
} catch (Throwable e) { |
348 |
log.error(sm.getString("jaasRealm.unexpectedError"), e); |
349 |
log.error(sm.getString("jaasRealm.unexpectedError"), e); |
349 |
return (null); |
350 |
return (null); |
350 |
} finally { |
|
|
351 |
if( isUseContextClassLoader()) { |
352 |
Thread.currentThread().setContextClassLoader(ocl); |
353 |
} |
354 |
} |
351 |
} |
355 |
|
352 |
|
356 |
if( log.isDebugEnabled()) |
353 |
if( log.isDebugEnabled()) |
Lines 404-409
Link Here
|
404 |
log.error( "error ", t); |
401 |
log.error( "error ", t); |
405 |
return null; |
402 |
return null; |
406 |
} |
403 |
} |
|
|
404 |
finally { |
405 |
if( !isUseContextClassLoader()) { |
406 |
Thread.currentThread().setContextClassLoader(ocl); |
407 |
} |
408 |
} |
407 |
} |
409 |
} |
408 |
|
410 |
|
409 |
|
411 |
|
Lines 547-552
Link Here
|
547 |
// Perform normal superclass initialization |
549 |
// Perform normal superclass initialization |
548 |
super.start(); |
550 |
super.start(); |
549 |
|
551 |
|
|
|
552 |
// These need to be called after loading configuration, in case |
553 |
// useContextClassLoader appears after them in xml config |
554 |
parseClassNames(userClassNames, userClasses); |
555 |
parseClassNames(roleClassNames, roleClasses); |
550 |
} |
556 |
} |
551 |
|
557 |
|
552 |
|
558 |
|