[jboss-cvs] JBossAS SVN: r103448 - branches/JBPAPP_5_0_0_GA-JBPAPP-4044/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 12:29:01 EDT 2010


Author: mmoyses
Date: 2010-04-01 12:29:00 -0400 (Thu, 01 Apr 2010)
New Revision: 103448

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

Modified: branches/JBPAPP_5_0_0_GA-JBPAPP-4044/tomcat/src/main/org/jboss/web/tomcat/security/JBossWebRealm.java
===================================================================
--- branches/JBPAPP_5_0_0_GA-JBPAPP-4044/tomcat/src/main/org/jboss/web/tomcat/security/JBossWebRealm.java	2010-04-01 16:10:13 UTC (rev 103447)
+++ branches/JBPAPP_5_0_0_GA-JBPAPP-4044/tomcat/src/main/org/jboss/web/tomcat/security/JBossWebRealm.java	2010-04-01 16:29:00 UTC (rev 103448)
@@ -117,6 +117,11 @@
     */
    protected boolean ignoreBaseDecision = false;
    
+   /**
+    * Should we rely on RealmBase Authorization Check Alone?
+    */
+   protected boolean ignoreJBossAuthorization = false;
+
    protected static boolean securityManagerFallback = false;
    
    static
@@ -175,8 +180,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
    //************************************************************************* 
@@ -471,13 +485,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());
 
@@ -507,13 +524,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;
    }
 
    /**
@@ -530,6 +548,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
@@ -567,10 +588,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();
 
@@ -612,9 +633,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