| 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.api.exception.RiceIllegalArgumentException; |
| 21 | |
import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient; |
| 22 | |
import org.kuali.rice.kew.actionrequest.Recipient; |
| 23 | |
import org.kuali.rice.kew.identity.PrincipalName; |
| 24 | |
import org.kuali.rice.kew.identity.service.IdentityHelperService; |
| 25 | |
import org.kuali.rice.kew.user.EmplId; |
| 26 | |
import org.kuali.rice.kew.user.UserId; |
| 27 | |
import org.kuali.rice.kew.user.WorkflowUserId; |
| 28 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 29 | |
import org.kuali.rice.kew.workgroup.GroupId; |
| 30 | |
import org.kuali.rice.kew.workgroup.GroupNameId; |
| 31 | |
import org.kuali.rice.kew.workgroup.WorkflowGroupId; |
| 32 | |
import org.kuali.rice.kim.api.group.Group; |
| 33 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
| 34 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
| 35 | |
import org.kuali.rice.kim.bo.Person; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | 0 | public class IdentityHelperServiceImpl implements IdentityHelperService { |
| 44 | |
|
| 45 | 0 | private static final Log logger = LogFactory.getLog(IdentityHelperServiceImpl.class); |
| 46 | |
|
| 47 | |
public String getIdForPrincipalName(String principalName) { |
| 48 | 0 | if (principalName == null) { |
| 49 | 0 | throw new RiceIllegalArgumentException("Can't lookup a principal ID for a null principal name."); |
| 50 | |
} |
| 51 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName); |
| 52 | 0 | if (principal == null) { |
| 53 | 0 | throw new RiceIllegalArgumentException("Given principal name of '" + principalName + "' was invalid. Failed to lookup a corresponding principal ID."); |
| 54 | |
} |
| 55 | 0 | return principal.getPrincipalId(); |
| 56 | |
} |
| 57 | |
|
| 58 | |
public void validatePrincipalId(String principalId) { |
| 59 | |
|
| 60 | 0 | getPrincipal(principalId); |
| 61 | 0 | } |
| 62 | |
|
| 63 | |
public String getIdForGroupName(String namespace, String groupName) { |
| 64 | 0 | Group group = KimApiServiceLocator.getGroupService().getGroupByName(namespace, groupName); |
| 65 | 0 | if (group == null) { |
| 66 | 0 | throw new RiceIllegalArgumentException("Given namespace of '" + namespace + "' and name of '" + groupName + "' was invalid. Failed to lookup a corresponding group ID."); |
| 67 | |
} |
| 68 | 0 | return group.getId(); |
| 69 | |
} |
| 70 | |
|
| 71 | |
|
| 72 | |
public Recipient getPrincipalRecipient(String principalId) { |
| 73 | 0 | Principal principal = getPrincipal(principalId); |
| 74 | 0 | return new KimPrincipalRecipient(principal); |
| 75 | |
} |
| 76 | |
|
| 77 | |
public Principal getPrincipal(String principalId) { |
| 78 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId); |
| 79 | 0 | if (principal == null) { |
| 80 | 0 | throw new RiceIllegalArgumentException("Could not locate a principal with the given principalId of " + principalId); |
| 81 | |
} |
| 82 | 0 | return principal; |
| 83 | |
} |
| 84 | |
|
| 85 | |
public Principal getPrincipalByPrincipalName(String principalName) { |
| 86 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName); |
| 87 | 0 | if (principal == null) { |
| 88 | 0 | throw new RiceIllegalArgumentException("Could not locate a principal with the given principalName of " + principalName); |
| 89 | |
} |
| 90 | 0 | return principal; |
| 91 | |
} |
| 92 | |
|
| 93 | |
public Group getGroupByName(String namespaceCode, String name) { |
| 94 | 0 | Group group = KimApiServiceLocator.getGroupService().getGroupByName(namespaceCode, name); |
| 95 | 0 | if (group == null) { |
| 96 | 0 | throw new RiceIllegalArgumentException("Could not locate a group with the given namspace of '" + namespaceCode + "' and group name of '" + name + "'"); |
| 97 | |
} |
| 98 | 0 | return group; |
| 99 | |
} |
| 100 | |
|
| 101 | |
public Person getPerson(String principalId) { |
| 102 | 0 | Person person = KimApiServiceLocator.getPersonService().getPerson(principalId); |
| 103 | 0 | if (person == null) { |
| 104 | 0 | throw new RiceIllegalArgumentException("Could not locate a person with the given principal id of " + principalId); |
| 105 | |
} |
| 106 | 0 | return person; |
| 107 | |
} |
| 108 | |
|
| 109 | |
public Person getPersonByPrincipalName(String principalName) { |
| 110 | 0 | Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(principalName); |
| 111 | 0 | if (person == null) { |
| 112 | 0 | throw new RiceIllegalArgumentException("Could not locate a person with the given principal name of " + principalName); |
| 113 | |
} |
| 114 | 0 | return person; |
| 115 | |
} |
| 116 | |
|
| 117 | |
public Person getPersonByEmployeeId(String employeeId) { |
| 118 | 0 | Person person = KimApiServiceLocator.getPersonService().getPersonByEmployeeId(employeeId); |
| 119 | 0 | if (person == null) { |
| 120 | 0 | throw new RiceIllegalArgumentException("Could not locate a person with the given employee id of " + employeeId); |
| 121 | |
} |
| 122 | 0 | return person; |
| 123 | |
} |
| 124 | |
|
| 125 | |
|
| 126 | |
public Group getGroup(String groupId) { |
| 127 | 0 | Group group = KimApiServiceLocator.getGroupService().getGroup(groupId); |
| 128 | 0 | if (group == null) { |
| 129 | 0 | throw new RiceIllegalArgumentException("Could not locate a group with the given groupId of " + groupId); |
| 130 | |
} |
| 131 | 0 | return group; |
| 132 | |
} |
| 133 | |
|
| 134 | |
public Group getGroup(GroupId groupId) { |
| 135 | 0 | if (groupId == null || groupId.isEmpty()) { |
| 136 | 0 | return null; |
| 137 | 0 | } else if (groupId instanceof WorkflowGroupId) { |
| 138 | 0 | return KimApiServiceLocator.getGroupService().getGroup(""+((WorkflowGroupId)groupId).getGroupId()); |
| 139 | 0 | } else if (groupId instanceof GroupNameId) { |
| 140 | 0 | return KimApiServiceLocator.getGroupService().getGroupByName(((GroupNameId)groupId).getNamespace(), ((GroupNameId)groupId).getNameId()); |
| 141 | |
} |
| 142 | 0 | throw new RiceIllegalArgumentException("Invalid GroupId type was passed: " + groupId); |
| 143 | |
} |
| 144 | |
|
| 145 | |
public Principal getPrincipal(UserId userId) { |
| 146 | 0 | if (userId == null) { |
| 147 | 0 | return null; |
| 148 | 0 | } else if (userId instanceof WorkflowUserId) { |
| 149 | 0 | String principalId = ((WorkflowUserId)userId).getWorkflowId(); |
| 150 | 0 | return KimApiServiceLocator.getIdentityService().getPrincipal(principalId); |
| 151 | 0 | } else if (userId instanceof PrincipalName) { |
| 152 | 0 | String principalName = ((PrincipalName)userId).getId(); |
| 153 | 0 | return KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName); |
| 154 | 0 | } else if (userId instanceof EmplId) { |
| 155 | 0 | String employeeId = ((EmplId)userId).getEmplId(); |
| 156 | 0 | Person person = getPersonByEmployeeId(employeeId); |
| 157 | 0 | return getPrincipal(person.getPrincipalId()); |
| 158 | |
} |
| 159 | 0 | throw new RiceIllegalArgumentException("Invalid UserIdDTO type was passed: " + userId); |
| 160 | |
} |
| 161 | |
|
| 162 | |
public Principal getSystemPrincipal() { |
| 163 | 0 | return getPrincipalByPrincipalName(KEWConstants.SYSTEM_USER); |
| 164 | |
} |
| 165 | |
|
| 166 | |
} |