1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sec.service.impl;
17
18 import java.util.Map;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.ole.sec.SecConstants;
22 import org.kuali.ole.sec.service.AccessPermissionEvaluator;
23 import org.kuali.rice.kim.api.identity.Person;
24
25
26
27
28
29 public class AccessPermissionEvaluatorImpl implements AccessPermissionEvaluator {
30 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccessPermissionEvaluatorImpl.class);
31
32 protected String constraintCode;
33 protected String operatorCode;
34 protected String propertyValue;
35 protected Map<String, Object> otherKeyFieldValues;
36 protected Person person;
37 protected String[] matchValues;
38 protected boolean performEqualMatch;
39 protected boolean performLessThanMatch;
40 protected boolean performGreaterThanMatch;
41 protected boolean allowConstraint;
42 protected boolean notOperator;
43
44 public AccessPermissionEvaluatorImpl() {
45 super();
46
47 performEqualMatch = false;
48 performLessThanMatch = false;
49 performGreaterThanMatch = false;
50 allowConstraint = false;
51 notOperator = false;
52 }
53
54
55
56
57 public boolean valueIsAllowed(String value) {
58 boolean allowed = false;
59
60 initializeAfterPropsSet();
61
62 boolean match = false;
63 for (int i = 0; i < matchValues.length; i++) {
64 String matchValue = matchValues[i];
65
66 if (isMatch(matchValue, value)) {
67 match = true;
68 break;
69 }
70 }
71
72 if ((allowConstraint && notOperator) || (!allowConstraint && !notOperator)) {
73 allowed = !match;
74 }
75 else {
76 allowed = match;
77 }
78
79 return allowed;
80 }
81
82
83
84
85
86
87
88
89 protected boolean isMatch(String matchValue, String value) {
90 boolean match = false;
91
92 boolean performWildcardMatch = false;
93 if (StringUtils.contains(matchValue, SecConstants.SecurityValueSpecialCharacters.WILDCARD_CHARACTER)) {
94 matchValue = StringUtils.remove(matchValue, SecConstants.SecurityValueSpecialCharacters.WILDCARD_CHARACTER);
95 performWildcardMatch = true;
96 }
97
98 if (performEqualMatch) {
99 if (performWildcardMatch) {
100 match = value.startsWith(matchValue);
101 }
102 else {
103 match = value.equals(matchValue);
104 }
105 }
106
107 if (!match && performLessThanMatch) {
108 match = value.compareTo(matchValue) < 0;
109 }
110
111 if (!match && performGreaterThanMatch) {
112 match = value.compareTo(matchValue) > 0;
113 }
114
115 return match;
116 }
117
118
119
120
121 protected void initializeAfterPropsSet() {
122 if (StringUtils.contains(constraintCode, SecConstants.SecurityConstraintCodes.ALLOWED)) {
123 allowConstraint = true;
124 }
125
126 if (SecConstants.SecurityDefinitionOperatorCodes.EQUAL.equals(operatorCode) || SecConstants.SecurityDefinitionOperatorCodes.NOT_EQUAL.equals(operatorCode) || SecConstants.SecurityDefinitionOperatorCodes.LESS_THAN_EQUAL.equals(operatorCode)
127 || SecConstants.SecurityDefinitionOperatorCodes.GREATER_THAN_EQUAL.equals(operatorCode)) {
128 performEqualMatch = true;
129 }
130
131 if (SecConstants.SecurityDefinitionOperatorCodes.LESS_THAN.equals(operatorCode) || SecConstants.SecurityDefinitionOperatorCodes.LESS_THAN_EQUAL.equals(operatorCode)) {
132 performLessThanMatch = true;
133 }
134
135 if (SecConstants.SecurityDefinitionOperatorCodes.GREATER_THAN.equals(operatorCode) || SecConstants.SecurityDefinitionOperatorCodes.GREATER_THAN_EQUAL.equals(operatorCode)) {
136 performGreaterThanMatch = true;
137 }
138
139 if (SecConstants.SecurityDefinitionOperatorCodes.NOT_EQUAL.equals(operatorCode)) {
140 notOperator = true;
141 }
142
143 setMatchValues();
144 }
145
146
147
148
149 protected void setMatchValues() {
150 if (StringUtils.contains(propertyValue, SecConstants.SecurityValueSpecialCharacters.MULTI_VALUE_SEPERATION_CHARACTER)) {
151 matchValues = StringUtils.split(propertyValue, SecConstants.SecurityValueSpecialCharacters.MULTI_VALUE_SEPERATION_CHARACTER);
152 }
153 else {
154 matchValues = new String[1];
155 matchValues[0] = propertyValue;
156 }
157 }
158
159
160
161
162 public void setConstraintCode(String constraintCode) {
163 this.constraintCode = constraintCode;
164 }
165
166
167
168
169 public void setOperatorCode(String operatorCode) {
170 this.operatorCode = operatorCode;
171 }
172
173
174
175
176 public void setPropertyValue(String propertyValue) {
177 this.propertyValue = propertyValue;
178 }
179
180
181
182
183 public void setOtherKeyFieldValueMap(Map<String, Object> otherKeyFieldValues) {
184 this.otherKeyFieldValues = otherKeyFieldValues;
185 }
186
187
188
189
190 public void setPerson(Person person) {
191 this.person = person;
192 }
193
194 }