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.List;
25  import java.util.Set;
26  import java.util.TreeSet;
27  import javax.ws.rs.PathParam;
28  import org.apache.commons.lang3.builder.EqualsBuilder;
29  import org.apache.commons.lang3.builder.HashCodeBuilder;
30  
31  public class RoleTO implements EntityTO {
32  
33      private static final long serialVersionUID = 4560822655754800031L;
34  
35      private String key;
36  
37      private final Set<String> entitlements = new TreeSet<>();
38  
39      private final List<String> realms = new ArrayList<>();
40  
41      private final List<String> dynRealms = new ArrayList<>();
42  
43      private String dynMembershipCond;
44  
45      private final Set<String> privileges = new TreeSet<>();
46  
47      @Override
48      public String getKey() {
49          return key;
50      }
51  
52      @PathParam("key")
53      @Override
54      public void setKey(final String key) {
55          this.key = key;
56      }
57  
58      @JacksonXmlElementWrapper(localName = "entitlements")
59      @JacksonXmlProperty(localName = "entitlement")
60      public Set<String> getEntitlements() {
61          return entitlements;
62      }
63  
64      @JacksonXmlElementWrapper(localName = "realms")
65      @JacksonXmlProperty(localName = "realm")
66      public List<String> getRealms() {
67          return realms;
68      }
69  
70      @JacksonXmlElementWrapper(localName = "dynRealms")
71      @JacksonXmlProperty(localName = "dynRealm")
72      public List<String> getDynRealms() {
73          return dynRealms;
74      }
75  
76      public String getDynMembershipCond() {
77          return dynMembershipCond;
78      }
79  
80      public void setDynMembershipCond(final String dynMembershipCond) {
81          this.dynMembershipCond = dynMembershipCond;
82      }
83  
84      @JacksonXmlElementWrapper(localName = "privileges")
85      @JacksonXmlProperty(localName = "privilege")
86      public Set<String> getPrivileges() {
87          return privileges;
88      }
89  
90      @Override
91      public boolean equals(final Object obj) {
92          if (this == obj) {
93              return true;
94          }
95          if (obj == null) {
96              return false;
97          }
98          if (getClass() != obj.getClass()) {
99              return false;
100         }
101         RoleTO other = (RoleTO) obj;
102         return new EqualsBuilder().
103                 append(key, other.key).
104                 append(entitlements, other.entitlements).
105                 append(realms, other.realms).
106                 append(dynRealms, other.dynRealms).
107                 append(dynMembershipCond, other.dynMembershipCond).
108                 append(privileges, other.privileges).
109                 build();
110     }
111 
112     @Override
113     public int hashCode() {
114         return new HashCodeBuilder().
115                 append(key).
116                 append(entitlements).
117                 append(realms).
118                 append(dynRealms).
119                 append(dynMembershipCond).
120                 append(privileges).
121                 build();
122     }
123 }