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.request;
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  
29  public class PasswordPatch extends StringReplacePatchItem {
30  
31      private static final long serialVersionUID = 961023537479513071L;
32  
33      public static class Builder extends AbstractReplacePatchItem.Builder<String, PasswordPatch, Builder> {
34  
35          @Override
36          protected PasswordPatch newInstance() {
37              return new PasswordPatch();
38          }
39  
40          public Builder onSyncope(final boolean onSyncope) {
41              getInstance().setOnSyncope(onSyncope);
42              return this;
43          }
44  
45          public Builder resource(final String resource) {
46              if (resource != null) {
47                  getInstance().getResources().add(resource);
48              }
49              return this;
50          }
51  
52          public Builder resources(final String... resources) {
53              getInstance().getResources().addAll(List.of(resources));
54              return this;
55          }
56  
57          public Builder resources(final Collection<String> resources) {
58              if (resources != null) {
59                  getInstance().getResources().addAll(resources);
60              }
61              return this;
62          }
63      }
64  
65      /**
66       * Whether update should be performed on internal storage.
67       */
68      private boolean onSyncope = true;
69  
70      /**
71       * External resources for which update is needed to be propagated.
72       */
73      private final List<String> resources = new ArrayList<>();
74  
75      public boolean isOnSyncope() {
76          return onSyncope;
77      }
78  
79      public void setOnSyncope(final boolean onSyncope) {
80          this.onSyncope = onSyncope;
81      }
82  
83      @JacksonXmlElementWrapper(localName = "resources")
84      @JacksonXmlProperty(localName = "resource")
85      public List<String> getResources() {
86          return resources;
87      }
88  
89      @Override
90      public int hashCode() {
91          return new HashCodeBuilder().
92                  appendSuper(super.hashCode()).
93                  append(onSyncope).
94                  append(resources).
95                  build();
96      }
97  
98      @Override
99      public boolean equals(final Object obj) {
100         if (this == obj) {
101             return true;
102         }
103         if (obj == null) {
104             return false;
105         }
106         if (getClass() != obj.getClass()) {
107             return false;
108         }
109         final PasswordPatch other = (PasswordPatch) obj;
110         return new EqualsBuilder().
111                 appendSuper(super.equals(obj)).
112                 append(onSyncope, other.onSyncope).
113                 append(resources, other.resources).
114                 build();
115     }
116 }