[jboss-cvs] JBossAS SVN: r103433 - branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/security.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 1 10:40:08 EDT 2010


Author: mmoyses
Date: 2010-04-01 10:40:07 -0400 (Thu, 01 Apr 2010)
New Revision: 103433

Modified:
   branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/security/JBossWebRealm.java
Log:
JBPAPP-4044: flag to bypass jboss security authorization framework

Modified: branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/security/JBossWebRealm.java
===================================================================
--- branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/security/JBossWebRealm.java	2010-04-01 14:39:53 UTC (rev 103432)
+++ branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/security/JBossWebRealm.java	2010-04-01 14:40:07 UTC (rev 103433)
@@ -118,6 +118,11 @@
     */
    protected boolean ignoreBaseDecision = false;
    
+   /**
+    * Should we rely on RealmBase Authorization Check Alone?
+    */
+   protected boolean ignoreJBossAuthorization = false;
+   
    protected static boolean securityManagerFallback = false;
    
    static
@@ -176,8 +181,17 @@
    public void setIgnoreBaseDecision(boolean ignoreBaseDecision)
    {
       this.ignoreBaseDecision = ignoreBaseDecision;
+      if (ignoreBaseDecision && ignoreJBossAuthorization)
+    	 throw new RuntimeException("One of ignoreBaseDecision or ignoreJBossAuthorization should be false");
    }
 
+   public void setIgnoreJBossAuthorization(boolean ignoreJBossAuthz )
+   {
+	  this.ignoreJBossAuthorization = ignoreJBossAuthz;
+	  if (ignoreBaseDecision && ignoreJBossAuthorization)
+		 throw new RuntimeException("One of ignoreBaseDecision or ignoreJBossAuthorization should be false");
+   }
+   
    //*************************************************************************
    //   Realm.Authenticate Methods
    //************************************************************************* 
@@ -472,13 +486,16 @@
    public boolean hasResourcePermission(Request request, Response response, SecurityConstraint[] securityConstraints,
          org.apache.catalina.Context context) throws IOException
    {
-      boolean ok = false;
+      if (ignoreBaseDecision && ignoreJBossAuthorization)
+    	  throw new RuntimeException("One of ignoreBaseDecision or ignoreJBossAuthorization should be false");
+	  
+      boolean ok = ignoreJBossAuthorization ? true : false;
       boolean baseDecision = ignoreBaseDecision ? true : super.hasResourcePermission(request, response,
             securityConstraints, context);
 
       //By default, the authorization framework always returns PERMIT such that the
       //decision of the realm base holds.
-      if (baseDecision)
+      if (baseDecision && !ignoreJBossAuthorization)
       {
          Subject caller = this.establishSubjectContext(request.getPrincipal());
 
@@ -508,13 +525,14 @@
          ok = helper.checkResourcePermission(contextMap, request, response, caller, PolicyContext.getContextID(),
                requestURI(request));
       }
+      boolean finalDecision = baseDecision && ok;
       if (trace)
-         log.trace("hasResourcePerm:RealmBase says:" + baseDecision + "::Authz framework says:" + ok + ":final=" + ok);
-      if (ok == false)
+         log.trace("hasResourcePerm:RealmBase says:" + baseDecision + "::Authz framework says:" + ok + ":final=" + finalDecision);
+      if (!finalDecision)
       {
          response.sendError(HttpServletResponse.SC_FORBIDDEN, sm.getString("realmBase.forbidden"));
       }
-      return ok;
+      return finalDecision;
    }
 
    /**
@@ -531,6 +549,9 @@
     */
    public boolean hasRole(Principal principal, String role)
    {
+      if (ignoreBaseDecision && ignoreJBossAuthorization)
+    	  throw new RuntimeException("One of ignoreBaseDecision or ignoreJBossAuthorization should be false");
+	  
       String servletName = null;
       //WebProgrammaticAuthentication does not go through hasResourcePermission
       //and hence the activeRequest thread local may not be set
@@ -568,10 +589,10 @@
          }
       }
 
-      boolean authzDecision = false;
+      boolean authzDecision = ignoreJBossAuthorization ? true : false;
       boolean baseDecision = ignoreBaseDecision ? true : super.hasRole(principal, role);
 
-      if (baseDecision)
+      if (baseDecision && !ignoreJBossAuthorization)
       {
          SecurityContext sc = SecurityAssociationActions.getSecurityContext();
 
@@ -613,9 +634,12 @@
    public boolean hasUserDataPermission(Request request, Response response, SecurityConstraint[] constraints)
          throws IOException
    {
+      if (ignoreBaseDecision && ignoreJBossAuthorization)
+    	  throw new RuntimeException("One of ignoreBaseDecision or ignoreJBossAuthorization should be false"); 
+	   
       boolean ok = ignoreBaseDecision ? true : super.hasUserDataPermission(request, response, constraints);
       //If the realmbase check has passed, then we can go to authz framework
-      if (ok)
+      if (ok && !ignoreJBossAuthorization)
       {
          Principal requestPrincipal = request.getPrincipal();
          establishSubjectContext(requestPrincipal);




More information about the jboss-cvs-commits mailing list