1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.http.auth;
28
29 import java.io.Serializable;
30 import java.security.Principal;
31 import java.util.Locale;
32
33 import org.apache.http.annotation.Immutable;
34
35 import org.apache.http.util.LangUtils;
36
37
38
39
40
41
42 @Immutable
43 public class NTUserPrincipal implements Principal, Serializable {
44
45 private static final long serialVersionUID = -6870169797924406894L;
46
47 private final String username;
48 private final String domain;
49 private final String ntname;
50
51 public NTUserPrincipal(
52 final String domain,
53 final String username) {
54 super();
55 if (username == null) {
56 throw new IllegalArgumentException("User name may not be null");
57 }
58 this.username = username;
59 if (domain != null) {
60 this.domain = domain.toUpperCase(Locale.ENGLISH);
61 } else {
62 this.domain = null;
63 }
64 if (this.domain != null && this.domain.length() > 0) {
65 StringBuilder buffer = new StringBuilder();
66 buffer.append(this.domain);
67 buffer.append('/');
68 buffer.append(this.username);
69 this.ntname = buffer.toString();
70 } else {
71 this.ntname = this.username;
72 }
73 }
74
75 public String getName() {
76 return this.ntname;
77 }
78
79 public String getDomain() {
80 return this.domain;
81 }
82
83 public String getUsername() {
84 return this.username;
85 }
86
87 @Override
88 public int hashCode() {
89 int hash = LangUtils.HASH_SEED;
90 hash = LangUtils.hashCode(hash, this.username);
91 hash = LangUtils.hashCode(hash, this.domain);
92 return hash;
93 }
94
95 @Override
96 public boolean equals(Object o) {
97 if (this == o) return true;
98 if (o instanceof NTUserPrincipal) {
99 NTUserPrincipal that = (NTUserPrincipal) o;
100 if (LangUtils.equals(this.username, that.username)
101 && LangUtils.equals(this.domain, that.domain)) {
102 return true;
103 }
104 }
105 return false;
106 }
107
108 @Override
109 public String toString() {
110 return this.ntname;
111 }
112
113 }