mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-25 21:42:17 +00:00
Added method to support unit testing, and made class more robust to null conditions.
This commit is contained in:
parent
dd39d747d5
commit
b886390a3f
@ -22,6 +22,7 @@ import java.security.Principal;
|
|||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.naming.Context;
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
|
|
||||||
@ -48,10 +49,24 @@ public class JbossIntegrationFilter extends AbstractIntegrationFilter {
|
|||||||
Subject subject = null;
|
Subject subject = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InitialContext ic = new InitialContext();
|
Context lc = this.getLookupContext();
|
||||||
subject = (Subject) ic.lookup("java:comp/env/security/subject");
|
|
||||||
|
if (lc == null) {
|
||||||
|
if (super.logger.isWarnEnabled()) {
|
||||||
|
super.logger.warn(
|
||||||
|
"Could not obtain a Context to perform lookup");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object result = lc.lookup("java:comp/env/security/subject");
|
||||||
|
|
||||||
|
if (result instanceof Subject) {
|
||||||
|
subject = (Subject) result;
|
||||||
|
}
|
||||||
} catch (NamingException ne) {
|
} catch (NamingException ne) {
|
||||||
if (super.logger.isDebugEnabled()) {
|
if (super.logger.isWarnEnabled()) {
|
||||||
super.logger.warn("Lookup on Subject failed "
|
super.logger.warn("Lookup on Subject failed "
|
||||||
+ ne.getLocalizedMessage());
|
+ ne.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
@ -63,10 +78,16 @@ public class JbossIntegrationFilter extends AbstractIntegrationFilter {
|
|||||||
while (principals.hasNext()) {
|
while (principals.hasNext()) {
|
||||||
Principal p = (Principal) principals.next();
|
Principal p = (Principal) principals.next();
|
||||||
|
|
||||||
|
if (p == null) {
|
||||||
|
if (super.logger.isDebugEnabled()) {
|
||||||
|
super.logger.debug("Found null Principal in container");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (super.logger.isDebugEnabled()) {
|
if (super.logger.isDebugEnabled()) {
|
||||||
super.logger.debug("Found Principal in container ("
|
super.logger.debug("Found Principal in container ("
|
||||||
+ p.getClass().getName() + ") : " + p.getName());
|
+ p.getClass().getName() + ") : " + p.getName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (p instanceof Authentication) {
|
if (p instanceof Authentication) {
|
||||||
return p;
|
return p;
|
||||||
@ -76,4 +97,15 @@ public class JbossIntegrationFilter extends AbstractIntegrationFilter {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provided so that unit tests can override.
|
||||||
|
*
|
||||||
|
* @return a <code>Context</code> that can be used for lookup
|
||||||
|
*
|
||||||
|
* @throws NamingException DOCUMENT ME!
|
||||||
|
*/
|
||||||
|
protected Context getLookupContext() throws NamingException {
|
||||||
|
return new InitialContext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user