1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.socksx.v5;
17
18 import io.netty.handler.codec.DecoderResult;
19 import io.netty.util.internal.ObjectUtil;
20 import io.netty.util.internal.StringUtil;
21
22
23
24
25 public class DefaultSocks5PasswordAuthRequest extends AbstractSocks5Message implements Socks5PasswordAuthRequest {
26
27 private final String username;
28 private final String password;
29
30 public DefaultSocks5PasswordAuthRequest(String username, String password) {
31 ObjectUtil.checkNotNull(username, "username");
32 ObjectUtil.checkNotNull(password, "password");
33
34 if (username.length() > 255) {
35 throw new IllegalArgumentException("username: **** (expected: less than 256 chars)");
36 }
37 if (password.length() > 255) {
38 throw new IllegalArgumentException("password: **** (expected: less than 256 chars)");
39 }
40
41 this.username = username;
42 this.password = password;
43 }
44
45 @Override
46 public String username() {
47 return username;
48 }
49
50 @Override
51 public String password() {
52 return password;
53 }
54
55 @Override
56 public String toString() {
57 StringBuilder buf = new StringBuilder(StringUtil.simpleClassName(this));
58
59 DecoderResult decoderResult = decoderResult();
60 if (!decoderResult.isSuccess()) {
61 buf.append("(decoderResult: ");
62 buf.append(decoderResult);
63 buf.append(", username: ");
64 } else {
65 buf.append("(username: ");
66 }
67 buf.append(username());
68 buf.append(", password: ****)");
69
70 return buf.toString();
71 }
72 }