1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.service.impl;
17
18 import java.sql.Timestamp;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.joda.time.DateTime;
26 import org.kuali.rice.core.api.criteria.CriteriaValue;
27 import org.kuali.rice.core.api.criteria.EqualPredicate;
28 import org.kuali.rice.core.api.criteria.Predicate;
29 import org.kuali.rice.core.api.criteria.QueryByCriteria;
30 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
31 import org.kuali.rice.kim.api.identity.IdentityService;
32 import org.kuali.rice.kim.api.identity.entity.Entity;
33 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
34 import org.kuali.rice.kim.api.identity.entity.EntityDefaultQueryResults;
35 import org.kuali.rice.kim.api.identity.principal.Principal;
36 import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences;
37 import org.kuali.rice.kim.dao.LdapPrincipalDao;
38 import org.kuali.rice.kim.impl.identity.IdentityServiceImpl;
39 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
40
41
42
43
44
45
46
47
48 public class LdapIdentityDelegateServiceImpl extends IdentityServiceImpl {
49 private LdapPrincipalDao principalDao;
50
51 @Override
52 public Entity getEntity(String entityId) {
53 if (StringUtils.isBlank(entityId)) {
54 throw new RiceIllegalArgumentException("entityId is blank");
55 }
56
57 Entity edsInfo = getPrincipalDao().getEntity(entityId);
58 if (edsInfo != null) {
59 return edsInfo;
60 } else {
61 return super.getEntity(entityId);
62 }
63 }
64
65
66
67
68 @Override
69 public Entity getEntityByPrincipalId(String principalId) {
70 if (StringUtils.isBlank(principalId)) {
71 throw new RiceIllegalArgumentException("principalId is blank");
72 }
73
74 Entity edsInfo = getPrincipalDao().getEntityByPrincipalId(principalId);
75 if (edsInfo != null) {
76 return edsInfo;
77 } else {
78 return super.getEntityByPrincipalId(principalId);
79 }
80 }
81
82 @Override
83 public Entity getEntityByPrincipalName(String principalName) {
84 if (StringUtils.isBlank(principalName)) {
85 throw new RiceIllegalArgumentException("principalName is blank");
86 }
87
88 final Entity edsInfo = getPrincipalDao().getEntityByPrincipalName(principalName);
89 if (edsInfo != null) {
90 return edsInfo;
91 } else {
92 return super.getEntityByPrincipalName(principalName);
93 }
94 }
95
96 @Override
97 public EntityDefault getEntityDefault(String entityId) {
98 if (StringUtils.isBlank(entityId)) {
99 throw new RiceIllegalArgumentException("entityId is blank");
100 }
101
102 EntityDefault edsInfo = getPrincipalDao().getEntityDefault(entityId);
103 if (edsInfo != null) {
104 return edsInfo;
105 }
106 else {
107 return super.getEntityDefault(entityId);
108 }
109 }
110
111 @Override
112 public EntityDefault getEntityDefaultByPrincipalId(String principalId) {
113 if (StringUtils.isBlank(principalId)) {
114 throw new RiceIllegalArgumentException("principalId is blank");
115 }
116
117 final EntityDefault retval = getPrincipalDao().getEntityDefaultByPrincipalId(principalId);
118 if (retval != null) {
119 return retval;
120 }
121 else {
122 return super.getEntityDefaultByPrincipalId(principalId);
123 }
124 }
125
126 @Override
127 public EntityDefault getEntityDefaultByPrincipalName(String principalName) {
128 if (StringUtils.isBlank(principalName)) {
129 throw new RiceIllegalArgumentException("principalName is blank");
130 }
131
132 final EntityDefault retval = getPrincipalDao().getEntityDefaultByPrincipalName(principalName);
133 if (retval != null) {
134 return retval;
135 }
136 else {
137 return super.getEntityDefaultByPrincipalName(principalName);
138 }
139 }
140
141
142 private static <U extends CriteriaValue<?>> Object getVal(U toConv) {
143 Object o = toConv.getValue();
144 if (o instanceof DateTime) {
145 return new Timestamp(((DateTime) o).getMillis());
146 }
147 return o;
148 }
149
150
151
152
153
154
155 @Override
156 @Deprecated
157 public Principal getPrincipalByPrincipalNameAndPassword(String principalName, String password) {
158 if (StringUtils.isBlank(principalName)) {
159 throw new RiceIllegalArgumentException("principalName is blank");
160 }
161
162
163
164 return getPrincipalByPrincipalName(principalName);
165 }
166
167 @Override
168 public EntityPrivacyPreferences getEntityPrivacyPreferences(String entityId) {
169 if (StringUtils.isBlank(entityId)) {
170 throw new RiceIllegalArgumentException("entityId is blank");
171 }
172
173 return getPrincipalDao().getEntityPrivacyPreferences(entityId);
174 }
175
176 @Override
177 public Principal getPrincipal(String principalId) {
178 if (StringUtils.isBlank(principalId)) {
179 throw new RiceIllegalArgumentException("principalId is blank");
180 }
181
182 final Principal edsInfo = getPrincipalDao().getPrincipal(principalId);
183 if (edsInfo != null) {
184 return edsInfo;
185 } else {
186 return super.getPrincipal(principalId);
187 }
188 }
189
190 @Override
191 public Principal getPrincipalByPrincipalName(String principalName) {
192 if (StringUtils.isBlank(principalName)) {
193 throw new RiceIllegalArgumentException("principalName is blank");
194 }
195
196 final Principal edsInfo = getPrincipalDao().getPrincipalByName(principalName);
197 if (edsInfo != null) {
198 return edsInfo;
199 } else {
200 return super.getPrincipalByPrincipalName(principalName);
201 }
202 }
203
204 public void setPrincipalDao(LdapPrincipalDao principalDao) {
205 this.principalDao = principalDao;
206 }
207
208 public LdapPrincipalDao getPrincipalDao() {
209 return principalDao;
210 }
211 }