1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.rice.student.permission;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.junit.Test;
25 import org.kuali.rice.kew.service.WorkflowDocument;
26 import org.kuali.rice.kew.util.KEWConstants;
27 import org.kuali.rice.kim.bo.impl.KimAttributes;
28 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
29 import org.kuali.rice.kim.service.KIMServiceLocator;
30 import org.kuali.rice.kim.service.PermissionService;
31 import org.kuali.rice.student.StudentStandaloneTestBase;
32
33
34
35
36
37
38 public class BasicPermissionsTest extends StudentStandaloneTestBase {
39
40 protected static final String PERMISSIONS_NAME_OPEN_DOCUMENT = "Open Document";
41 protected static final String PERMISSIONS_NAME_COMMENT_ON_DOCUMENT = "Comment on Document";
42 protected static final String PERMISSIONS_NAME_EDIT_DOCUMENT = "Edit Document";
43
44 @Override
45 public void setUp() throws Exception {
46 super.setUp();
47 loadXmlFile("BasicPermissionsTestConfig.xml");
48 }
49
50 protected void verifyPermissions(String principalId, String documentId, Map<String,Boolean> existingPermissions) {
51 String permissionNamespace = "KS-LUM";
52 PermissionService permService = KIMServiceLocator.getPermissionService();
53 for (Map.Entry<String, Boolean> entry : existingPermissions.entrySet()) {
54 if ( (entry.getValue() != null) && (entry.getValue().booleanValue()) ) {
55 assertTrue("Principal Id '" + principalId + "' should have permission '" + entry.getKey() + "'", permService.isAuthorized(principalId, permissionNamespace, entry.getKey(), null, new AttributeSet(KimAttributes.DOCUMENT_NUMBER, ""+documentId)));
56 }
57 else {
58 assertFalse("Principal Id '" + principalId + "' should not have permission '" + entry.getKey() + "'", permService.isAuthorized(principalId, permissionNamespace, entry.getKey(), null, new AttributeSet(KimAttributes.DOCUMENT_NUMBER, ""+documentId)));
59 }
60 }
61 }
62
63 @Test public void testOpenPermission() throws Exception {
64 String documentTypeName = "BasicPermissionsTestDocument";
65 Map<String,Boolean> hasPermissionByPermissionName = new HashMap<String,Boolean>();
66
67 String principalId = "testuser1";
68 WorkflowDocument doc = new WorkflowDocument(principalId, documentTypeName);
69 doc.saveDocument("");
70
71
72 principalId = "testuser1";
73 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
74 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
75 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
76 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
77 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
78
79
80 doc.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_APPROVE_REQ, "", "testuser3", "", true);
81
82
83 principalId = "testuser2";
84 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
85 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.FALSE);
86 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
87 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
88 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
89
90
91 principalId = "testuser3";
92 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
93 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
94 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
95 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.TRUE);
96 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
97
98 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
99 doc.routeDocument("");
100
101
102 principalId = "testuser1";
103 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
104 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
105 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
106 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
107
108
109 principalId = "testuser3";
110 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
111 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
112 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
113 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
114
115
116 principalId = "fred";
117 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
118 assertTrue("Approval should be requested of user '" + principalId + "'", doc.isApprovalRequested());
119 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
120 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
121 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.TRUE);
122 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
123
124
125 principalId = "doug";
126 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
127 assertTrue("FYI should be requested of user '" + principalId + "'", doc.isFYIRequested());
128 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
129 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
130 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
131 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
132
133
134 principalId = "fred";
135 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
136 doc.approve("");
137
138
139 principalId = "fred";
140 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
141 assertFalse("Approval should be requested of user '" + principalId + "'", doc.isApprovalRequested());
142 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
143 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
144 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
145 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
146
147
148 principalId = "doug";
149 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
150 assertTrue("FYI should be requested of user '" + principalId + "'", doc.isFYIRequested());
151 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
152 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
153 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
154 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
155
156
157 principalId = "edna";
158 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
159 assertTrue("Acknowledge should be requested of user '" + principalId + "'", doc.isAcknowledgeRequested());
160 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
161 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
162 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
163 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
164
165
166 principalId = "fran";
167 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
168 doc.approve("");
169 principalId = "user1";
170 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
171 doc.approve("");
172
173
174 principalId = "edna";
175 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
176 assertTrue("", doc.stateIsProcessed());
177 assertTrue("Acknowledge should be requested of user '" + principalId + "'", doc.isAcknowledgeRequested());
178 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
179 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
180 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
181 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
182
183
184 doc.acknowledge("");
185
186
187 principalId = "edna";
188 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
189 assertTrue("Doc should be FINAL", doc.stateIsFinal());
190 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
191 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
192 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
193 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
194
195
196 principalId = "doug";
197 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
198 assertTrue("FYI should be requested of user '" + principalId + "'", doc.isFYIRequested());
199 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
200 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
201 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
202 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
203
204 }
205 }