1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.lifecycle.model;
17
18 import org.kuali.rice.kim.api.identity.Person;
19 import org.kuali.rice.krad.uif.component.Component;
20 import org.kuali.rice.krad.uif.component.DataBinding;
21 import org.kuali.rice.krad.uif.container.Group;
22 import org.kuali.rice.krad.uif.element.Action;
23 import org.kuali.rice.krad.uif.field.ActionField;
24 import org.kuali.rice.krad.uif.field.DataField;
25 import org.kuali.rice.krad.uif.field.Field;
26 import org.kuali.rice.krad.uif.lifecycle.AbstractViewLifecycleTask;
27 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
28 import org.kuali.rice.krad.uif.lifecycle.ViewLifecyclePhase;
29 import org.kuali.rice.krad.uif.view.View;
30 import org.kuali.rice.krad.uif.view.ViewAuthorizer;
31 import org.kuali.rice.krad.uif.view.ViewModel;
32 import org.kuali.rice.krad.uif.view.ViewPresentationController;
33 import org.kuali.rice.krad.uif.widget.Widget;
34 import org.kuali.rice.krad.util.GlobalVariables;
35
36
37
38
39
40
41 public class ApplyAuthAndPresentationLogicTask extends AbstractViewLifecycleTask {
42
43
44
45
46
47
48 public ApplyAuthAndPresentationLogicTask(ViewLifecyclePhase phase) {
49 super(phase);
50 }
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 @Override
69 protected void performLifecycleTask() {
70 ViewModel model = (ViewModel) getPhase().getModel();
71 Component component = getPhase().getComponent();
72 View view = ViewLifecycle.getView();
73 ViewPresentationController presentationController = view.getPresentationController();
74 ViewAuthorizer authorizer = view.getAuthorizer();
75
76
77 if (GlobalVariables.getUserSession() == null) {
78 return;
79 }
80
81 Person user = GlobalVariables.getUserSession().getPerson();
82
83
84 if (!component.isRender()) {
85 return;
86 }
87
88
89 if (component instanceof View) {
90 if (!view.isReadOnly()) {
91 boolean canEditView = authorizer.canEditView(view, model, user);
92 if (canEditView) {
93 canEditView = presentationController.canEditView(view, model);
94 }
95 view.setReadOnly(!canEditView);
96 }
97 }
98
99
100 else if (component instanceof Group) {
101 Group group = (Group) component;
102
103
104 if (!group.isHidden()) {
105 boolean canViewGroup = authorizer.canViewGroup(view, model, group, group.getId(), user);
106 if (canViewGroup) {
107 canViewGroup = presentationController.canViewGroup(view, model, group, group.getId());
108 }
109 group.setHidden(!canViewGroup);
110 group.setRender(canViewGroup);
111 }
112
113
114 if (!group.isReadOnly()) {
115 boolean canEditGroup = authorizer.canEditGroup(view, model, group, group.getId(), user);
116 if (canEditGroup) {
117 canEditGroup = presentationController.canEditGroup(view, model, group, group.getId());
118 }
119 group.setReadOnly(!canEditGroup);
120 }
121 }
122
123
124 else if (component instanceof Field && !(component instanceof ActionField)) {
125 Field field = (Field) component;
126
127 String propertyName = null;
128 if (field instanceof DataBinding) {
129 propertyName = ((DataBinding) field).getPropertyName();
130 }
131
132
133 if (!field.isHidden()) {
134 boolean canViewField = authorizer.canViewField(view, model, field, propertyName, user);
135 if (canViewField) {
136 canViewField = presentationController.canViewField(view, model, field, propertyName);
137 }
138 field.setHidden(!canViewField);
139 field.setRender(canViewField);
140 }
141
142
143 if (!field.isReadOnly()) {
144
145 boolean canEditField = authorizer.canEditField(view, model, field, propertyName, user);
146 if (canEditField) {
147 canEditField = presentationController.canEditField(view, model, field, propertyName);
148 }
149 field.setReadOnly(!canEditField);
150 }
151
152
153 if ((field.getRequired() == null) || !field.getRequired().booleanValue()) {
154
155 presentationController.fieldIsRequired(view, model, field, propertyName);
156 }
157
158 if (field instanceof DataField) {
159 DataField dataField = (DataField) field;
160
161
162 boolean canUnmaskValue = authorizer.canUnmaskField(view, model, dataField, dataField.getPropertyName(),
163 user);
164 if (!canUnmaskValue) {
165 dataField.setApplyMask(true);
166 dataField.setMaskFormatter(dataField.getDataFieldSecurity().getAttributeSecurity().
167 getMaskFormatter());
168 } else {
169
170 boolean canPartiallyUnmaskValue = authorizer.canPartialUnmaskField(view, model, dataField,
171 dataField.getPropertyName(), user);
172 if (!canPartiallyUnmaskValue) {
173 dataField.setApplyMask(true);
174 dataField.setMaskFormatter(
175 dataField.getDataFieldSecurity().getAttributeSecurity().getPartialMaskFormatter());
176 }
177 }
178 }
179 }
180
181
182 else if (component instanceof ActionField || component instanceof Action) {
183 Action action = null;
184 if (component instanceof ActionField) {
185 action = ((ActionField) component).getAction();
186 } else {
187 action = (Action) component;
188 }
189
190 boolean canTakeAction = authorizer.canPerformAction(view, model, action, action.getActionEvent(),
191 action.getId(), user);
192 if (canTakeAction) {
193 canTakeAction = presentationController.canPerformAction(view, model, action, action.getActionEvent(),
194 action.getId());
195 }
196 action.setRender(canTakeAction);
197 }
198
199
200 else if (component instanceof Widget) {
201 Widget widget = (Widget) component;
202
203
204 if (!widget.isHidden()) {
205 boolean canViewWidget = authorizer.canViewWidget(view, model, widget, widget.getId(), user);
206 if (canViewWidget) {
207 canViewWidget = presentationController.canViewWidget(view, model, widget, widget.getId());
208 }
209 widget.setHidden(!canViewWidget);
210 widget.setRender(canViewWidget);
211 }
212
213
214 if (!widget.isReadOnly()) {
215 boolean canEditWidget = authorizer.canEditWidget(view, model, widget, widget.getId(), user);
216 if (canEditWidget) {
217 canEditWidget = presentationController.canEditWidget(view, model, widget, widget.getId());
218 }
219 widget.setReadOnly(!canEditWidget);
220 }
221 }
222 }
223
224 }