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