hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1619126 - in /httpcomponents/httpclient/trunk/httpclient-win/src: main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java
Date Wed, 20 Aug 2014 15:29:00 GMT
Author: olegk
Date: Wed Aug 20 15:28:59 2014
New Revision: 1619126

URL: http://svn.apache.org/r1619126
Log:
HTTPCLIENT-1545: Improved unit test
Contributed by Ka-Lok Fung <ka-lok.fung at sap.com>

Modified:
    httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java
    httpcomponents/httpclient/trunk/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java

Modified: httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java?rev=1619126&r1=1619125&r2=1619126&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java
Wed Aug 20 15:28:59 2014
@@ -65,12 +65,12 @@ public class WindowsNegotiateScheme exte
 
     // NTLM or Negotiate
     private final String scheme;
+    private final String servicePrincipalName;
 
     private CredHandle clientCred;
     private CtxtHandle sppicontext;
     private boolean continueNeeded;
     private String challenge;
-    private String servicePrincipalName;
 
     public WindowsNegotiateScheme(final String scheme, final String servicePrincipalName)
{
         super();
@@ -214,7 +214,7 @@ public class WindowsNegotiateScheme exte
     }
 
     // See http://msdn.microsoft.com/en-us/library/windows/desktop/aa375506(v=vs.85).aspx
-    private String getToken(
+    String getToken(
             final CtxtHandle continueCtx,
             final SecBufferDesc continueToken,
             final String targetName) {

Modified: httpcomponents/httpclient/trunk/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java?rev=1619126&r1=1619125&r2=1619126&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java
Wed Aug 20 15:28:59 2014
@@ -28,12 +28,17 @@ package org.apache.http.impl.auth.win;
 
 import java.io.IOException;
 
+import com.sun.jna.platform.win32.Sspi.CtxtHandle;
+import com.sun.jna.platform.win32.Sspi.SecBufferDesc;
+import com.sun.jna.platform.win32.Win32Exception;
+import com.sun.jna.platform.win32.WinError;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.auth.AUTH;
+import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthSchemeProvider;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.config.AuthSchemes;
@@ -94,9 +99,13 @@ public class TestWindowsNegotiateScheme 
         // you can contact the server that authenticated you." is associated with SEC_E_DOWNGRADE_DETECTED.
 
         final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
-                .register(AuthSchemes.SPNEGO, new WindowsNegotiateSchemeFactory("HTTP/EXAMPLE.COM"))
-                .build();
-        final CredentialsProvider credsProvider = new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider());
+            .register(AuthSchemes.SPNEGO, new AuthSchemeProvider() {
+                public AuthScheme create(final HttpContext context) {
+                    return new WindowsNegotiateSchemeGetTokenFail(AuthSchemes.SPNEGO, "HTTP/EXAMPLE.COM");
+                }
+            }).build();
+        final CredentialsProvider credsProvider =
+                new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider());
         final CloseableHttpClient customClient = HttpClientBuilder.create()
                 .setDefaultCredentialsProvider(credsProvider)
                 .setDefaultAuthSchemeRegistry(authSchemeRegistry).build();
@@ -111,6 +120,18 @@ public class TestWindowsNegotiateScheme 
         }
     }
 
-}
+    private final class WindowsNegotiateSchemeGetTokenFail extends WindowsNegotiateScheme
{
+
+        public WindowsNegotiateSchemeGetTokenFail(final String scheme, final String servicePrincipalName)
{
+            super(scheme, servicePrincipalName);
+        }
 
+        @Override
+        String getToken(final CtxtHandle continueCtx, final SecBufferDesc continueToken,
final String targetName) {
+            dispose();
+            throw new Win32Exception(WinError.SEC_E_DOWNGRADE_DETECTED);
+        }
 
+    }
+
+}



Mime
View raw message