package frame.role; import java.util.HashSet; import java.util.Set; import frame.object.http.Path; import frame.util.Util; public class Role { private String name; private Set dataSet; private Set includeResources; private Set endsWithResource; private Set cachedAuthorization; public Role(String name) { this.name = name; dataSet = new HashSet(); includeResources = new HashSet(); endsWithResource = new HashSet(); cachedAuthorization = new HashSet(); } public boolean containsData(String data) { return dataSet.contains(data); } public boolean containsPath(Path path) { String uri = path.getURI(); if (cachedAuthorization.contains(uri)) { return true; } for (String include: includeResources) { if (uri.contains(include)) { return true; } } for (String endswidth: cachedAuthorization) { if (uri.endsWith(endswidth)) { return true; } } return false; } public void addResource(String resource) { if (Util.isEmptyStr(resource)) { return; } resource = resource.trim().toLowerCase(); if (resource.startsWith("/")) { } if (resource.endsWith("/*")) { resource = resource.subString(0, resource.length() - "/*".length()); includeResources.add(resource); return; } endsWithResource.add(resource); } @Override public String toString() { return "Role [name=" + name + "]"; } }