1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.common.lib.to;
20
21 import com.fasterxml.jackson.annotation.JsonIgnore;
22 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
23 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
24 import java.util.Optional;
25 import java.util.Set;
26 import java.util.TreeSet;
27 import org.apache.commons.lang3.builder.EqualsBuilder;
28 import org.apache.commons.lang3.builder.HashCodeBuilder;
29 import org.apache.syncope.common.lib.Attr;
30
31 public class LinkedAccountTO implements EntityTO {
32
33 private static final long serialVersionUID = 7396929732310559535L;
34
35 public static class Builder {
36
37 private final LinkedAccountTO instance = new LinkedAccountTO();
38
39 public Builder(final String resource, final String connObjectKeyValue) {
40 this(null, resource, connObjectKeyValue);
41 }
42
43 public Builder(final String key, final String resource, final String connObjectKeyValue) {
44 instance.setKey(key);
45 instance.setResource(resource);
46 instance.setConnObjectKeyValue(connObjectKeyValue);
47 }
48
49 public Builder username(final String username) {
50 instance.setUsername(username);
51 return this;
52 }
53
54 public Builder password(final String password) {
55 instance.setPassword(password);
56 return this;
57 }
58
59 public Builder suspended(final boolean suspended) {
60 instance.setSuspended(suspended);
61 return this;
62 }
63
64 public LinkedAccountTO build() {
65 return instance;
66 }
67 }
68
69 private String key;
70
71 private String connObjectKeyValue;
72
73 private String resource;
74
75 private String username;
76
77 private String password;
78
79 private boolean suspended;
80
81 private final Set<Attr> plainAttrs = new TreeSet<>();
82
83 private final Set<String> privileges = new TreeSet<>();
84
85 @Override
86 public String getKey() {
87 return key;
88 }
89
90 @Override
91 public void setKey(final String key) {
92 this.key = key;
93 }
94
95 public String getConnObjectKeyValue() {
96 return connObjectKeyValue;
97 }
98
99 public void setConnObjectKeyValue(final String connObjectKeyValue) {
100 this.connObjectKeyValue = connObjectKeyValue;
101 }
102
103 public String getResource() {
104 return resource;
105 }
106
107 public void setResource(final String resource) {
108 this.resource = resource;
109 }
110
111 public String getUsername() {
112 return username;
113 }
114
115 public void setUsername(final String username) {
116 this.username = username;
117 }
118
119 public String getPassword() {
120 return password;
121 }
122
123 public void setPassword(final String password) {
124 this.password = password;
125 }
126
127 public boolean isSuspended() {
128 return suspended;
129 }
130
131 public void setSuspended(final boolean suspended) {
132 this.suspended = suspended;
133 }
134
135 @JacksonXmlElementWrapper(localName = "plainAttrs")
136 @JacksonXmlProperty(localName = "plainAttr")
137 public Set<Attr> getPlainAttrs() {
138 return plainAttrs;
139 }
140
141 @JsonIgnore
142 public Optional<Attr> getPlainAttr(final String schema) {
143 return plainAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
144 }
145
146 @JacksonXmlElementWrapper(localName = "privileges")
147 @JacksonXmlProperty(localName = "privilege")
148 public Set<String> getPrivileges() {
149 return privileges;
150 }
151
152 @Override
153 public int hashCode() {
154 return new HashCodeBuilder().
155 append(key).
156 append(connObjectKeyValue).
157 append(resource).
158 append(username).
159 append(suspended).
160 append(plainAttrs).
161 append(privileges).
162 build();
163 }
164
165 @Override
166 public boolean equals(final Object obj) {
167 if (this == obj) {
168 return true;
169 }
170 if (obj == null) {
171 return false;
172 }
173 if (getClass() != obj.getClass()) {
174 return false;
175 }
176 final LinkedAccountTO other = (LinkedAccountTO) obj;
177 return new EqualsBuilder().
178 append(key, other.key).
179 append(connObjectKeyValue, other.connObjectKeyValue).
180 append(resource, other.resource).
181 append(username, other.username).
182 append(suspended, other.suspended).
183 append(plainAttrs, other.plainAttrs).
184 append(privileges, other.privileges).
185 build();
186 }
187 }