geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r156133 - in geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc: HTTPMethodSpec.java URLPatternSpec.java WebResourcePermission.java WebUserDataPermission.java
Date Fri, 04 Mar 2005 05:31:44 GMT
Author: adc
Date: Thu Mar  3 21:31:41 2005
New Revision: 156133

URL: http://svn.apache.org/viewcvs?view=rev&rev=156133
Log:
Some efficiency improvements.

Modified:
    geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/HTTPMethodSpec.java
    geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/URLPatternSpec.java
    geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/WebResourcePermission.java
    geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/WebUserDataPermission.java

Modified: geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/HTTPMethodSpec.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/HTTPMethodSpec.java?view=diff&r1=156132&r2=156133
==============================================================================
--- geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/HTTPMethodSpec.java (original)
+++ geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/HTTPMethodSpec.java Thu Mar
 3 21:31:41 2005
@@ -23,59 +23,47 @@
 
 package javax.security.jacc;
 
-import javax.servlet.http.HttpServletRequest;
-
 
 /**
  * @version $Rev$ $Date$
  */
-class HTTPMethodSpec {
+final class HTTPMethodSpec {
 
     private final static String[] HTTP_METHODS = {"GET", "POST", "PUT", "DELETE", "HEAD",
"OPTIONS", "TRACE"};
     private final static int[] HTTP_MASKS = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40};
 
-    private final static int INTEGRAL = 0x01;
-    private final static int CONFIDENTIAL = 0x02;
-    private final static int NONE = INTEGRAL | CONFIDENTIAL;
+    final static int NA = 0x00;
+    final static int INTEGRAL = 0x01;
+    final static int CONFIDENTIAL = 0x02;
+    final static int NONE = INTEGRAL | CONFIDENTIAL;
 
-    private int mask;
-    private int transport;
+    private final int mask;
+    private final int transport;
     private String actions;
 
     public HTTPMethodSpec(String[] HTTPMethods) {
         this(HTTPMethods, null);
     }
 
-    public HTTPMethodSpec(HttpServletRequest request) {
-        for (int j = 0; j < HTTP_METHODS.length; j++) {
-            if (request.getMethod().equals(HTTP_METHODS[j])) {
-                mask = HTTP_MASKS[j];
-
-                break;
-            }
-        }
-
-        transport = request.isSecure() ? CONFIDENTIAL : NONE;
-    }
-
-    public HTTPMethodSpec(String name) {
+    public HTTPMethodSpec(String name, boolean parseTransportType) {
         if (name == null || name.length() == 0) {
-            mask = 0x7F;
-            transport = NONE;
+            this.mask = 0x7F;
+            this.transport = NONE;
         } else {
             String[] tokens = name.split(":", 2);
 
             if (tokens[0].length() == 0) {
-                mask = 0x7F;
+                this.mask = 0x7F;
             } else {
                 String[] methods = tokens[0].split(",", -1);
+                int tmpMask = 0;
 
                 for (int i = 0; i < methods.length; i++) {
                     boolean found = false;
 
                     for (int j = 0; j < HTTP_METHODS.length; j++) {
                         if (methods[i].equals(HTTP_METHODS[j])) {
-                            mask |= HTTP_MASKS[j];
+                            tmpMask |= HTTP_MASKS[j];
                             found = true;
 
                             break;
@@ -83,60 +71,82 @@
                     }
                     if (!found) throw new IllegalArgumentException("Invalid HTTPMethodSpec");
                 }
+                this.mask = tmpMask;
             }
 
             if (tokens.length == 2) {
+                if (!parseTransportType) throw new IllegalArgumentException("Invalid HTTPMethodSpec");
+
                 if (tokens[1].equals("NONE")) {
-                    transport = NONE;
+                    this.transport = NONE;
                 } else if (tokens[1].equals("INTEGRAL")) {
-                    transport = INTEGRAL;
+                    this.transport = INTEGRAL;
                 } else if (tokens[1].equals("CONFIDENTIAL")) {
-                    transport = CONFIDENTIAL;
+                    this.transport = CONFIDENTIAL;
                 } else {
                     throw new IllegalArgumentException("Invalid transportType: " + tokens[1]);
                 }
             } else {
-                transport = NONE;
+                if (parseTransportType)
+                    this.transport = NONE;
+                else
+                    this.transport = NA;
             }
         }
     }
 
-    public HTTPMethodSpec(String[] HTTPMethods, String transportType) {
-        boolean parseTransportType = transportType != null;
+    public HTTPMethodSpec(String[] HTTPMethods, String transport) {
+        boolean parseTransportType = transport != null;
 
         if (HTTPMethods == null || HTTPMethods.length == 0) {
-            mask = 0x7F;
+            this.mask = 0x7F;
         } else {
+            int tmpMask = 0;
+
             for (int i = 0; i < HTTPMethods.length; i++) {
-                boolean found = false;
 
                 for (int j = 0; j < HTTP_METHODS.length; j++) {
                     if (HTTPMethods[i].equals(HTTP_METHODS[j])) {
-                        mask |= HTTP_MASKS[j];
-                        found = true;
+                        tmpMask |= HTTP_MASKS[j];
 
                         break;
                     }
                 }
-                if (!found) throw new IllegalArgumentException("Invalid HTTPMethodSpec");
+                if (tmpMask == 0) throw new IllegalArgumentException("Invalid HTTPMethodSpec");
             }
+            this.mask = tmpMask;
         }
 
         if (parseTransportType) {
-            if (transportType.length() == 0 || transportType.equals("NONE")) {
-                transport = NONE;
-            } else if (transportType.equals("INTEGRAL")) {
-                transport = INTEGRAL;
-            } else if (transportType.equals("CONFIDENTIAL")) {
-                transport = CONFIDENTIAL;
+            if (transport.length() == 0 || transport.equals("NONE")) {
+                this.transport = NONE;
+            } else if (transport.equals("INTEGRAL")) {
+                this.transport = INTEGRAL;
+            } else if (transport.equals("CONFIDENTIAL")) {
+                this.transport = CONFIDENTIAL;
             } else {
-                throw new IllegalArgumentException("Invalid transportType");
+                throw new IllegalArgumentException("Invalid transport");
             }
         } else {
-            transport = NONE;
+            this.transport = NONE;
         }
     }
 
+    public HTTPMethodSpec(String singleMethod, int transport) {
+        int tmpMask = 0;
+
+        for (int j = 0; j < HTTP_METHODS.length; j++) {
+            if (HTTP_METHODS[j].equals(singleMethod)) {
+                tmpMask = HTTP_MASKS[j];
+
+                break;
+            }
+        }
+        if (tmpMask == 0) throw new IllegalArgumentException("Invalid HTTPMethodSpec");
+        this.mask = tmpMask;
+        this.transport = transport;
+    }
+
     public boolean equals(HTTPMethodSpec o) {
         return mask == o.mask && transport == o.transport;
     }
@@ -157,14 +167,12 @@
                 }
             }
 
-            if (transport != NONE) {
-                buffer.append(":");
-                if (transport == INTEGRAL) {
-                    buffer.append("INTEGRAL");
-                } else {
-                    buffer.append("CONFIDENTIAL");
-                }
+            if (transport == INTEGRAL) {
+                buffer.append(":INTEGRAL");
+            } else if (transport == CONFIDENTIAL) {
+                buffer.append(":CONFIDENTIAL");
             }
+
             actions = buffer.toString();
         }
         return actions;

Modified: geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/URLPatternSpec.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/URLPatternSpec.java?view=diff&r1=156132&r2=156133
==============================================================================
--- geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/URLPatternSpec.java (original)
+++ geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/URLPatternSpec.java Thu Mar
 3 21:31:41 2005
@@ -30,11 +30,11 @@
  *
  * @version $Rev$ $Date$
  */
-class URLPatternSpec {
+final class URLPatternSpec {
 
-    private String pattern;
-    private URLPattern first;
-    private LinkedList qualifiers = new LinkedList();
+    private final String pattern;
+    private final URLPattern first;
+    private final LinkedList qualifiers = new LinkedList();
 
     public URLPatternSpec(String name) {
         if (name == null) throw new java.lang.IllegalArgumentException("URLPatternSpec cannot
be null");

Modified: geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/WebResourcePermission.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/WebResourcePermission.java?view=diff&r1=156132&r2=156133
==============================================================================
--- geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/WebResourcePermission.java
(original)
+++ geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/WebResourcePermission.java
Thu Mar  3 21:31:41 2005
@@ -45,19 +45,14 @@
         super(request.getServletPath());
 
         urlPatternSpec = new URLPatternSpec(request.getServletPath());
-        httpMethodSpec = new HTTPMethodSpec(request);
+        httpMethodSpec = new HTTPMethodSpec(request.getMethod(), HTTPMethodSpec.NA);
     }
 
     public WebResourcePermission(String name, String actions) {
         super(name);
 
-        // we do this because we're resusing the HTTPMethodSpec, which allows ':'
-        if (actions.indexOf(':') != -1) {
-            throw new IllegalArgumentException("Transports not allowed in WebResourcePermission
httpMethodSpec");
-        }
-
         urlPatternSpec = new URLPatternSpec(name);
-        httpMethodSpec = new HTTPMethodSpec(actions);
+        httpMethodSpec = new HTTPMethodSpec(actions, false);
     }
 
     public WebResourcePermission(String urlPattern, String[] HTTPMethods) {
@@ -98,7 +93,7 @@
 
     private synchronized void readObject(ObjectInputStream in) throws IOException {
         urlPatternSpec = new URLPatternSpec(in.readUTF());
-        httpMethodSpec = new HTTPMethodSpec(in.readUTF());
+        httpMethodSpec = new HTTPMethodSpec(in.readUTF(), false);
     }
 
     private synchronized void writeObject(ObjectOutputStream out) throws IOException {

Modified: geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/WebUserDataPermission.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/WebUserDataPermission.java?view=diff&r1=156132&r2=156133
==============================================================================
--- geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/WebUserDataPermission.java
(original)
+++ geronimo/trunk/specs/j2ee-jacc/src/java/javax/security/jacc/WebUserDataPermission.java
Thu Mar  3 21:31:41 2005
@@ -67,14 +67,14 @@
         super(request.getServletPath());
 
         urlPatternSpec = new URLPatternSpec(request.getServletPath());
-        httpMethodSpec = new HTTPMethodSpec(request);
+        httpMethodSpec = new HTTPMethodSpec(request.getMethod(), request.isSecure()? HTTPMethodSpec.CONFIDENTIAL:
HTTPMethodSpec.NONE);
     }
 
     public WebUserDataPermission(String name, String actions) {
         super(name);
 
         urlPatternSpec = new URLPatternSpec(name);
-        httpMethodSpec = new HTTPMethodSpec(actions);
+        httpMethodSpec = new HTTPMethodSpec(actions, true);
     }
 
     public WebUserDataPermission(String urlPattern, String[] HTTPMethods, String transportType)
{
@@ -115,7 +115,7 @@
 
     private synchronized void readObject(ObjectInputStream in) throws IOException {
         urlPatternSpec = new URLPatternSpec(in.readUTF());
-        httpMethodSpec = new HTTPMethodSpec(in.readUTF());
+        httpMethodSpec = new HTTPMethodSpec(in.readUTF(), true);
     }
 
     private synchronized void writeObject(ObjectOutputStream out) throws IOException {



Mime
View raw message