User: starksm
Date: 01/06/12 13:02:31
Modified: tomcat/src/main/org/jboss/tomcat/security
JBossSecurityMgrRealm.java
Log:
Handle authentication callback when there is no JBoss security context
Revision Changes Path
1.3 +41 -10
contrib/tomcat/src/main/org/jboss/tomcat/security/JBossSecurityMgrRealm.java
Index: JBossSecurityMgrRealm.java
===================================================================
RCS file:
/cvsroot/jboss/contrib/tomcat/src/main/org/jboss/tomcat/security/JBossSecurityMgrRealm.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JBossSecurityMgrRealm.java 2001/05/31 01:43:23 1.2
+++ JBossSecurityMgrRealm.java 2001/06/12 20:02:31 1.3
@@ -5,6 +5,7 @@
import java.util.Hashtable;
import java.util.HashSet;
import java.util.Set;
+import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.security.auth.Subject;
@@ -12,7 +13,6 @@
import org.apache.log4j.Category;
import org.apache.tomcat.core.BaseInterceptor;
-import org.apache.tomcat.core.Context;
import org.apache.tomcat.core.Request;
import org.apache.tomcat.core.Response;
import org.apache.tomcat.util.SecurityTools;
@@ -37,7 +37,7 @@
@see org.jboss.security.SubjectSecurityManager
@author [EMAIL PROTECTED]
-@version $Revision: 1.2 $
+@version $Revision: 1.3 $
*/
public class JBossSecurityMgrRealm extends BaseInterceptor
{
@@ -74,6 +74,11 @@
String username = (String) credentialMap.get("username");
String password = (String) credentialMap.get("password");
+ // If we don't have a security context security is not required
+ Context securityCtx = getSecurityContext();
+ if( securityCtx == null )
+ return 0;
+
/* Make sure the thread context class loader it set ot the servlet
class loader. The Jdk12Interceptor should be handling this but
it does not do it for the authenticate/authorize phases of a
@@ -92,14 +97,13 @@
if( scl != cl )
Thread.currentThread().setContextClassLoader(scl);
// Get the JBoss security manager from the ENC context
- InitialContext iniCtx = new InitialContext();
- EJBSecurityManager securityMgr = (EJBSecurityManager)
iniCtx.lookup("java:comp/env/security/securityMgr");
+ EJBSecurityManager securityMgr = (EJBSecurityManager)
securityCtx.lookup("securityMgr");
SimplePrincipal principal = new SimplePrincipal(username);
if( securityMgr.isValid(principal, password) )
{
request.setRemoteUser(username);
request.setUserPrincipal(principal);
- Context ctx = request.getContext();
+ org.apache.tomcat.core.Context ctx = request.getContext();
if (ctx != null)
request.setAuthType(ctx.getAuthMethod());
category.debug("User: "+username+" is authenticated");
@@ -160,12 +164,23 @@
{
if( scl != cl )
Thread.currentThread().setContextClassLoader(scl);
- // Get the JBoss security manager from the ENC context
- InitialContext iniCtx = new InitialContext();
- RealmMapping securityMgr = (RealmMapping)
iniCtx.lookup("java:comp/env/security/realmMapping");
- SimplePrincipal principal = new SimplePrincipal(username);
+
+ boolean userHasRole = false;
Set requiredRoles = new HashSet(Arrays.asList(roles));
- if( securityMgr.doesUserHaveRole(principal, requiredRoles) )
+ // Get the JBoss security manager from the ENC context
+ Context securityCtx = getSecurityContext();
+ if( securityCtx != null )
+ {
+ RealmMapping securityMgr = (RealmMapping)
securityCtx.lookup("realmMapping");
+ SimplePrincipal principal = new SimplePrincipal(username);
+ userHasRole = securityMgr.doesUserHaveRole(principal,
requiredRoles);
+ }
+ else
+ {
+ category.warn("no security context available");
+ }
+
+ if( userHasRole )
{
// Need to get roles from the security mgr. Needs updated
interface...
String userRoles[] = {};
@@ -190,6 +205,22 @@
}
return code;
+ }
+
+ private Context getSecurityContext()
+ {
+ Context securityCtx = null;
+ // Get the JBoss security manager from the ENC context
+ try
+ {
+ InitialContext iniCtx = new InitialContext();
+ securityCtx = (Context) iniCtx.lookup("java:comp/env/security");
+ }
+ catch(NamingException e)
+ {
+ // Apparently there is no security context?
+ }
+ return securityCtx;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development