View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.persistence.jpa.entity;
20  
21  import org.apache.syncope.core.persistence.api.dao.AnySearchDAO;
22  import org.apache.syncope.core.persistence.api.entity.AccessToken;
23  import org.apache.syncope.core.persistence.api.entity.AnyAbout;
24  import org.apache.syncope.core.persistence.api.entity.AnyTemplateRealm;
25  import org.apache.syncope.core.persistence.api.entity.AnyType;
26  import org.apache.syncope.core.persistence.api.entity.AnyTypeClass;
27  import org.apache.syncope.core.persistence.api.entity.Application;
28  import org.apache.syncope.core.persistence.api.entity.AuditConf;
29  import org.apache.syncope.core.persistence.api.entity.Batch;
30  import org.apache.syncope.core.persistence.api.entity.ConnInstance;
31  import org.apache.syncope.core.persistence.api.entity.ConnPoolConf;
32  import org.apache.syncope.core.persistence.api.entity.Delegation;
33  import org.apache.syncope.core.persistence.api.entity.DerSchema;
34  import org.apache.syncope.core.persistence.api.entity.DynRealm;
35  import org.apache.syncope.core.persistence.api.entity.DynRealmMembership;
36  import org.apache.syncope.core.persistence.api.entity.Entity;
37  import org.apache.syncope.core.persistence.api.entity.EntityFactory;
38  import org.apache.syncope.core.persistence.api.entity.ExternalResource;
39  import org.apache.syncope.core.persistence.api.entity.FIQLQuery;
40  import org.apache.syncope.core.persistence.api.entity.Implementation;
41  import org.apache.syncope.core.persistence.api.entity.JobStatus;
42  import org.apache.syncope.core.persistence.api.entity.MailTemplate;
43  import org.apache.syncope.core.persistence.api.entity.Notification;
44  import org.apache.syncope.core.persistence.api.entity.PlainSchema;
45  import org.apache.syncope.core.persistence.api.entity.Privilege;
46  import org.apache.syncope.core.persistence.api.entity.Realm;
47  import org.apache.syncope.core.persistence.api.entity.RelationshipType;
48  import org.apache.syncope.core.persistence.api.entity.Remediation;
49  import org.apache.syncope.core.persistence.api.entity.Report;
50  import org.apache.syncope.core.persistence.api.entity.ReportExec;
51  import org.apache.syncope.core.persistence.api.entity.Role;
52  import org.apache.syncope.core.persistence.api.entity.SRARoute;
53  import org.apache.syncope.core.persistence.api.entity.VirSchema;
54  import org.apache.syncope.core.persistence.api.entity.am.AttrRepo;
55  import org.apache.syncope.core.persistence.api.entity.am.AuthModule;
56  import org.apache.syncope.core.persistence.api.entity.am.AuthProfile;
57  import org.apache.syncope.core.persistence.api.entity.am.CASSPClientApp;
58  import org.apache.syncope.core.persistence.api.entity.am.OIDCJWKS;
59  import org.apache.syncope.core.persistence.api.entity.am.OIDCRPClientApp;
60  import org.apache.syncope.core.persistence.api.entity.am.SAML2IdPEntity;
61  import org.apache.syncope.core.persistence.api.entity.am.SAML2SPClientApp;
62  import org.apache.syncope.core.persistence.api.entity.am.SAML2SPEntity;
63  import org.apache.syncope.core.persistence.api.entity.am.WAConfigEntry;
64  import org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership;
65  import org.apache.syncope.core.persistence.api.entity.anyobject.AMembership;
66  import org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttr;
67  import org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttrUniqueValue;
68  import org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttrValue;
69  import org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship;
70  import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
71  import org.apache.syncope.core.persistence.api.entity.group.GPlainAttr;
72  import org.apache.syncope.core.persistence.api.entity.group.GPlainAttrUniqueValue;
73  import org.apache.syncope.core.persistence.api.entity.group.GPlainAttrValue;
74  import org.apache.syncope.core.persistence.api.entity.group.Group;
75  import org.apache.syncope.core.persistence.api.entity.group.TypeExtension;
76  import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
77  import org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy;
78  import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
79  import org.apache.syncope.core.persistence.api.entity.policy.AuthPolicy;
80  import org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy;
81  import org.apache.syncope.core.persistence.api.entity.policy.PropagationPolicy;
82  import org.apache.syncope.core.persistence.api.entity.policy.PullCorrelationRuleEntity;
83  import org.apache.syncope.core.persistence.api.entity.policy.PullPolicy;
84  import org.apache.syncope.core.persistence.api.entity.policy.PushCorrelationRuleEntity;
85  import org.apache.syncope.core.persistence.api.entity.policy.PushPolicy;
86  import org.apache.syncope.core.persistence.api.entity.policy.TicketExpirationPolicy;
87  import org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask;
88  import org.apache.syncope.core.persistence.api.entity.task.MacroTask;
89  import org.apache.syncope.core.persistence.api.entity.task.NotificationTask;
90  import org.apache.syncope.core.persistence.api.entity.task.PropagationTask;
91  import org.apache.syncope.core.persistence.api.entity.task.PullTask;
92  import org.apache.syncope.core.persistence.api.entity.task.PushTask;
93  import org.apache.syncope.core.persistence.api.entity.task.SchedTask;
94  import org.apache.syncope.core.persistence.api.entity.user.DynRoleMembership;
95  import org.apache.syncope.core.persistence.api.entity.user.LAPlainAttr;
96  import org.apache.syncope.core.persistence.api.entity.user.LAPlainAttrUniqueValue;
97  import org.apache.syncope.core.persistence.api.entity.user.LAPlainAttrValue;
98  import org.apache.syncope.core.persistence.api.entity.user.LinkedAccount;
99  import org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion;
100 import org.apache.syncope.core.persistence.api.entity.user.UDynGroupMembership;
101 import org.apache.syncope.core.persistence.api.entity.user.UMembership;
102 import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr;
103 import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrUniqueValue;
104 import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue;
105 import org.apache.syncope.core.persistence.api.entity.user.URelationship;
106 import org.apache.syncope.core.persistence.api.entity.user.User;
107 import org.apache.syncope.core.persistence.jpa.dao.JPAAnySearchDAO;
108 import org.apache.syncope.core.persistence.jpa.entity.am.JPAAttrRepo;
109 import org.apache.syncope.core.persistence.jpa.entity.am.JPAAuthModule;
110 import org.apache.syncope.core.persistence.jpa.entity.am.JPAAuthProfile;
111 import org.apache.syncope.core.persistence.jpa.entity.am.JPACASSPClientApp;
112 import org.apache.syncope.core.persistence.jpa.entity.am.JPAOIDCJWKS;
113 import org.apache.syncope.core.persistence.jpa.entity.am.JPAOIDCRPClientApp;
114 import org.apache.syncope.core.persistence.jpa.entity.am.JPASAML2IdPEntity;
115 import org.apache.syncope.core.persistence.jpa.entity.am.JPASAML2SPClientApp;
116 import org.apache.syncope.core.persistence.jpa.entity.am.JPASAML2SPEntity;
117 import org.apache.syncope.core.persistence.jpa.entity.am.JPAWAConfigEntry;
118 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAADynGroupMembership;
119 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAMembership;
120 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttr;
121 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttrUniqueValue;
122 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttrValue;
123 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship;
124 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject;
125 import org.apache.syncope.core.persistence.jpa.entity.group.JPAGPlainAttr;
126 import org.apache.syncope.core.persistence.jpa.entity.group.JPAGPlainAttrUniqueValue;
127 import org.apache.syncope.core.persistence.jpa.entity.group.JPAGPlainAttrValue;
128 import org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup;
129 import org.apache.syncope.core.persistence.jpa.entity.group.JPATypeExtension;
130 import org.apache.syncope.core.persistence.jpa.entity.policy.JPAAccessPolicy;
131 import org.apache.syncope.core.persistence.jpa.entity.policy.JPAAccountPolicy;
132 import org.apache.syncope.core.persistence.jpa.entity.policy.JPAAttrReleasePolicy;
133 import org.apache.syncope.core.persistence.jpa.entity.policy.JPAAuthPolicy;
134 import org.apache.syncope.core.persistence.jpa.entity.policy.JPAPasswordPolicy;
135 import org.apache.syncope.core.persistence.jpa.entity.policy.JPAPropagationPolicy;
136 import org.apache.syncope.core.persistence.jpa.entity.policy.JPAPullCorrelationRuleEntity;
137 import org.apache.syncope.core.persistence.jpa.entity.policy.JPAPullPolicy;
138 import org.apache.syncope.core.persistence.jpa.entity.policy.JPAPushCorrelationRuleEntity;
139 import org.apache.syncope.core.persistence.jpa.entity.policy.JPAPushPolicy;
140 import org.apache.syncope.core.persistence.jpa.entity.policy.JPATicketExpirationPolicy;
141 import org.apache.syncope.core.persistence.jpa.entity.task.JPAAnyTemplatePullTask;
142 import org.apache.syncope.core.persistence.jpa.entity.task.JPAMacroTask;
143 import org.apache.syncope.core.persistence.jpa.entity.task.JPANotificationTask;
144 import org.apache.syncope.core.persistence.jpa.entity.task.JPAPropagationTask;
145 import org.apache.syncope.core.persistence.jpa.entity.task.JPAPullTask;
146 import org.apache.syncope.core.persistence.jpa.entity.task.JPAPushTask;
147 import org.apache.syncope.core.persistence.jpa.entity.task.JPASchedTask;
148 import org.apache.syncope.core.persistence.jpa.entity.user.JPADynRoleMembership;
149 import org.apache.syncope.core.persistence.jpa.entity.user.JPALAPlainAttr;
150 import org.apache.syncope.core.persistence.jpa.entity.user.JPALAPlainAttrUniqueValue;
151 import org.apache.syncope.core.persistence.jpa.entity.user.JPALAPlainAttrValue;
152 import org.apache.syncope.core.persistence.jpa.entity.user.JPALinkedAccount;
153 import org.apache.syncope.core.persistence.jpa.entity.user.JPASecurityQuestion;
154 import org.apache.syncope.core.persistence.jpa.entity.user.JPAUDynGroupMembership;
155 import org.apache.syncope.core.persistence.jpa.entity.user.JPAUMembership;
156 import org.apache.syncope.core.persistence.jpa.entity.user.JPAUPlainAttr;
157 import org.apache.syncope.core.persistence.jpa.entity.user.JPAUPlainAttrUniqueValue;
158 import org.apache.syncope.core.persistence.jpa.entity.user.JPAUPlainAttrValue;
159 import org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship;
160 import org.apache.syncope.core.persistence.jpa.entity.user.JPAUser;
161 import org.apache.syncope.core.spring.security.SecureRandomUtils;
162 
163 public class JPAEntityFactory implements EntityFactory {
164 
165     @SuppressWarnings("unchecked")
166     @Override
167     public <E extends Entity> E newEntity(final Class<E> reference) {
168         E result;
169 
170         if (reference.equals(Realm.class)) {
171             result = (E) new JPARealm();
172         } else if (reference.equals(DynRealm.class)) {
173             result = (E) new JPADynRealm();
174         } else if (reference.equals(DynRealmMembership.class)) {
175             result = (E) new JPADynRealmMembership();
176         } else if (reference.equals(AnyTemplateRealm.class)) {
177             result = (E) new JPAAnyTemplateRealm();
178         } else if (reference.equals(AccountPolicy.class)) {
179             result = (E) new JPAAccountPolicy();
180         } else if (reference.equals(PasswordPolicy.class)) {
181             result = (E) new JPAPasswordPolicy();
182         } else if (reference.equals(PropagationPolicy.class)) {
183             result = (E) new JPAPropagationPolicy();
184         } else if (reference.equals(PushPolicy.class)) {
185             result = (E) new JPAPushPolicy();
186         } else if (reference.equals(PullPolicy.class)) {
187             result = (E) new JPAPullPolicy();
188         } else if (reference.equals(PullCorrelationRuleEntity.class)) {
189             result = (E) new JPAPullCorrelationRuleEntity();
190         } else if (reference.equals(PushCorrelationRuleEntity.class)) {
191             result = (E) new JPAPushCorrelationRuleEntity();
192         } else if (reference.equals(AnyTypeClass.class)) {
193             result = (E) new JPAAnyTypeClass();
194         } else if (reference.equals(AnyType.class)) {
195             result = (E) new JPAAnyType();
196         } else if (reference.equals(AnyObject.class)) {
197             result = (E) new JPAAnyObject();
198         } else if (reference.equals(Role.class)) {
199             result = (E) new JPARole();
200         } else if (reference.equals(Application.class)) {
201             result = (E) new JPAApplication();
202         } else if (reference.equals(Privilege.class)) {
203             result = (E) new JPAPrivilege();
204         } else if (reference.equals(User.class)) {
205             result = (E) new JPAUser();
206         } else if (reference.equals(Group.class)) {
207             result = (E) new JPAGroup();
208         } else if (reference.equals(TypeExtension.class)) {
209             result = (E) new JPATypeExtension();
210         } else if (reference.equals(RelationshipType.class)) {
211             result = (E) new JPARelationshipType();
212         } else if (reference.equals(ARelationship.class)) {
213             result = (E) new JPAARelationship();
214         } else if (reference.equals(URelationship.class)) {
215             result = (E) new JPAURelationship();
216         } else if (reference.equals(AMembership.class)) {
217             result = (E) new JPAAMembership();
218         } else if (reference.equals(UMembership.class)) {
219             result = (E) new JPAUMembership();
220         } else if (reference.equals(LinkedAccount.class)) {
221             result = (E) new JPALinkedAccount();
222         } else if (reference.equals(AnyAbout.class)) {
223             result = (E) new JPAAnyAbout();
224         } else if (reference.equals(MailTemplate.class)) {
225             result = (E) new JPAMailTemplate();
226         } else if (reference.equals(Notification.class)) {
227             result = (E) new JPANotification();
228         } else if (reference.equals(ConnInstance.class)) {
229             result = (E) new JPAConnInstance();
230         } else if (reference.equals(ExternalResource.class)) {
231             result = (E) new JPAExternalResource();
232         } else if (reference.equals(PlainSchema.class)) {
233             result = (E) new JPAPlainSchema();
234         } else if (reference.equals(APlainAttr.class)) {
235             result = (E) new JPAAPlainAttr();
236         } else if (reference.equals(APlainAttrValue.class)) {
237             result = (E) new JPAAPlainAttrValue();
238         } else if (reference.equals(APlainAttrUniqueValue.class)) {
239             result = (E) new JPAAPlainAttrUniqueValue();
240         } else if (reference.equals(UPlainAttr.class)) {
241             result = (E) new JPAUPlainAttr();
242         } else if (reference.equals(UPlainAttrValue.class)) {
243             result = (E) new JPAUPlainAttrValue();
244         } else if (reference.equals(UPlainAttrUniqueValue.class)) {
245             result = (E) new JPAUPlainAttrUniqueValue();
246         } else if (reference.equals(LAPlainAttr.class)) {
247             result = (E) new JPALAPlainAttr();
248         } else if (reference.equals(LAPlainAttrValue.class)) {
249             result = (E) new JPALAPlainAttrValue();
250         } else if (reference.equals(LAPlainAttrUniqueValue.class)) {
251             result = (E) new JPALAPlainAttrUniqueValue();
252         } else if (reference.equals(DerSchema.class)) {
253             result = (E) new JPADerSchema();
254         } else if (reference.equals(VirSchema.class)) {
255             result = (E) new JPAVirSchema();
256         } else if (reference.equals(GPlainAttr.class)) {
257             result = (E) new JPAGPlainAttr();
258         } else if (reference.equals(GPlainAttrValue.class)) {
259             result = (E) new JPAGPlainAttrValue();
260         } else if (reference.equals(GPlainAttrUniqueValue.class)) {
261             result = (E) new JPAGPlainAttrUniqueValue();
262         } else if (reference.equals(Report.class)) {
263             result = (E) new JPAReport();
264         } else if (reference.equals(ReportExec.class)) {
265             result = (E) new JPAReportExec();
266         } else if (reference.equals(NotificationTask.class)) {
267             result = (E) new JPANotificationTask();
268         } else if (reference.equals(PropagationTask.class)) {
269             result = (E) new JPAPropagationTask();
270         } else if (reference.equals(PushTask.class)) {
271             result = (E) new JPAPushTask();
272         } else if (reference.equals(PullTask.class)) {
273             result = (E) new JPAPullTask();
274         } else if (reference.equals(MacroTask.class)) {
275             result = (E) new JPAMacroTask();
276         } else if (reference.equals(SchedTask.class)) {
277             result = (E) new JPASchedTask();
278         } else if (reference.equals(AnyTemplatePullTask.class)) {
279             result = (E) new JPAAnyTemplatePullTask();
280         } else if (reference.equals(SecurityQuestion.class)) {
281             result = (E) new JPASecurityQuestion();
282         } else if (reference.equals(AuditConf.class)) {
283             result = (E) new JPAAuditConf();
284         } else if (reference.equals(DynRoleMembership.class)) {
285             result = (E) new JPADynRoleMembership();
286         } else if (reference.equals(ADynGroupMembership.class)) {
287             result = (E) new JPAADynGroupMembership();
288         } else if (reference.equals(UDynGroupMembership.class)) {
289             result = (E) new JPAUDynGroupMembership();
290         } else if (reference.equals(AccessToken.class)) {
291             result = (E) new JPAAccessToken();
292         } else if (reference.equals(Implementation.class)) {
293             result = (E) new JPAImplementation();
294         } else if (reference.equals(Remediation.class)) {
295             result = (E) new JPARemediation();
296         } else if (reference.equals(Batch.class)) {
297             result = (E) new JPABatch();
298         } else if (reference.equals(Delegation.class)) {
299             result = (E) new JPADelegation();
300         } else if (reference.equals(FIQLQuery.class)) {
301             result = (E) new JPAFIQLQuery();
302         } else if (reference.equals(JobStatus.class)) {
303             result = (E) new JPAJobStatus();
304         } else if (reference.equals(SRARoute.class)) {
305             result = (E) new JPASRARoute();
306         } else if (reference.equals(AuthModule.class)) {
307             result = (E) new JPAAuthModule();
308         } else if (reference.equals(AttrRepo.class)) {
309             result = (E) new JPAAttrRepo();
310         } else if (reference.equals(AuthPolicy.class)) {
311             result = (E) new JPAAuthPolicy();
312         } else if (reference.equals(AccessPolicy.class)) {
313             result = (E) new JPAAccessPolicy();
314         } else if (reference.equals(AttrReleasePolicy.class)) {
315             result = (E) new JPAAttrReleasePolicy();
316         } else if (reference.equals(TicketExpirationPolicy.class)) {
317             result = (E) new JPATicketExpirationPolicy();
318         } else if (reference.equals(OIDCRPClientApp.class)) {
319             result = (E) new JPAOIDCRPClientApp();
320         } else if (reference.equals(CASSPClientApp.class)) {
321             result = (E) new JPACASSPClientApp();
322         } else if (reference.equals(SAML2SPClientApp.class)) {
323             result = (E) new JPASAML2SPClientApp();
324         } else if (reference.equals(SAML2IdPEntity.class)) {
325             result = (E) new JPASAML2IdPEntity();
326         } else if (reference.equals(SAML2SPEntity.class)) {
327             result = (E) new JPASAML2SPEntity();
328         } else if (reference.equals(AuthProfile.class)) {
329             result = (E) new JPAAuthProfile();
330         } else if (reference.equals(OIDCJWKS.class)) {
331             result = (E) new JPAOIDCJWKS();
332         } else if (reference.equals(WAConfigEntry.class)) {
333             result = (E) new JPAWAConfigEntry();
334         } else {
335             throw new IllegalArgumentException("Could not find a JPA implementation of " + reference.getName());
336         }
337 
338         if (result instanceof AbstractGeneratedKeyEntity) {
339             ((AbstractGeneratedKeyEntity) result).setKey(SecureRandomUtils.generateRandomUUID().toString());
340         }
341 
342         return result;
343     }
344 
345     @Override
346     public ConnPoolConf newConnPoolConf() {
347         return new JPAConnPoolConf();
348     }
349 
350     @Override
351     public Class<? extends User> userClass() {
352         return JPAUser.class;
353     }
354 
355     @Override
356     public Class<? extends Group> groupClass() {
357         return JPAGroup.class;
358     }
359 
360     @Override
361     public Class<? extends AnyObject> anyObjectClass() {
362         return JPAAnyObject.class;
363     }
364 
365     @Override
366     public Class<? extends AnySearchDAO> anySearchDAOClass() {
367         return JPAAnySearchDAO.class;
368     }
369 }