1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.authorization; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
20 | |
import org.kuali.rice.core.api.membership.MemberType; |
21 | |
import org.kuali.rice.kim.api.role.Role; |
22 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
23 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
24 | |
import org.kuali.rice.kim.api.common.assignee.Assignee; |
25 | |
import org.kuali.rice.kim.api.permission.PermissionService; |
26 | |
import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase; |
27 | |
|
28 | |
import java.util.ArrayList; |
29 | |
import java.util.HashMap; |
30 | |
import java.util.List; |
31 | |
import java.util.Map; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public class PermissionDerivedRoleTypeServiceImpl extends DerivedRoleTypeServiceBase { |
39 | |
|
40 | |
private static PermissionService permissionService; |
41 | |
private String permissionTemplateNamespace; |
42 | |
private String permissionTemplateName; |
43 | |
|
44 | |
|
45 | |
|
46 | |
public String getPermissionTemplateNamespace() { |
47 | 0 | return this.permissionTemplateNamespace; |
48 | |
} |
49 | |
|
50 | |
|
51 | |
|
52 | |
public void setPermissionTemplateNamespace(String permissionTemplateNamespace) { |
53 | 0 | this.permissionTemplateNamespace = permissionTemplateNamespace; |
54 | 0 | } |
55 | |
|
56 | |
|
57 | |
|
58 | |
public String getPermissionTemplateName() { |
59 | 0 | return this.permissionTemplateName; |
60 | |
} |
61 | |
|
62 | |
|
63 | |
|
64 | |
public void setPermissionTemplateName(String permissionTemplateName) { |
65 | 0 | this.permissionTemplateName = permissionTemplateName; |
66 | 0 | } |
67 | |
|
68 | |
protected List<Assignee> getPermissionAssignees(Map<String, String> qualification) { |
69 | 0 | return getPermissionService().getPermissionAssigneesByTemplateName(permissionTemplateNamespace, |
70 | |
permissionTemplateName, new HashMap<String, String>(qualification), new HashMap<String, String>( |
71 | |
qualification)); |
72 | |
} |
73 | |
|
74 | |
@Override |
75 | |
public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) { |
76 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
77 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
78 | |
} |
79 | |
|
80 | 0 | if (roleName == null) { |
81 | 0 | throw new RiceIllegalArgumentException("roleName was null"); |
82 | |
} |
83 | 0 | List<Assignee> permissionAssignees = getPermissionAssignees(qualification); |
84 | 0 | List<RoleMembership> members = new ArrayList<RoleMembership>(); |
85 | 0 | for (Assignee permissionAssigneeInfo : permissionAssignees) { |
86 | 0 | if (StringUtils.isNotBlank(permissionAssigneeInfo.getPrincipalId())) { |
87 | 0 | members.add(RoleMembership.Builder.create(null, null, permissionAssigneeInfo.getPrincipalId(), MemberType.PRINCIPAL, null).build()); |
88 | 0 | } else if (StringUtils.isNotBlank(permissionAssigneeInfo.getGroupId())) { |
89 | 0 | members.add(RoleMembership.Builder.create(null, null, permissionAssigneeInfo.getGroupId(), MemberType.GROUP, null).build()); |
90 | |
} |
91 | |
} |
92 | 0 | return members; |
93 | |
} |
94 | |
|
95 | |
|
96 | |
@Override |
97 | |
public boolean hasApplicationRole( |
98 | |
String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification){ |
99 | 0 | if (StringUtils.isBlank(principalId)) { |
100 | 0 | throw new RiceIllegalArgumentException("principalId was null or blank"); |
101 | |
} |
102 | |
|
103 | 0 | if (groupIds == null) { |
104 | 0 | throw new RiceIllegalArgumentException("groupIds was null or blank"); |
105 | |
} |
106 | |
|
107 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
108 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
109 | |
} |
110 | |
|
111 | 0 | if (StringUtils.isBlank(roleName)) { |
112 | 0 | throw new RiceIllegalArgumentException("roleName was null or blank"); |
113 | |
} |
114 | |
|
115 | 0 | if (qualification == null) { |
116 | 0 | throw new RiceIllegalArgumentException("qualification was null"); |
117 | |
} |
118 | |
|
119 | |
|
120 | 0 | return getPermissionService().isAuthorizedByTemplateName(principalId, permissionTemplateNamespace, permissionTemplateName, new HashMap<String, String>(qualification), new HashMap<String, String>(qualification)); |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
protected PermissionService getPermissionService() { |
127 | 0 | if (permissionService == null) { |
128 | 0 | permissionService = KimApiServiceLocator.getPermissionService(); |
129 | |
} |
130 | 0 | return permissionService; |
131 | |
} |
132 | |
|
133 | |
} |