diff --git a/httpclient-win/src/main/java/org/apache/http/impl/auth/win/CurrentWindowsCredentials.java b/httpclient-win/src/main/java/org/apache/http/impl/auth/win/CurrentWindowsCredentials.java index 9bf4d67fb..52a18de04 100644 --- a/httpclient-win/src/main/java/org/apache/http/impl/auth/win/CurrentWindowsCredentials.java +++ b/httpclient-win/src/main/java/org/apache/http/impl/auth/win/CurrentWindowsCredentials.java @@ -33,8 +33,8 @@ import java.security.Principal; import org.apache.http.annotation.Immutable; import org.apache.http.auth.Credentials; -import com.sun.jna.platform.win32.Secur32Util; import com.sun.jna.platform.win32.Secur32.EXTENDED_NAME_FORMAT; +import com.sun.jna.platform.win32.Secur32Util; /** * Returns the current Windows user credentials @@ -44,10 +44,12 @@ import com.sun.jna.platform.win32.Secur32.EXTENDED_NAME_FORMAT; * @since 4.4 */ @Immutable -public class CurrentWindowsCredentials implements Credentials, Serializable, Principal { +public final class CurrentWindowsCredentials implements Credentials, Serializable, Principal { private static final long serialVersionUID = 4361166468529298169L; + public static final CurrentWindowsCredentials INSTANCE = new CurrentWindowsCredentials(); + /** * Get the SAM-compatible username of the currently logged-on user. * @@ -60,14 +62,6 @@ public class CurrentWindowsCredentials implements Credentials, Serializable, Pri private CurrentWindowsCredentials() { } - private static class LazyHolder { - private static final CurrentWindowsCredentials INSTANCE = new CurrentWindowsCredentials(); - } - - public static CurrentWindowsCredentials get() { - return LazyHolder.INSTANCE; - } - @Override public Principal getUserPrincipal() { return this; @@ -75,16 +69,18 @@ public class CurrentWindowsCredentials implements Credentials, Serializable, Pri @Override public int hashCode() { - return 245678; // always the same? + return getClass().hashCode(); } @Override public boolean equals(final Object o) { - if (this == o) return true; - if (o instanceof CurrentWindowsCredentials) { + if (this == o) { return true; } - return false; + if (o == null) { + return false; + } + return getClass().equals(o.getClass()); } @Override diff --git a/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsCredentialsProvider.java b/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsCredentialsProvider.java index 875bf0625..5a262aa2b 100644 --- a/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsCredentialsProvider.java +++ b/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsCredentialsProvider.java @@ -48,7 +48,7 @@ public class WindowsCredentialsProvider extends BasicCredentialsProvider { public Credentials getCredentials(final AuthScope authscope) { final String scheme = authscope.getScheme(); if (AuthSchemes.NTLM.equalsIgnoreCase(scheme) || AuthSchemes.SPNEGO.equalsIgnoreCase(scheme)) { - return CurrentWindowsCredentials.get(); + return CurrentWindowsCredentials.INSTANCE; } else { return super.getCredentials(authscope); }