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.core.spring.security;
20  
21  import java.io.Serializable;
22  import javax.servlet.http.HttpServletRequest;
23  import org.apache.commons.lang3.StringUtils;
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.SyncopeConstants;
28  import org.apache.syncope.common.rest.api.RESTHeaders;
29  
30  public class SyncopeAuthenticationDetails implements Serializable {
31  
32      private static final long serialVersionUID = -5899959397393502897L;
33  
34      private final String domain;
35  
36      private final String delegatedBy;
37  
38      public SyncopeAuthenticationDetails(final HttpServletRequest request) {
39          this.domain = request.getHeader(RESTHeaders.DOMAIN);
40          this.delegatedBy = request.getHeader(RESTHeaders.DELEGATED_BY);
41      }
42  
43      public SyncopeAuthenticationDetails(final String domain, final String delegatedBy) {
44          this.domain = domain;
45          this.delegatedBy = delegatedBy;
46      }
47  
48      public String getDomain() {
49          return StringUtils.isBlank(domain)
50                  ? SyncopeConstants.MASTER_DOMAIN
51                  : domain;
52      }
53  
54      public String getDelegatedBy() {
55          return delegatedBy;
56      }
57  
58      @Override
59      public int hashCode() {
60          return new HashCodeBuilder().
61                  append(domain).
62                  append(delegatedBy).
63                  build();
64      }
65  
66      @Override
67      public boolean equals(final Object obj) {
68          if (this == obj) {
69              return true;
70          }
71          if (obj == null) {
72              return false;
73          }
74          if (getClass() != obj.getClass()) {
75              return false;
76          }
77          final SyncopeAuthenticationDetails other = (SyncopeAuthenticationDetails) obj;
78          return new EqualsBuilder().
79                  append(domain, other.domain).
80                  append(delegatedBy, other.delegatedBy).
81                  build();
82      }
83  
84      @Override
85      public String toString() {
86          return new ToStringBuilder(this).
87                  append(domain).
88                  append(delegatedBy).
89                  build();
90      }
91  }