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.common.lib.to;
20  
21  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
22  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.List;
26  import javax.ws.rs.PathParam;
27  import org.apache.commons.lang3.builder.EqualsBuilder;
28  import org.apache.commons.lang3.builder.HashCodeBuilder;
29  import org.apache.syncope.common.lib.wa.GoogleMfaAuthAccount;
30  import org.apache.syncope.common.lib.wa.GoogleMfaAuthToken;
31  import org.apache.syncope.common.lib.wa.ImpersonationAccount;
32  import org.apache.syncope.common.lib.wa.MfaTrustedDevice;
33  import org.apache.syncope.common.lib.wa.U2FDevice;
34  import org.apache.syncope.common.lib.wa.WebAuthnDeviceCredential;
35  
36  public class AuthProfileTO implements EntityTO {
37  
38      private static final long serialVersionUID = -6543425997956703057L;
39  
40      public static class Builder {
41  
42          private final AuthProfileTO instance = new AuthProfileTO();
43  
44          public AuthProfileTO.Builder key(final String key) {
45              instance.setKey(key);
46              return this;
47          }
48  
49          public AuthProfileTO.Builder owner(final String owner) {
50              instance.setOwner(owner);
51              return this;
52          }
53  
54          public AuthProfileTO.Builder googleMfaAuthToken(final GoogleMfaAuthToken token) {
55              instance.getGoogleMfaAuthTokens().add(token);
56              return this;
57          }
58  
59          public AuthProfileTO.Builder googleMfaAuthTokens(final GoogleMfaAuthToken... tokens) {
60              instance.getGoogleMfaAuthTokens().addAll(List.of(tokens));
61              return this;
62          }
63  
64          public AuthProfileTO.Builder googleMfaAuthTokens(final Collection<GoogleMfaAuthToken> tokens) {
65              instance.getGoogleMfaAuthTokens().addAll(tokens);
66              return this;
67          }
68  
69          public AuthProfileTO.Builder googleMfaAuthAccount(final GoogleMfaAuthAccount account) {
70              instance.getGoogleMfaAuthAccounts().add(account);
71              return this;
72          }
73  
74          public AuthProfileTO.Builder googleMfaAuthAccounts(final GoogleMfaAuthAccount... accounts) {
75              instance.getGoogleMfaAuthAccounts().addAll(List.of(accounts));
76              return this;
77          }
78  
79          public AuthProfileTO.Builder googleMfaAuthAccounts(final Collection<GoogleMfaAuthAccount> accounts) {
80              instance.getGoogleMfaAuthAccounts().addAll(accounts);
81              return this;
82          }
83  
84          public AuthProfileTO.Builder u2fRegisteredDevice(final U2FDevice device) {
85              instance.getU2FRegisteredDevices().add(device);
86              return this;
87          }
88  
89          public AuthProfileTO.Builder u2fRegisteredDevices(final U2FDevice... devices) {
90              instance.getU2FRegisteredDevices().addAll(List.of(devices));
91              return this;
92          }
93  
94          public AuthProfileTO.Builder u2fRegisteredDevices(final Collection<U2FDevice> devices) {
95              instance.getU2FRegisteredDevices().addAll(devices);
96              return this;
97          }
98  
99          public AuthProfileTO.Builder mfaTrustedDevice(final MfaTrustedDevice device) {
100             instance.getMfaTrustedDevices().add(device);
101             return this;
102         }
103 
104         public AuthProfileTO.Builder mfaTrustedDevices(final MfaTrustedDevice... devices) {
105             instance.getMfaTrustedDevices().addAll(List.of(devices));
106             return this;
107         }
108 
109         public AuthProfileTO.Builder mfaTrustedDevices(final Collection<MfaTrustedDevice> devices) {
110             instance.getMfaTrustedDevices().addAll(devices);
111             return this;
112         }
113 
114         public AuthProfileTO.Builder credential(final WebAuthnDeviceCredential credential) {
115             instance.getWebAuthnDeviceCredentials().add(credential);
116             return this;
117         }
118 
119         public AuthProfileTO.Builder credentials(final WebAuthnDeviceCredential... credentials) {
120             instance.getWebAuthnDeviceCredentials().addAll(List.of(credentials));
121             return this;
122         }
123 
124         public AuthProfileTO.Builder credentials(final Collection<WebAuthnDeviceCredential> credentials) {
125             instance.getWebAuthnDeviceCredentials().addAll(credentials);
126             return this;
127         }
128 
129         public AuthProfileTO build() {
130             return instance;
131         }
132     }
133 
134     private String key;
135 
136     private String owner;
137 
138     private final List<ImpersonationAccount> impersonationAccounts = new ArrayList<>();
139 
140     private final List<GoogleMfaAuthToken> googleMfaAuthTokens = new ArrayList<>();
141 
142     private final List<GoogleMfaAuthAccount> googleMfaAuthAccounts = new ArrayList<>();
143 
144     private final List<U2FDevice> u2fRegisteredDevices = new ArrayList<>();
145 
146     private final List<MfaTrustedDevice> mfaTrustedDevices = new ArrayList<>();
147 
148     private final List<WebAuthnDeviceCredential> webAuthnDeviceCredentials = new ArrayList<>();
149 
150     @Override
151     public String getKey() {
152         return key;
153     }
154 
155     @PathParam("key")
156     @Override
157     public void setKey(final String key) {
158         this.key = key;
159     }
160 
161     public String getOwner() {
162         return owner;
163     }
164 
165     public void setOwner(final String owner) {
166         this.owner = owner;
167     }
168 
169     @JacksonXmlElementWrapper(localName = "impersonationAccounts")
170     @JacksonXmlProperty(localName = "impersonationAccount")
171     public List<ImpersonationAccount> getImpersonationAccounts() {
172         return impersonationAccounts;
173     }
174 
175     @JacksonXmlElementWrapper(localName = "googleMfaAuthTokens")
176     @JacksonXmlProperty(localName = "googleMfaAuthToken")
177     public List<GoogleMfaAuthToken> getGoogleMfaAuthTokens() {
178         return googleMfaAuthTokens;
179     }
180 
181     @JacksonXmlElementWrapper(localName = "googleMfaAuthAccounts")
182     @JacksonXmlProperty(localName = "googleMfaAuthAccount")
183     public List<GoogleMfaAuthAccount> getGoogleMfaAuthAccounts() {
184         return googleMfaAuthAccounts;
185     }
186 
187     @JacksonXmlElementWrapper(localName = "u2fRegisteredDevices")
188     @JacksonXmlProperty(localName = "u2fRegisteredDevice")
189     public List<U2FDevice> getU2FRegisteredDevices() {
190         return u2fRegisteredDevices;
191     }
192 
193     @JacksonXmlElementWrapper(localName = "mfaTrustedDevices")
194     @JacksonXmlProperty(localName = "mfaTrustedDevice")
195     public List<MfaTrustedDevice> getMfaTrustedDevices() {
196         return mfaTrustedDevices;
197     }
198 
199     @JacksonXmlElementWrapper(localName = "credentials")
200     @JacksonXmlProperty(localName = "credential")
201     public List<WebAuthnDeviceCredential> getWebAuthnDeviceCredentials() {
202         return webAuthnDeviceCredentials;
203     }
204 
205     @Override
206     public int hashCode() {
207         return new HashCodeBuilder().
208                 append(key).
209                 append(owner).
210                 append(impersonationAccounts).
211                 append(googleMfaAuthTokens).
212                 append(googleMfaAuthAccounts).
213                 append(u2fRegisteredDevices).
214                 append(mfaTrustedDevices).
215                 append(webAuthnDeviceCredentials).
216                 build();
217     }
218 
219     @Override
220     public boolean equals(final Object obj) {
221         if (this == obj) {
222             return true;
223         }
224         if (obj == null) {
225             return false;
226         }
227         if (getClass() != obj.getClass()) {
228             return false;
229         }
230         AuthProfileTO other = (AuthProfileTO) obj;
231         return new EqualsBuilder().
232                 append(key, other.key).
233                 append(owner, other.owner).
234                 append(impersonationAccounts, other.impersonationAccounts).
235                 append(googleMfaAuthTokens, other.googleMfaAuthTokens).
236                 append(googleMfaAuthAccounts, other.googleMfaAuthAccounts).
237                 append(u2fRegisteredDevices, other.u2fRegisteredDevices).
238                 append(mfaTrustedDevices, other.mfaTrustedDevices).
239                 append(webAuthnDeviceCredentials, other.webAuthnDeviceCredentials).
240                 build();
241     }
242 }