Authz unit test and code cleanup
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / authz / impl / AuthzResource.java
index 2e95793..c248468 100644 (file)
@@ -7,9 +7,9 @@
  * * Licensed under the Apache License, Version 2.0 (the "License");\r
  * * you may not use this file except in compliance with the License.\r
  * * You may obtain a copy of the License at\r
- * * \r
+ * *\r
  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
+ * *\r
  *  * Unless required by applicable law or agreed to in writing, software\r
  * * distributed under the License is distributed on an "AS IS" BASIS,\r
  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
@@ -30,7 +30,6 @@ import java.util.regex.Pattern;
 /** Internal representation of an authorization resource (the entity to which access is being requested).  Consists\r
  * of a type and an identifier.   The constructor takes the request URI from an HTTP request and checks it against\r
  * patterns for the the different resource types.  In DR R1, there are four resource types:\r
- * <ul>\r
  * <li>the feeds collection resource, the target of POST requests to create a new feed and GET requests to list\r
  * the existing feeds.  This is the root resource for the DR provisioning system, and it has no explicit id.\r
  * </li>\r
@@ -44,57 +43,57 @@ import java.util.regex.Pattern;
  * <li>a subscription resource, the target of GET, PUT, and DELETE requests used to manage an existing subscription.\r
  * Each subscription has a unique subscription ID.\r
  * </li>\r
- * \r
+ *\r
  * @author J. F. Lucas\r
  *\r
  */\r
 public class AuthzResource {\r
-       private ResourceType type = null;\r
-       private String id = "";\r
+    private ResourceType type = null;\r
+    private String id = "";\r
+\r
+    /* Construct an AuthzResource by matching a request URI against the various patterns */\r
+    AuthzResource(String requestUri) {\r
+        if (requestUri != null) {\r
+            for (ResourceType t : ResourceType.values()) {\r
+                Matcher m = t.getPattern().matcher(requestUri);\r
+                if (m.find(0)) {\r
+                    this.type = t;\r
+                    if (m.group("id") != null) {\r
+                        this.id = m.group("id");\r
+                    }\r
+                    break;\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    public ResourceType getType() {\r
+        return this.type;\r
+    }\r
+\r
+    public String getId() {\r
+        return this.id;\r
+    }\r
+\r
+    /* Enumeration that helps turn a request URI into something more useful for\r
+     * authorization purposes by given a type name and a pattern for determining if the URI\r
+     * represents that resource type.\r
+     * Highly dependent on the URL scheme, could be parameterized.\r
+     */\r
+    public enum ResourceType {\r
+        FEEDS_COLLECTION("((://[^/]+/)|(^/))(?<id>)$"),\r
+        SUBS_COLLECTION("((://[^/]+/)|(^/{0,1}))subscribe/(?<id>[^/]+)$"),\r
+        FEED("((://[^/]+/)|(^/{0,1}))feed/(?<id>[^/]+)$"),\r
+        SUB("((://[^/]+/)|(^/{0,1}))subs/(?<id>[^/]+)$");\r
+\r
+        private Pattern uriPattern;\r
+\r
+        ResourceType(String patternString) {\r
+            this.uriPattern = Pattern.compile(patternString);\r
+        }\r
 \r
-       /* Construct an AuthzResource by matching a request URI against the various patterns */\r
-       public AuthzResource(String rURI) {\r
-               if (rURI != null) {\r
-                       for (ResourceType t : ResourceType.values()) {\r
-                               Matcher m = t.getPattern().matcher(rURI);\r
-                               if (m.find(0)) {\r
-                                       this.type = t;\r
-                                       if (m.group("id") != null) {\r
-                                               this.id = m.group("id");\r
-                                       }\r
-                                       break;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       \r
-       public ResourceType getType() {\r
-               return this.type;\r
-       }\r
-       \r
-       public String getId() {\r
-               return this.id;\r
-       }\r
-       \r
-       /* Enumeration that helps turn a request URI into something more useful for\r
-        * authorization purposes by given a type name and a pattern for determining if the URI\r
-        * represents that resource type.\r
-        * Highly dependent on the URL scheme, could be parameterized.\r
-        */\r
-       public enum ResourceType { \r
-               FEEDS_COLLECTION("((://[^/]+/)|(^/))(?<id>)$"), \r
-               SUBS_COLLECTION ("((://[^/]+/)|(^/{0,1}))subscribe/(?<id>[^/]+)$"),\r
-               FEED("((://[^/]+/)|(^/{0,1}))feed/(?<id>[^/]+)$"),\r
-               SUB("((://[^/]+/)|(^/{0,1}))subs/(?<id>[^/]+)$");\r
-               \r
-               private Pattern uriPattern;\r
-               \r
-               private ResourceType(String patternString) {\r
-                       this.uriPattern = Pattern.compile(patternString);\r
-               }\r
-               \r
-               Pattern getPattern() {\r
-                       return this.uriPattern;\r
-               }\r
-       }\r
+        Pattern getPattern() {\r
+            return this.uriPattern;\r
+        }\r
+    }\r
 }\r