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.policy;
20  
21  import org.apache.syncope.common.lib.types.PolicyType;
22  import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
23  import org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy;
24  import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
25  import org.apache.syncope.core.persistence.api.entity.policy.AuthPolicy;
26  import org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy;
27  import org.apache.syncope.core.persistence.api.entity.policy.Policy;
28  import org.apache.syncope.core.persistence.api.entity.policy.PolicyUtils;
29  import org.apache.syncope.core.persistence.api.entity.policy.PropagationPolicy;
30  import org.apache.syncope.core.persistence.api.entity.policy.PullPolicy;
31  import org.apache.syncope.core.persistence.api.entity.policy.PushPolicy;
32  import org.apache.syncope.core.persistence.api.entity.policy.TicketExpirationPolicy;
33  
34  public class JPAPolicyUtils implements PolicyUtils {
35  
36      private final PolicyType type;
37  
38      protected JPAPolicyUtils(final PolicyType type) {
39          this.type = type;
40      }
41  
42      @Override
43      public PolicyType getType() {
44          return type;
45      }
46  
47      @Override
48      public Class<? extends Policy> policyClass() {
49          switch (type) {
50              case ACCOUNT:
51                  return AccountPolicy.class;
52  
53              case PASSWORD:
54                  return PasswordPolicy.class;
55  
56              case AUTH:
57                  return AuthPolicy.class;
58  
59              case ATTR_RELEASE:
60                  return AttrReleasePolicy.class;
61  
62              case ACCESS:
63                  return AccessPolicy.class;
64  
65              case TICKET_EXPIRATION:
66                  return TicketExpirationPolicy.class;
67  
68              case PROPAGATION:
69                  return PropagationPolicy.class;
70  
71              case PULL:
72                  return PullPolicy.class;
73  
74              case PUSH:
75              default:
76                  return PushPolicy.class;
77          }
78      }
79  }