You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2009/06/29 23:43:20 UTC

svn commit: r789456 - in /geronimo/specs/trunk/geronimo-jacc_1.1_spec/src: main/java/javax/security/jacc/HTTPMethodSpec.java test/java/javax/security/jacc/HTTPMethodSpecTest.java

Author: djencks
Date: Mon Jun 29 21:43:20 2009
New Revision: 789456

URL: http://svn.apache.org/viewvc?rev=789456&view=rev
Log:
GERONIMO-4721 represent 'all http methods' with '' rather than '\!' when computing the actions string in web permissions

Added:
    geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/HTTPMethodSpecTest.java   (with props)
Modified:
    geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/HTTPMethodSpec.java

Modified: geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/HTTPMethodSpec.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/HTTPMethodSpec.java?rev=789456&r1=789455&r2=789456&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/HTTPMethodSpec.java (original)
+++ geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/HTTPMethodSpec.java Mon Jun 29 21:43:20 2009
@@ -25,10 +25,8 @@
 
 package javax.security.jacc;
 
-import java.util.List;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
+import java.util.Arrays;
 import java.util.regex.Pattern;
 
 
@@ -92,26 +90,28 @@
             if (isExcluded = name.charAt(0) == '!') {
                 name = name.substring(1);
             }
-            String[] methods = name.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])) {
-                        tmpMask |= HTTP_MASKS[j];
-                        found = true;
+            if (name.length() > 0) {
+                String[] methods = name.split(",", -1);
+                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])) {
+                            tmpMask |= HTTP_MASKS[j];
+                            found = true;
 
-                        break;
+                            break;
+                        }
                     }
-                }
-                if (!found) {
-                    checkToken(methods[i]);
-                    if (extensions == null) {
-                        extensions = new ArrayList<String>(methods.length);
+                    if (!found) {
+                        checkToken(methods[i]);
+                        if (extensions == null) {
+                            extensions = new ArrayList<String>(methods.length);
+                        }
+                        add(extensions, methods[i]);
                     }
-                    add(extensions, methods[i]);
                 }
             }
             this.mask = tmpMask;
@@ -223,20 +223,25 @@
 
 
     public boolean equals(HTTPMethodSpec o) {
-        return mask == o.mask && transport == o.transport;
+        return mask == o.mask && transport == o.transport && Arrays.equals(extensionMethods, o.extensionMethods);
     }
 
     public String getActions() {
         if (actions == null) {
-            if (isAllWebResources()) {
-                actions = "";
+            StringBuilder buffer;
+            if (isAllHttpActions()) {
+                if (hasTransportGuarantee()) {
+                    buffer = new StringBuilder();
+                } else {
+                    return "";
+                }
             } else {
-                boolean first = true;
-                StringBuilder buffer = new StringBuilder();
+                buffer = new StringBuilder();
                 if (isExcluded) {
                     buffer.append("!");
                 }
 
+                boolean first = true;
                 for (int i = 0; i < HTTP_MASKS.length; i++) {
                     if ((mask & HTTP_MASKS[i]) > 0) {
                         if (first) {
@@ -247,8 +252,7 @@
                         buffer.append(HTTP_METHODS[i]);
                     }
                 }
-                for (int i = 0; i < extensionMethods.length; i++) {
-                    String method = extensionMethods[i];
+                for (String method : extensionMethods) {
                     if (first) {
                         first = false;
                     } else {
@@ -256,21 +260,27 @@
                     }
                     buffer.append(method);
                 }
+            }
 
+            if (hasTransportGuarantee()) {
                 if (transport == INTEGRAL) {
                     buffer.append(":INTEGRAL");
                 } else if (transport == CONFIDENTIAL) {
                     buffer.append(":CONFIDENTIAL");
                 }
-
-                actions = buffer.toString();
             }
+
+            actions = buffer.toString();
         }
         return actions;
     }
 
-    private boolean isAllWebResources() {
-        return isExcluded && mask == 0x00 && transport == NA && extensionMethods.length == 0;
+    private boolean isAllHttpActions() {
+        return isExcluded && mask == 0x00 && extensionMethods.length == 0;
+    }
+
+    private boolean hasTransportGuarantee() {
+        return  !(transport == NA || transport == NONE);
     }
 
     public int hashCode() {

Added: geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/HTTPMethodSpecTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/HTTPMethodSpecTest.java?rev=789456&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/HTTPMethodSpecTest.java (added)
+++ geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/HTTPMethodSpecTest.java Mon Jun 29 21:43:20 2009
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package javax.security.jacc;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HTTPMethodSpecTest extends TestCase {
+    
+    public void testHTTPMethodSpec() throws Exception {
+        testHTTPMethodSpec(true);
+        testHTTPMethodSpec(false);
+        assertEquals("NONE", new HTTPMethodSpec("NONE", true).getActions());
+    }
+
+    public void testHTTPMethodSpec(boolean parseTransport) throws Exception {
+        assertEquals("", new HTTPMethodSpec(null, parseTransport).getActions());
+        assertEquals("", new HTTPMethodSpec("", parseTransport).getActions());
+        assertEquals("", new HTTPMethodSpec("!", parseTransport).getActions());
+        assertEquals("GET", new HTTPMethodSpec("GET", parseTransport).getActions());
+        assertEquals("GET,PUT", new HTTPMethodSpec("GET,PUT", parseTransport).getActions());
+        assertEquals("GET,PUT", new HTTPMethodSpec("PUT,GET", parseTransport).getActions());
+        assertEquals("FOO", new HTTPMethodSpec("FOO", parseTransport).getActions());
+        assertEquals("!GET", new HTTPMethodSpec("!GET", parseTransport).getActions());
+        assertEquals("!FOO", new HTTPMethodSpec("!FOO", parseTransport).getActions());
+        assertEquals("!GET,PUT", new HTTPMethodSpec("!PUT,GET", parseTransport).getActions());
+    }
+}

Propchange: geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/HTTPMethodSpecTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/HTTPMethodSpecTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/HTTPMethodSpecTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain