1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.httpclient;
16
17 import java.io.Serializable;
18 import java.security.Principal;
19
20 import org.apache.http.auth.Credentials;
21 import org.apache.http.auth.UsernamePasswordCredentials;
22 import org.apache.http.util.LangUtils;
23
24
25
26
27
28
29
30 public class HtmlUnitUsernamePasswordCredentials implements Credentials, Serializable {
31
32 private final UsernamePasswordCredentials httpClientUsernamePasswordCredentials_;
33
34
35
36
37
38
39
40 public HtmlUnitUsernamePasswordCredentials(final String userName, final char[] password) {
41 httpClientUsernamePasswordCredentials_ = new UsernamePasswordCredentials(
42 userName,
43 password == null ? null : String.valueOf(password));
44 }
45
46 @Override
47 public String getPassword() {
48 return httpClientUsernamePasswordCredentials_.getPassword();
49 }
50
51 @Override
52 public Principal getUserPrincipal() {
53 return httpClientUsernamePasswordCredentials_.getUserPrincipal();
54 }
55
56 @Override
57 public int hashCode() {
58 return getUserPrincipal().hashCode();
59 }
60
61 @Override
62 public boolean equals(final Object o) {
63 if (this == o) {
64 return true;
65 }
66 if (o instanceof HtmlUnitUsernamePasswordCredentials) {
67 final HtmlUnitUsernamePasswordCredentials that = (HtmlUnitUsernamePasswordCredentials) o;
68 if (LangUtils.equals(this.getUserPrincipal(), that.getUserPrincipal())) {
69 return true;
70 }
71 }
72 return false;
73 }
74
75 @Override
76 public String toString() {
77 return getUserPrincipal().toString();
78 }
79 }