1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.authorization;
17
18 import java.util.HashMap;
19 import java.util.HashSet;
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.rice.kns.datadictionary.mask.MaskFormatter;
25 import org.kuali.rice.kns.util.KNSConstants;
26 import org.kuali.rice.kns.web.ui.Field;
27
28 public class BusinessObjectRestrictionsBase implements
29 BusinessObjectRestrictions {
30 private Map<String, MaskFormatter> partiallyMaskedFields;
31 private Map<String, MaskFormatter> fullyMaskedFields;
32
33 protected Set<String> allRestrictedFields;
34
35 public BusinessObjectRestrictionsBase() {
36 clearAllRestrictions();
37 }
38
39 public boolean hasAnyFieldRestrictions() {
40 return !partiallyMaskedFields.isEmpty() || !fullyMaskedFields.isEmpty();
41 }
42
43 public boolean hasRestriction(String fieldName) {
44 return isPartiallyMaskedField(fieldName) || isFullyMaskedField(fieldName);
45 }
46
47 public void addFullyMaskedField(String fieldName,
48 MaskFormatter maskFormatter) {
49 fullyMaskedFields.put(fieldName, maskFormatter);
50 }
51
52 public void addPartiallyMaskedField(String fieldName,
53 MaskFormatter maskFormatter) {
54 partiallyMaskedFields.put(fieldName, maskFormatter);
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68 public FieldRestriction getFieldRestriction(String fieldName) {
69 if (hasRestriction(fieldName)) {
70 FieldRestriction fieldRestriction = null;
71 if (isPartiallyMaskedField(fieldName)) {
72 fieldRestriction = new FieldRestriction(fieldName,
73 Field.PARTIALLY_MASKED);
74 fieldRestriction.setMaskFormatter(partiallyMaskedFields
75 .get(normalizeFieldName(fieldName)));
76 }
77 if (isFullyMaskedField(fieldName)) {
78 fieldRestriction = new FieldRestriction(fieldName, Field.MASKED);
79 fieldRestriction.setMaskFormatter(fullyMaskedFields
80 .get(normalizeFieldName(fieldName)));
81 }
82 return fieldRestriction;
83 } else {
84 return new FieldRestriction(fieldName, Field.EDITABLE);
85 }
86 }
87
88 public void clearAllRestrictions() {
89 partiallyMaskedFields = new HashMap<String, MaskFormatter>();
90 fullyMaskedFields = new HashMap<String, MaskFormatter>();
91 allRestrictedFields = null;
92 }
93
94
95
96
97
98
99
100
101
102 protected String normalizeFieldName(String fieldName) {
103 return fieldName;
104 }
105
106 protected boolean isFullyMaskedField(String fieldName) {
107 String normalizedFieldName = normalizeFieldName(fieldName);
108 return fullyMaskedFields.containsKey(normalizedFieldName);
109 }
110
111 protected boolean isPartiallyMaskedField(String fieldName) {
112 String normalizedFieldName = normalizeFieldName(fieldName);
113 return partiallyMaskedFields.containsKey(normalizedFieldName);
114 }
115 }