This repository was archived by the owner on May 28, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
connectors/apache-connector/src
main/java/org/glassfish/jersey/apache/connector
test/java/org/glassfish/jersey/apache/connector Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -439,6 +439,14 @@ public ClientResponse apply(final ClientRequest clientRequest) throws Processing
439439 authCache .put (getHost (request ), basicScheme );
440440 context .setAuthCache (authCache );
441441 }
442+
443+ // If a request-specific CredentialsProvider exists, use it instead of the default one
444+ CredentialsProvider credentialsProvider =
445+ clientRequest .resolveProperty (ApacheClientProperties .CREDENTIALS_PROVIDER , CredentialsProvider .class );
446+ if (credentialsProvider != null ) {
447+ context .setCredentialsProvider (credentialsProvider );
448+ }
449+
442450 response = client .execute (getHost (request ), request , context );
443451 HeaderUtils .checkHeaderChanges (clientHeadersSnapshot , clientRequest .getHeaders (), this .getClass ().getName ());
444452
Original file line number Diff line number Diff line change 11/*
22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33 *
4- * Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
4+ * Copyright (c) 2010-2017 Oracle and/or its affiliates. All rights reserved.
55 *
66 * The contents of this file are subject to the terms of either the GNU
77 * General Public License Version 2 only ("GPL") or the Common Development
@@ -248,6 +248,25 @@ public void testAuthGet() {
248248 assertEquals ("GET" , r .request ().get (String .class ));
249249 }
250250
251+ @ Test
252+ public void testAuthGetWithRequestCredentialsProvider () {
253+ CredentialsProvider credentialsProvider = new org .apache .http .impl .client .BasicCredentialsProvider ();
254+ credentialsProvider .setCredentials (
255+ AuthScope .ANY ,
256+ new UsernamePasswordCredentials ("name" , "password" )
257+ );
258+
259+ ClientConfig cc = new ClientConfig ();
260+ cc .connectorProvider (new ApacheConnectorProvider ());
261+ Client client = ClientBuilder .newClient (cc );
262+ WebTarget r = client .target (getBaseUri ()).path ("test" );
263+
264+ assertEquals ("GET" ,
265+ r .request ()
266+ .property (ApacheClientProperties .CREDENTIALS_PROVIDER , credentialsProvider )
267+ .get (String .class ));
268+ }
269+
251270 @ Test
252271 public void testAuthGetWithClientFilter () {
253272 ClientConfig cc = new ClientConfig ();
You can’t perform that action at this time.
0 commit comments