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.wa;
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 org.apache.commons.lang3.builder.EqualsBuilder;
27  import org.apache.commons.lang3.builder.HashCodeBuilder;
28  import org.apache.commons.lang3.builder.ToStringBuilder;
29  import org.apache.syncope.common.lib.BaseBean;
30  
31  public class WebAuthnAccount implements BaseBean {
32  
33      private static final long serialVersionUID = 2285073386484048953L;
34  
35      public static class Builder {
36  
37          private final WebAuthnAccount instance = new WebAuthnAccount();
38  
39          public WebAuthnAccount.Builder credential(final WebAuthnDeviceCredential credential) {
40              instance.getCredentials().add(credential);
41              return this;
42          }
43  
44          public WebAuthnAccount.Builder credentials(final WebAuthnDeviceCredential... credentials) {
45              instance.getCredentials().addAll(List.of(credentials));
46              return this;
47          }
48  
49          public WebAuthnAccount.Builder credentials(final Collection<WebAuthnDeviceCredential> credentials) {
50              instance.getCredentials().addAll(credentials);
51              return this;
52          }
53  
54          public WebAuthnAccount build() {
55              return instance;
56          }
57      }
58  
59      private final List<WebAuthnDeviceCredential> credentials = new ArrayList<>();
60  
61      @JacksonXmlElementWrapper(localName = "credentials")
62      @JacksonXmlProperty(localName = "credential")
63      public List<WebAuthnDeviceCredential> getCredentials() {
64          return credentials;
65      }
66  
67      @Override
68      public int hashCode() {
69          return new HashCodeBuilder()
70                  .appendSuper(super.hashCode())
71                  .append(credentials)
72                  .toHashCode();
73      }
74  
75      @Override
76      public boolean equals(final Object obj) {
77          if (obj == null) {
78              return false;
79          }
80          if (obj == this) {
81              return true;
82          }
83          if (obj.getClass() != getClass()) {
84              return false;
85          }
86          WebAuthnAccount rhs = (WebAuthnAccount) obj;
87          return new EqualsBuilder()
88                  .appendSuper(super.equals(obj))
89                  .append(this.credentials, rhs.credentials)
90                  .isEquals();
91      }
92  
93      @Override
94      public String toString() {
95          return new ToStringBuilder(this)
96                  .append("credentials", credentials)
97                  .toString();
98      }
99  }