Skip to content

Commit b9f4e3c

Browse files
committed
Solved some SpotBugs issues
1 parent d636535 commit b9f4e3c

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.bbottema.javasocksproxyserver;
22

3-
public interface AuthConstants {
4-
byte AUTH_VERSION = 0x01;
5-
byte[] AUTH_USER_PASS_SUCCESS = new byte[]{AUTH_VERSION, 0x00};
3+
public class AuthConstants {
4+
static final byte AUTH_VERSION = 0x01;
5+
static final byte[] AUTH_USER_PASS_SUCCESS = new byte[]{AUTH_VERSION, 0x00};
66
// 0x00 denotes success, any other value denotes failure
7-
byte[] AUTH_USER_PASS_FAILED = new byte[]{AUTH_VERSION, 0x01};
7+
static final byte[] AUTH_USER_PASS_FAILED = new byte[]{AUTH_VERSION, 0x01};
88

9-
byte TYPE_NO_AUTH = 0x00;
10-
byte TYPE_USER_PASS_AUTH = 0x02;
9+
public static final byte TYPE_NO_AUTH = 0x00;
10+
public static final byte TYPE_USER_PASS_AUTH = 0x02;
1111

12-
byte NONE_ACCEPTED = (byte) 0xff;
12+
public static final byte NONE_ACCEPTED = (byte) 0xff;
1313
}

src/main/java/org/bbottema/javasocksproxyserver/SocksServer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public SocksServer(int listenPort, ServerSocketFactory factory) {
3535
this.factory = factory;
3636
}
3737

38-
public SocksServer setAuthenticator(Authenticator authenticator) {
38+
public synchronized SocksServer setAuthenticator(Authenticator authenticator) {
3939
this.authenticator = authenticator;
4040
return this;
4141
}
@@ -90,8 +90,8 @@ public void run() {
9090
protected void handleClients(int port) throws IOException {
9191
final ServerSocket listenSocket = serverSocketFactory.createServerSocket(port);
9292
listenSocket.setSoTimeout(SocksConstants.LISTEN_TIMEOUT);
93-
94-
LOGGER.debug("SOCKS server listening at port: " + listenSocket.getLocalPort());
93+
94+
LOGGER.debug("SOCKS server listening at port: {}", listenSocket.getLocalPort());
9595

9696
while (true) {
9797
synchronized (SocksServer.this) {
@@ -113,7 +113,7 @@ private void handleNextClient(ServerSocket listenSocket) {
113113
try {
114114
final Socket clientSocket = listenSocket.accept();
115115
clientSocket.setSoTimeout(SocksConstants.DEFAULT_SERVER_TIMEOUT);
116-
LOGGER.debug("Connection from : " + Utils.getSocketInfo(clientSocket));
116+
LOGGER.debug("Connection from : {}", Utils.getSocketInfo(clientSocket));
117117
new Thread(new ProxyHandler(clientSocket, authenticator)).start();
118118
} catch (InterruptedIOException e) {
119119
// This exception is thrown when accept timeout is expired

src/main/java/org/bbottema/javasocksproxyserver/auth/UsernamePasswordAuthenticator.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.bbottema.javasocksproxyserver.AuthConstants;
44

5+
import static java.nio.charset.StandardCharsets.UTF_8;
6+
57
public abstract class UsernamePasswordAuthenticator extends Authenticator {
68

79
private final boolean acceptNoAuthMode;
@@ -29,7 +31,7 @@ public byte accept(byte[] authTypes) {
2931

3032
@Override
3133
public boolean validate(byte[] username, byte[] password) {
32-
return validate(new String(username), new String(password));
34+
return validate(new String(username, UTF_8), new String(password, UTF_8));
3335
}
3436

3537
public abstract boolean validate(String username, String password);

0 commit comments

Comments
 (0)