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.Contract;
34 import org.apache.http.annotation.ThreadingBehavior;
35 import org.apache.http.util.Args;
36 import org.apache.http.util.LangUtils;
37
38
39
40
41
42
43 @Contract(threading = ThreadingBehavior.IMMUTABLE)
44 public class NTUserPrincipal implements Principal, Serializable {
45
46 private static final long serialVersionUID = -6870169797924406894L;
47
48 private final String username;
49 private final String domain;
50 private final String ntname;
51
52 public NTUserPrincipal(
53 final String domain,
54 final String username) {
55 super();
56 Args.notNull(username, "User name");
57 this.username = username;
58 if (domain != null) {
59 this.domain = domain.toUpperCase(Locale.ROOT);
60 } else {
61 this.domain = null;
62 }
63 if (this.domain != null && !this.domain.isEmpty()) {
64 final StringBuilder buffer = new StringBuilder();
65 buffer.append(this.domain);
66 buffer.append('\\');
67 buffer.append(this.username);
68 this.ntname = buffer.toString();
69 } else {
70 this.ntname = this.username;
71 }
72 }
73
74 @Override
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(final Object o) {
97 if (this == o) {
98 return true;
99 }
100 if (o instanceof NTUserPrincipal) {
101 final NTUserPrincipal./../org/apache/http/auth/NTUserPrincipal.html#NTUserPrincipal">NTUserPrincipal that = (NTUserPrincipal) o;
102 if (LangUtils.equals(this.username, that.username)
103 && LangUtils.equals(this.domain, that.domain)) {
104 return true;
105 }
106 }
107 return false;
108 }
109
110 @Override
111 public String toString() {
112 return this.ntname;
113 }
114
115 }