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 java.util.ArrayList;
22  import java.util.List;
23  import javax.persistence.Entity;
24  import javax.persistence.FetchType;
25  import javax.persistence.JoinColumn;
26  import javax.persistence.JoinTable;
27  import javax.persistence.ManyToMany;
28  import javax.persistence.Table;
29  import javax.persistence.UniqueConstraint;
30  import javax.validation.constraints.NotNull;
31  import org.apache.syncope.common.lib.types.IdRepoImplementationType;
32  import org.apache.syncope.core.persistence.api.entity.Implementation;
33  import org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy;
34  import org.apache.syncope.core.persistence.jpa.entity.JPAImplementation;
35  
36  @Entity
37  @Table(name = JPAPasswordPolicy.TABLE)
38  public class JPAPasswordPolicy extends AbstractPolicy implements PasswordPolicy {
39  
40      private static final long serialVersionUID = 9138550910385232849L;
41  
42      public static final String TABLE = "PasswordPolicy";
43  
44      @NotNull
45      private Boolean allowNullPassword = false;
46  
47      private int historyLength;
48  
49      @ManyToMany(fetch = FetchType.EAGER)
50      @JoinTable(name = TABLE + "Rule",
51              joinColumns =
52              @JoinColumn(name = "policy_id"),
53              inverseJoinColumns =
54              @JoinColumn(name = "implementation_id"),
55              uniqueConstraints =
56              @UniqueConstraint(columnNames = { "policy_id", "implementation_id" }))
57      private List<JPAImplementation> rules = new ArrayList<>();
58  
59      @Override
60      public boolean isAllowNullPassword() {
61          return allowNullPassword;
62      }
63  
64      @Override
65      public void setAllowNullPassword(final boolean allowNullPassword) {
66          this.allowNullPassword = allowNullPassword;
67      }
68  
69      @Override
70      public int getHistoryLength() {
71          return historyLength;
72      }
73  
74      @Override
75      public void setHistoryLength(final int historyLength) {
76          this.historyLength = historyLength;
77      }
78  
79      @Override
80      public boolean add(final Implementation rule) {
81          checkType(rule, JPAImplementation.class);
82          checkImplementationType(rule, IdRepoImplementationType.PASSWORD_RULE);
83          return rules.contains((JPAImplementation) rule) || rules.add((JPAImplementation) rule);
84      }
85  
86      @Override
87      public List<? extends Implementation> getRules() {
88          return rules;
89      }
90  }