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.am;
20  
21  import org.apache.syncope.common.lib.to.CASSPClientAppTO;
22  import org.apache.syncope.common.lib.to.ClientAppTO;
23  import org.apache.syncope.common.lib.to.OIDCRPClientAppTO;
24  import org.apache.syncope.common.lib.to.SAML2SPClientAppTO;
25  import org.apache.syncope.common.lib.types.ClientAppType;
26  import org.apache.syncope.core.persistence.api.entity.am.CASSPClientApp;
27  import org.apache.syncope.core.persistence.api.entity.am.ClientApp;
28  import org.apache.syncope.core.persistence.api.entity.am.ClientAppUtils;
29  import org.apache.syncope.core.persistence.api.entity.am.ClientAppUtilsFactory;
30  import org.apache.syncope.core.persistence.api.entity.am.OIDCRPClientApp;
31  import org.apache.syncope.core.persistence.api.entity.am.SAML2SPClientApp;
32  
33  public class JPAClientAppUtilsFactory implements ClientAppUtilsFactory {
34  
35      @Override
36      public ClientAppUtils getInstance(final ClientAppType type) {
37          return new JPAClientAppUtils(type);
38      }
39  
40      @Override
41      public ClientAppUtils getInstance(final ClientApp clientApp) {
42          ClientAppType type;
43          if (clientApp instanceof SAML2SPClientApp) {
44              type = ClientAppType.SAML2SP;
45          } else if (clientApp instanceof CASSPClientApp) {
46              type = ClientAppType.CASSP;
47          } else if (clientApp instanceof OIDCRPClientApp) {
48              type = ClientAppType.OIDCRP;
49          } else {
50              throw new IllegalArgumentException("Invalid client app: " + clientApp);
51          }
52  
53          return getInstance(type);
54      }
55  
56      @Override
57      public ClientAppUtils getInstance(final Class<? extends ClientAppTO> clientAppClass) {
58          ClientAppType type;
59          if (clientAppClass == SAML2SPClientAppTO.class) {
60              type = ClientAppType.SAML2SP;
61          } else if (clientAppClass == CASSPClientAppTO.class) {
62              type = ClientAppType.CASSP;
63          } else if (clientAppClass == OIDCRPClientAppTO.class) {
64              type = ClientAppType.OIDCRP;
65          } else {
66              throw new IllegalArgumentException("Invalid ClientAppTO app: " + clientAppClass.getName());
67          }
68  
69          return getInstance(type);
70      }
71  
72      @Override
73      public ClientAppUtils getInstance(final ClientAppTO clientAppTO) {
74          return getInstance(clientAppTO.getClass());
75      }
76  }