1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.identity.service.impl; |
17 | |
|
18 | |
import org.apache.commons.logging.Log; |
19 | |
import org.apache.commons.logging.LogFactory; |
20 | |
import org.kuali.rice.core.exception.RiceRuntimeException; |
21 | |
import org.kuali.rice.kew.actionrequest.KimGroupRecipient; |
22 | |
import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient; |
23 | |
import org.kuali.rice.kew.actionrequest.Recipient; |
24 | |
import org.kuali.rice.kew.dto.EmplIdDTO; |
25 | |
import org.kuali.rice.kew.dto.NetworkIdDTO; |
26 | |
import org.kuali.rice.kew.dto.UserIdDTO; |
27 | |
import org.kuali.rice.kew.dto.WorkflowIdDTO; |
28 | |
import org.kuali.rice.kew.identity.service.IdentityHelperService; |
29 | |
import org.kuali.rice.kew.user.AuthenticationUserId; |
30 | |
import org.kuali.rice.kew.user.EmplId; |
31 | |
import org.kuali.rice.kew.user.UserId; |
32 | |
import org.kuali.rice.kew.user.WorkflowUserId; |
33 | |
import org.kuali.rice.kew.util.KEWConstants; |
34 | |
import org.kuali.rice.kew.workgroup.GroupId; |
35 | |
import org.kuali.rice.kew.workgroup.GroupNameId; |
36 | |
import org.kuali.rice.kew.workgroup.WorkflowGroupId; |
37 | |
import org.kuali.rice.kim.bo.Group; |
38 | |
import org.kuali.rice.kim.bo.Person; |
39 | |
import org.kuali.rice.kim.bo.entity.KimPrincipal; |
40 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class IdentityHelperServiceImpl implements IdentityHelperService { |
48 | |
|
49 | 0 | private static final Log logger = LogFactory.getLog(IdentityHelperServiceImpl.class); |
50 | |
|
51 | |
public String getIdForPrincipalName(String principalName) { |
52 | 0 | if (principalName == null) { |
53 | 0 | throw new IllegalArgumentException("Can't lookup a principal ID for a null principal name."); |
54 | |
} |
55 | 0 | KimPrincipal principal = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(principalName); |
56 | 0 | if (principal == null) { |
57 | 0 | throw new RiceRuntimeException("Given principal name of '" + principalName + "' was invalid. Failed to lookup a corresponding principal ID."); |
58 | |
} |
59 | 0 | return principal.getPrincipalId(); |
60 | |
} |
61 | |
|
62 | |
public void validatePrincipalId(String principalId) { |
63 | |
|
64 | 0 | getPrincipal(principalId); |
65 | 0 | } |
66 | |
|
67 | |
public String getIdForGroupName(String namespace, String groupName) { |
68 | 0 | Group group = KIMServiceLocator.getIdentityManagementService().getGroupByName(namespace, groupName); |
69 | 0 | if (group == null) { |
70 | 0 | throw new RiceRuntimeException("Given namespace of '" + namespace + "' and name of '" + groupName + "' was invalid. Failed to lookup a corresponding group ID."); |
71 | |
} |
72 | 0 | return group.getGroupId(); |
73 | |
} |
74 | |
|
75 | |
|
76 | |
public Recipient getPrincipalRecipient(String principalId) { |
77 | 0 | KimPrincipal principal = getPrincipal(principalId); |
78 | 0 | return new KimPrincipalRecipient(principal); |
79 | |
} |
80 | |
|
81 | |
public KimPrincipal getPrincipal(String principalId) { |
82 | 0 | KimPrincipal principal = KIMServiceLocator.getIdentityManagementService().getPrincipal(principalId); |
83 | 0 | if (principal == null) { |
84 | 0 | throw new RiceRuntimeException("Could not locate a principal with the given principalId of " + principalId); |
85 | |
} |
86 | 0 | return principal; |
87 | |
} |
88 | |
|
89 | |
public KimPrincipal getPrincipalByPrincipalName(String principalName) { |
90 | 0 | KimPrincipal principal = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(principalName); |
91 | 0 | if (principal == null) { |
92 | 0 | throw new RiceRuntimeException("Could not locate a principal with the given principalName of " + principalName); |
93 | |
} |
94 | 0 | return principal; |
95 | |
} |
96 | |
|
97 | |
public Group getGroupByName(String namespaceCode, String name) { |
98 | 0 | Group group = KIMServiceLocator.getIdentityManagementService().getGroupByName(namespaceCode, name); |
99 | 0 | if (group == null) { |
100 | 0 | throw new RiceRuntimeException("Could not locate a group with the given namspace of '" + namespaceCode + "' and group name of '" + name + "'"); |
101 | |
} |
102 | 0 | return group; |
103 | |
} |
104 | |
|
105 | |
public Person getPerson(String principalId) { |
106 | 0 | Person person = KIMServiceLocator.getPersonService().getPerson(principalId); |
107 | 0 | if (person == null) { |
108 | 0 | throw new RiceRuntimeException("Could not locate a person with the given principal id of " + principalId); |
109 | |
} |
110 | 0 | return person; |
111 | |
} |
112 | |
|
113 | |
public Person getPersonByPrincipalName(String principalName) { |
114 | 0 | Person person = KIMServiceLocator.getPersonService().getPersonByPrincipalName(principalName); |
115 | 0 | if (person == null) { |
116 | 0 | throw new RiceRuntimeException("Could not locate a person with the given principal name of " + principalName); |
117 | |
} |
118 | 0 | return person; |
119 | |
} |
120 | |
|
121 | |
public Person getPersonByEmployeeId(String employeeId) { |
122 | 0 | Person person = KIMServiceLocator.getPersonService().getPersonByEmployeeId(employeeId); |
123 | 0 | if (person == null) { |
124 | 0 | throw new RiceRuntimeException("Could not locate a person with the given employee id of " + employeeId); |
125 | |
} |
126 | 0 | return person; |
127 | |
} |
128 | |
|
129 | |
|
130 | |
public Group getGroup(String groupId) { |
131 | 0 | Group group = KIMServiceLocator.getIdentityManagementService().getGroup(groupId); |
132 | 0 | if (group == null) { |
133 | 0 | throw new RiceRuntimeException("Could not locate a group with the given groupId of " + groupId); |
134 | |
} |
135 | 0 | return group; |
136 | |
} |
137 | |
|
138 | |
public Group getGroup(GroupId groupId) { |
139 | 0 | if (groupId == null || groupId.isEmpty()) { |
140 | 0 | return null; |
141 | 0 | } else if (groupId instanceof WorkflowGroupId) { |
142 | 0 | return KIMServiceLocator.getIdentityManagementService().getGroup(""+((WorkflowGroupId)groupId).getGroupId()); |
143 | 0 | } else if (groupId instanceof GroupNameId) { |
144 | 0 | return KIMServiceLocator.getIdentityManagementService().getGroupByName(((GroupNameId)groupId).getNamespace(), ((GroupNameId)groupId).getNameId()); |
145 | |
} |
146 | 0 | throw new IllegalArgumentException("Invalid GroupId type was passed: " + groupId); |
147 | |
} |
148 | |
|
149 | |
public String getGroupId(GroupId groupId) { |
150 | 0 | if (groupId == null || groupId.isEmpty()) { |
151 | 0 | return null; |
152 | 0 | } else if (groupId instanceof WorkflowGroupId) { |
153 | 0 | return ((WorkflowGroupId)groupId).getGroupId().toString(); |
154 | 0 | } else if (groupId instanceof GroupNameId) { |
155 | 0 | Group group = getGroup(groupId); |
156 | 0 | return group.getGroupId(); |
157 | |
} |
158 | 0 | throw new IllegalArgumentException("Invalid GroupId type was passed: " + groupId); |
159 | |
} |
160 | |
|
161 | |
public KimPrincipal getPrincipal(UserId userId) { |
162 | 0 | if (userId == null) { |
163 | 0 | return null; |
164 | 0 | } else if (userId instanceof WorkflowUserId) { |
165 | 0 | String principalId = ((WorkflowUserId)userId).getWorkflowId(); |
166 | 0 | return KIMServiceLocator.getIdentityManagementService().getPrincipal(principalId); |
167 | 0 | } else if (userId instanceof AuthenticationUserId) { |
168 | 0 | String principalName = ((AuthenticationUserId)userId).getAuthenticationId(); |
169 | 0 | return KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(principalName); |
170 | 0 | } else if (userId instanceof EmplId) { |
171 | 0 | String employeeId = ((EmplId)userId).getEmplId(); |
172 | 0 | Person person = getPersonByEmployeeId(employeeId); |
173 | 0 | return getPrincipal(person.getPrincipalId()); |
174 | |
} |
175 | 0 | throw new IllegalArgumentException("Invalid UserIdDTO type was passed: " + userId); |
176 | |
} |
177 | |
|
178 | |
|
179 | |
public KimPrincipal getPrincipal(UserIdDTO userId) { |
180 | 0 | if (userId == null) { |
181 | 0 | return null; |
182 | 0 | } else if (userId instanceof WorkflowIdDTO) { |
183 | 0 | String principalId = ((WorkflowIdDTO)userId).getWorkflowId(); |
184 | 0 | return KIMServiceLocator.getIdentityManagementService().getPrincipal(principalId); |
185 | 0 | } else if (userId instanceof NetworkIdDTO) { |
186 | 0 | String principalName = ((NetworkIdDTO)userId).getNetworkId(); |
187 | 0 | return KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(principalName); |
188 | 0 | } else if (userId instanceof EmplIdDTO) { |
189 | 0 | String employeeId = ((EmplIdDTO)userId).getEmplId(); |
190 | 0 | Person person = getPersonByEmployeeId(employeeId); |
191 | 0 | return getPrincipal(person.getPrincipalId()); |
192 | |
} |
193 | 0 | throw new IllegalArgumentException("Invalid UserIdDTO type was passed: " + userId.getClass()); |
194 | |
} |
195 | |
|
196 | |
public Recipient getGroupRecipient(String groupId) { |
197 | 0 | Group group = KIMServiceLocator.getIdentityManagementService().getGroup(groupId); |
198 | 0 | return new KimGroupRecipient(group); |
199 | |
} |
200 | |
|
201 | |
public KimPrincipal getSystemPrincipal() { |
202 | 0 | return getPrincipalByPrincipalName(KEWConstants.SYSTEM_USER); |
203 | |
} |
204 | |
|
205 | |
} |