01: package com.technoetic.xplanner.security.config;
02:
03: import com.technoetic.xplanner.security.SecurityHelper;
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 SecurityConstraint {
11: private ArrayList webResourceCollections = new ArrayList();
12: private ArrayList authConstraints = new ArrayList();
13: private String displayName;
14:
15: public void addWebResourceCollection(
16: WebResourceCollection collection) {
17: webResourceCollections.add(collection);
18: }
19:
20: public void addAuthConstraint(AuthConstraint authConstraint) {
21: authConstraints.add(authConstraint);
22: }
23:
24: public String getDisplayName() {
25: return displayName;
26: }
27:
28: public void setDisplayName(String displayName) {
29: this .displayName = displayName;
30: }
31:
32: public Collection getWebResourceCollection() {
33: return webResourceCollections;
34: }
35:
36: public Collection getAuthConstraints() {
37: return authConstraints;
38: }
39:
40: public boolean isApplicable(HttpServletRequest request) {
41: Iterator webResourceCollections = getWebResourceCollection()
42: .iterator();
43: while (webResourceCollections.hasNext()) {
44: WebResourceCollection webResourceCollection = (WebResourceCollection) webResourceCollections
45: .next();
46: if (webResourceCollection.matches(request)) {
47: return true;
48: }
49: }
50: return false;
51: }
52:
53: public boolean isAuthorized(HttpServletRequest request) {
54: Iterator authConstraints = getAuthConstraints().iterator();
55: while (authConstraints.hasNext()) {
56: AuthConstraint authConstraint = (AuthConstraint) authConstraints
57: .next();
58: Iterator roleNames = authConstraint.getRoleNames()
59: .iterator();
60: while (roleNames.hasNext()) {
61: String role = (String) roleNames.next();
62: if ((SecurityHelper.getSubject(request) != null && role
63: .equals("*"))
64: || SecurityHelper.isUserInRole(request, role)) {
65: return true;
66: }
67: }
68: }
69: return false;
70: }
71: }
|