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
28
29
30
31
32 package org.apache.commons.httpclient;
33
34 /***
35 * <p>Username and password {@link Credentials}.</p>
36 *
37 * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
38 * @author Sean C. Sullivan
39 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
40 *
41 * @version $Revision: 1.11.2.1 $ $Date: 2004/02/22 18:21:13 $
42 *
43 */
44 public class UsernamePasswordCredentials implements Credentials {
45
46
47
48 /***
49 * Default constructor.
50 */
51 public UsernamePasswordCredentials() {
52 }
53
54
55 /***
56 * The constructor with the username and password combined string argument.
57 *
58 * @param usernamePassword the username:password formed string
59 * @see #toString
60 */
61 public UsernamePasswordCredentials(String usernamePassword) {
62 int atColon = usernamePassword.indexOf(':');
63 if (atColon >= 0) {
64 this.userName = usernamePassword.substring(0, atColon);
65 this.password = usernamePassword.substring(atColon + 1);
66 } else {
67 this.userName = usernamePassword;
68 }
69 }
70
71
72 /***
73 * The constructor with the username and password arguments.
74 *
75 * @param userName the user name
76 * @param password the password
77 */
78 public UsernamePasswordCredentials(String userName, String password) {
79 this.userName = userName;
80 this.password = password;
81 }
82
83
84
85 /***
86 * User name.
87 */
88 private String userName;
89
90
91 /***
92 * Password.
93 */
94 private String password;
95
96
97
98
99
100 /***
101 * User name property setter.
102 *
103 * @param userName
104 * @see #getUserName()
105 */
106 public void setUserName(String userName) {
107 this.userName = userName;
108 }
109
110
111 /***
112 * User name property getter.
113 *
114 * @return the userName
115 * @see #setUserName(String)
116 */
117 public String getUserName() {
118 return userName;
119 }
120
121
122 /***
123 * Password property setter.
124 *
125 * @param password
126 * @see #getPassword()
127 */
128 public void setPassword(String password) {
129 this.password = password;
130 }
131
132
133 /***
134 * Password property getter.
135 *
136 * @return the password
137 * @see #setPassword(String)
138 */
139 public String getPassword() {
140 return password;
141 }
142
143
144 /***
145 * Get this object string.
146 *
147 * @return the username:password formed string
148 */
149 public String toString() {
150 StringBuffer result = new StringBuffer();
151 result.append((this.userName == null) ? "null" : this.userName);
152 result.append(":");
153 result.append((this.password == null) ? "null" : this.password);
154 return result.toString();
155 }
156
157 }
158