1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }