1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.role.service.impl; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.kew.exception.WorkflowException; |
20 | |
import org.kuali.rice.kew.service.WorkflowInfo; |
21 | |
import org.kuali.rice.kim.api.role.Role; |
22 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
23 | |
import org.kuali.rice.kim.framework.type.KimDelegationTypeService; |
24 | |
import org.kuali.rice.kim.framework.type.KimRoleTypeService; |
25 | |
import org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase; |
26 | |
import org.kuali.rice.kim.util.KimConstants; |
27 | |
|
28 | |
import java.util.ArrayList; |
29 | |
import java.util.List; |
30 | |
import java.util.Map; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class RouteLogDerivedRoleTypeServiceImpl extends KimDerivedRoleTypeServiceBase implements KimRoleTypeService, KimDelegationTypeService { |
38 | |
public static final String INITIATOR_ROLE_NAME = "Initiator"; |
39 | |
public static final String INITIATOR_OR_REVIEWER_ROLE_NAME = "Initiator or Reviewer"; |
40 | |
public static final String ROUTER_ROLE_NAME = "Router"; |
41 | |
|
42 | 0 | protected WorkflowInfo workflowInfo = new WorkflowInfo(); |
43 | |
|
44 | |
{ |
45 | |
|
46 | |
|
47 | |
|
48 | 0 | checkRequiredAttributes = true; |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
@Override |
62 | |
public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) { |
63 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
64 | 0 | List<RoleMembership> members = new ArrayList<RoleMembership>(); |
65 | 0 | if(qualification!=null && !qualification.isEmpty()){ |
66 | 0 | String documentId = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER); |
67 | 0 | if (StringUtils.isNotBlank(documentId)) { |
68 | |
try{ |
69 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)) { |
70 | 0 | String principalId = workflowInfo.getDocumentInitiatorPrincipalId(documentId); |
71 | 0 | RoleMembership roleMembership = RoleMembership.Builder.create(null,null,principalId, Role.PRINCIPAL_MEMBER_TYPE,null).build(); |
72 | 0 | members.add(roleMembership); |
73 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) { |
74 | 0 | List<String> ids = workflowInfo.getPrincipalIdsInRouteLog(documentId, true); |
75 | 0 | for ( String id : ids ) { |
76 | 0 | if ( StringUtils.isNotBlank(id) ) { |
77 | 0 | RoleMembership roleMembership = RoleMembership.Builder.create(null,null,id, Role.PRINCIPAL_MEMBER_TYPE,null).build(); |
78 | 0 | members.add(roleMembership ); |
79 | 0 | } |
80 | |
} |
81 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)) { |
82 | 0 | String principalId = workflowInfo.getDocumentRoutedByPrincipalId(documentId); |
83 | 0 | RoleMembership roleMembership = RoleMembership.Builder.create(null,null,principalId, Role.PRINCIPAL_MEMBER_TYPE,null).build(); |
84 | 0 | members.add(roleMembership); |
85 | |
} |
86 | 0 | } catch(WorkflowException wex){ |
87 | 0 | throw new RuntimeException( |
88 | |
"Error in getting principal Ids in route log for document id: "+ documentId +" :"+wex.getLocalizedMessage(),wex); |
89 | 0 | } |
90 | |
} |
91 | |
} |
92 | |
|
93 | 0 | return members; |
94 | |
} |
95 | |
|
96 | |
@Override |
97 | |
public boolean hasApplicationRole( |
98 | |
String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification){ |
99 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
100 | 0 | boolean isUserInRouteLog = false; |
101 | 0 | if(qualification!=null && !qualification.isEmpty()){ |
102 | 0 | String documentId = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER); |
103 | |
try { |
104 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)){ |
105 | 0 | isUserInRouteLog = principalId.equals(workflowInfo.getDocumentInitiatorPrincipalId(documentId)); |
106 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)){ |
107 | 0 | isUserInRouteLog = workflowInfo.isUserAuthenticatedByRouteLog(documentId, principalId, true); |
108 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)){ |
109 | 0 | isUserInRouteLog = principalId.equals(workflowInfo.getDocumentRoutedByPrincipalId(documentId)); |
110 | |
} |
111 | 0 | } catch (WorkflowException wex) { |
112 | 0 | throw new RuntimeException("Error in determining whether the principal Id: " + principalId + " is in route log " + |
113 | |
"for document id: " + documentId + " :"+wex.getLocalizedMessage(),wex); |
114 | 0 | } |
115 | |
} |
116 | 0 | return isUserInRouteLog; |
117 | |
} |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
@Override |
125 | |
public boolean shouldCacheRoleMembershipResults(String namespaceCode, |
126 | |
String roleName) { |
127 | 0 | return false; |
128 | |
} |
129 | |
} |