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.HashSet;
23 import java.util.List;
24 import java.util.Set;
25 import javax.persistence.Entity;
26 import javax.persistence.FetchType;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.JoinTable;
29 import javax.persistence.ManyToMany;
30 import javax.persistence.Table;
31 import javax.persistence.UniqueConstraint;
32 import javax.validation.constraints.NotNull;
33 import org.apache.syncope.common.lib.types.IdRepoImplementationType;
34 import org.apache.syncope.core.persistence.api.entity.ExternalResource;
35 import org.apache.syncope.core.persistence.api.entity.Implementation;
36 import org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy;
37 import org.apache.syncope.core.persistence.jpa.entity.JPAExternalResource;
38 import org.apache.syncope.core.persistence.jpa.entity.JPAImplementation;
39
40 @Entity
41 @Table(name = JPAAccountPolicy.TABLE)
42 public class JPAAccountPolicy extends AbstractPolicy implements AccountPolicy {
43
44 private static final long serialVersionUID = -2767606675667839060L;
45
46 public static final String TABLE = "AccountPolicy";
47
48 @NotNull
49 private Boolean propagateSuspension = false;
50
51 private int maxAuthenticationAttempts;
52
53 @ManyToMany(fetch = FetchType.EAGER)
54 @JoinTable(name = TABLE + "Rule",
55 joinColumns =
56 @JoinColumn(name = "policy_id"),
57 inverseJoinColumns =
58 @JoinColumn(name = "implementation_id"),
59 uniqueConstraints =
60 @UniqueConstraint(columnNames = { "policy_id", "implementation_id" }))
61 private List<JPAImplementation> rules = new ArrayList<>();
62
63
64
65
66 @ManyToMany(fetch = FetchType.EAGER)
67 @JoinTable(joinColumns =
68 @JoinColumn(name = "accountPolicy_id"),
69 inverseJoinColumns =
70 @JoinColumn(name = "resource_id"),
71 uniqueConstraints =
72 @UniqueConstraint(columnNames = { "accountPolicy_id", "resource_id" }))
73 private Set<JPAExternalResource> resources = new HashSet<>();
74
75 @Override
76 public boolean isPropagateSuspension() {
77 return propagateSuspension;
78 }
79
80 @Override
81 public void setPropagateSuspension(final boolean propagateSuspension) {
82 this.propagateSuspension = propagateSuspension;
83 }
84
85 @Override
86 public int getMaxAuthenticationAttempts() {
87 return maxAuthenticationAttempts;
88 }
89
90 @Override
91 public void setMaxAuthenticationAttempts(final int maxAuthenticationAttempts) {
92 this.maxAuthenticationAttempts = maxAuthenticationAttempts;
93 }
94
95 @Override
96 public boolean add(final Implementation rule) {
97 checkType(rule, JPAImplementation.class);
98 checkImplementationType(rule, IdRepoImplementationType.ACCOUNT_RULE);
99 return rules.contains((JPAImplementation) rule) || rules.add((JPAImplementation) rule);
100 }
101
102 @Override
103 public List<? extends Implementation> getRules() {
104 return rules;
105 }
106
107 @Override
108 public boolean add(final ExternalResource resource) {
109 checkType(resource, JPAExternalResource.class);
110 return resources.contains((JPAExternalResource) resource) || resources.add((JPAExternalResource) resource);
111 }
112
113 @Override
114 public Set<? extends ExternalResource> getResources() {
115 return resources;
116 }
117 }