1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }