01: package com.technoetic.xplanner.security.config;
02:
03: import org.apache.commons.lang.StringUtils;
04:
05: import javax.servlet.http.HttpServletRequest;
06: import java.util.ArrayList;
07: import java.util.Collection;
08: import java.util.Iterator;
09:
10: public class WebResourceCollection {
11: private ArrayList urlPatterns = new ArrayList();
12: private String name;
13:
14: public void addUrlPattern(String pattern) {
15: urlPatterns.add(pattern);
16: }
17:
18: public Collection getUrlPatterns() {
19: return urlPatterns;
20: }
21:
22: public String getName() {
23: return name;
24: }
25:
26: public void setName(String name) {
27: this .name = name;
28: }
29:
30: public boolean matches(HttpServletRequest request) {
31: Iterator urlPatterns = getUrlPatterns().iterator();
32: while (urlPatterns.hasNext()) {
33: String urlPattern = (String) urlPatterns.next();
34: if (isMatchingPathInfo(request, urlPattern)) {
35: return true;
36: }
37: }
38: return false;
39: }
40:
41: private boolean isMatchingPathInfo(HttpServletRequest request,
42: String urlPattern) {
43: String path = request.getServletPath()
44: + (request.getPathInfo() == null ? "" : request
45: .getPathInfo());
46: return (urlPattern.equals("/") && (path.equals("/")))
47: || (urlPattern.length() > 2
48: && urlPattern.startsWith("*.") && path != null && path
49: .endsWith(urlPattern.substring(2)))
50: || (urlPattern.endsWith("*") && path != null && path
51: .startsWith(urlPattern.substring(0, urlPattern
52: .length() - 1)))
53: || (StringUtils.equals(urlPattern, path));
54: }
55:
56: }
|