--- /dev/null
+/*******************************************************************************\r
+ * ============LICENSE_START==================================================\r
+ * * org.onap.dmaap\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * ===========================================================================\r
+ * * 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
+ * * http://www.apache.org/licenses/LICENSE-2.0\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
+ * * See the License for the specific language governing permissions and\r
+ * * limitations under the License.\r
+ * * ============LICENSE_END====================================================\r
+ * *\r
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+\r
+\r
+package org.onap.dmaap.datarouter.authz.impl;\r
+\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
+\r
+/** 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
+ * <li>a feed resource, the target of GET, PUT, and DELETE requests used to manage an existing feed. Each feed\r
+ * has a unique feed ID.\r
+ * </li>\r
+ * <li>a subscription collection resource, the target of POST requests to create a new subscription and GET requests\r
+ * to list the subscriptions for a feed. Each feed has a subscription collection, and the ID associated with a\r
+ * subscription collection is the ID of the feed.\r
+ * </li>\r
+ * <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
+ * @author J. F. Lucas\r
+ *\r
+ */\r
+public class AuthzResource {\r
+ private ResourceType type = null;\r
+ private String id = "";\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
+}\r