/** * Sets the authorization header created from the session on the soap client. * * @param soapClient the SOAP client to set the HTTP header on * @param adsSession the session * @throws AuthenticationException if the authorization header could not be * created */ @SuppressWarnings("unchecked") /* See constructor comments. */ public void setAuthorization(Object soapClient, AdsSession adsSession) throws AuthenticationException { final String authorizationHeader = authorizationHeaderProvider.getAuthorizationHeader(adsSession, soapClientHandler.getEndpointAddress(soapClient)); soapClientHandler.putAllHttpHeaders(soapClient, new HashMap<String, String>() { { put("Authorization", authorizationHeader); } }); } }
/** * Sets the authorization header created from the session on the soap client. * * @param soapClient the SOAP client to set the HTTP header on * @param adsSession the session * @throws AuthenticationException if the authorization header could not be * created */ @SuppressWarnings("unchecked") /* See constructor comments. */ public void setAuthorization(Object soapClient, AdsSession adsSession) throws AuthenticationException { final String authorizationHeader = authorizationHeaderProvider.getAuthorizationHeader(adsSession, soapClientHandler.getEndpointAddress(soapClient)); soapClientHandler.putAllHttpHeaders(soapClient, new HashMap<String, String>() { { put("Authorization", authorizationHeader); } }); } }
@SuppressWarnings("unchecked") @Test public void testSetAuthorization() throws Exception { String authorizationHeaderValue = "IAmAuthorized"; final String endpoint = "endpoint"; Object soapClient = new Object(); AdsSession adsSession = () -> endpoint; @SuppressWarnings("rawtypes") ArgumentCaptor<Map> headers = ArgumentCaptor.forClass(Map.class); when(soapClientHandler.getEndpointAddress(soapClient)).thenReturn(endpoint); when(authorizationHeaderProvider.getAuthorizationHeader( same(adsSession), eq(endpoint))).thenReturn(authorizationHeaderValue); authorizationHeaderHandler.setAuthorization(soapClient, adsSession); verify(soapClientHandler).putAllHttpHeaders(eq(soapClient), headers.capture()); String actualAuthorizationHeaderValue = (String) headers.getValue().get("Authorization"); assertEquals(authorizationHeaderValue, actualAuthorizationHeaderValue); } }