+ 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