@Test public void createBasicAuthHeaderWithoutUsernameAuthThrowsException() throws Exception { config.authentication = ntlmAuthentication; Header basicAuth = underTest.createBasicAuthHeader(); assertThat(basicAuth, is(nullValue())); }
@Nullable @Override @Guarded(by = STARTED) public Header createBasicAuthHeader() { if (config.authentication instanceof UsernameAuthenticationConfiguration) { UsernameAuthenticationConfiguration userAuth = (UsernameAuthenticationConfiguration) config.authentication; String auth = format("%1$s:%2$s", userAuth.getUsername(), userAuth.getPassword()); byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(ISO_8859_1)); String authHeader = "Basic " + new String(encodedAuth, ISO_8859_1); return new BasicHeader(AUTHORIZATION, authHeader); } else { log.debug("Basic auth header cannot be created for auth config of {}", config.authentication); return null; } }
HttpClientFacetImpl extends FacetSupport implements HttpClientFacet, RemoteConnectionStatusObserver { @Nullable @Override @Guarded(by = STARTED) public Header createBasicAuthHeader() { if (config.authentication instanceof UsernameAuthenticationConfiguration) { UsernameAuthenticationConfiguration userAuth = (UsernameAuthenticationConfiguration) config.authentication; String auth = format("%1$s:%2$s", userAuth.getUsername(), userAuth.getPassword()); byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(ISO_8859_1)); String authHeader = "Basic " + new String(encodedAuth, ISO_8859_1); return new BasicHeader(AUTHORIZATION, authHeader); } else { log.debug("Basic auth header cannot be created for auth config of {}", config.authentication); return null; } } }
HttpClientFacetImpl extends FacetSupport implements HttpClientFacet, RemoteConnectionStatusObserver { @Nullable @Override @Guarded(by = STARTED) public Header createBasicAuthHeader() { if (config.authentication instanceof UsernameAuthenticationConfiguration) { UsernameAuthenticationConfiguration userAuth = (UsernameAuthenticationConfiguration) config.authentication; String auth = format("%1$s:%2$s", userAuth.getUsername(), userAuth.getPassword()); byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(ISO_8859_1)); String authHeader = "Basic " + new String(encodedAuth, ISO_8859_1); return new BasicHeader(AUTHORIZATION, authHeader); } else { log.debug("Basic auth header cannot be created for auth config of {}", config.authentication); return null; } } @Inject  HttpClientFacetImpl(final HttpClientManager httpClientManager,
                             final Map<String, AutoBlockConfiguration> autoBlockConfiguration,
                             final Map<String, RedirectStrategy> redirectStrategy,
                             final Map<String, NormalizationStrategy> normalizationStrategies,
                             final Map<String, ContentCompressionStrategy> contentCompressionStrategies,
                             final Map<String, TargetAuthenticationStrategy> authenticationStrategies); @VisibleForTesting  HttpClientFacetImpl(final HttpClientManager httpClientManager,
                      final Map<String, AutoBlockConfiguration> autoBlockConfiguration,
                      final Map<String, RedirectStrategy> redirectStrategy,
                      final Map<String, NormalizationStrategy> normalizationStrategy,
                      final Map<String, ContentCompressionStrategy> contentCompressionStrategies,
                      final Map<String, TargetAuthenticationStrategy> authenticationStrategies,
                      final Config config); }
HttpClientFacetImpl extends FacetSupport implements HttpClientFacet, RemoteConnectionStatusObserver { @Nullable @Override @Guarded(by = STARTED) public Header createBasicAuthHeader() { if (config.authentication instanceof UsernameAuthenticationConfiguration) { UsernameAuthenticationConfiguration userAuth = (UsernameAuthenticationConfiguration) config.authentication; String auth = format("%1$s:%2$s", userAuth.getUsername(), userAuth.getPassword()); byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(ISO_8859_1)); String authHeader = "Basic " + new String(encodedAuth, ISO_8859_1); return new BasicHeader(AUTHORIZATION, authHeader); } else { log.debug("Basic auth header cannot be created for auth config of {}", config.authentication); return null; } } @Inject  HttpClientFacetImpl(final HttpClientManager httpClientManager,
                             final Map<String, AutoBlockConfiguration> autoBlockConfiguration,
                             final Map<String, RedirectStrategy> redirectStrategy,
                             final Map<String, NormalizationStrategy> normalizationStrategies,
                             final Map<String, ContentCompressionStrategy> contentCompressionStrategies,
                             final Map<String, TargetAuthenticationStrategy> authenticationStrategies); @VisibleForTesting  HttpClientFacetImpl(final HttpClientManager httpClientManager,
                      final Map<String, AutoBlockConfiguration> autoBlockConfiguration,
                      final Map<String, RedirectStrategy> redirectStrategy,
                      final Map<String, NormalizationStrategy> normalizationStrategy,
                      final Map<String, ContentCompressionStrategy> contentCompressionStrategies,
                      final Map<String, TargetAuthenticationStrategy> authenticationStrategies,
                      final Config config); @Override @Guarded(by = STARTED) HttpClient getHttpClient(); @Nullable @Override @Guarded(by = STARTED) Header createBasicAuthHeader(); @Override String getBearerToken(); @Override @Guarded(by = STARTED) RemoteConnectionStatus getStatus(); @Subscribe void on(final HttpClientConfigurationChangedEvent event); @Override void onStatusChanged(final RemoteConnectionStatus oldStatus, final RemoteConnectionStatus newStatus); }
HttpClientFacetImpl extends FacetSupport implements HttpClientFacet, RemoteConnectionStatusObserver { @Nullable @Override @Guarded(by = STARTED) public Header createBasicAuthHeader() { if (config.authentication instanceof UsernameAuthenticationConfiguration) { UsernameAuthenticationConfiguration userAuth = (UsernameAuthenticationConfiguration) config.authentication; String auth = format("%1$s:%2$s", userAuth.getUsername(), userAuth.getPassword()); byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(ISO_8859_1)); String authHeader = "Basic " + new String(encodedAuth, ISO_8859_1); return new BasicHeader(AUTHORIZATION, authHeader); } else { log.debug("Basic auth header cannot be created for auth config of {}", config.authentication); return null; } } @Inject  HttpClientFacetImpl(final HttpClientManager httpClientManager,
                             final Map<String, AutoBlockConfiguration> autoBlockConfiguration,
                             final Map<String, RedirectStrategy> redirectStrategy,
                             final Map<String, NormalizationStrategy> normalizationStrategies,
                             final Map<String, ContentCompressionStrategy> contentCompressionStrategies,
                             final Map<String, TargetAuthenticationStrategy> authenticationStrategies); @VisibleForTesting  HttpClientFacetImpl(final HttpClientManager httpClientManager,
                      final Map<String, AutoBlockConfiguration> autoBlockConfiguration,
                      final Map<String, RedirectStrategy> redirectStrategy,
                      final Map<String, NormalizationStrategy> normalizationStrategy,
                      final Map<String, ContentCompressionStrategy> contentCompressionStrategies,
                      final Map<String, TargetAuthenticationStrategy> authenticationStrategies,
                      final Config config); @Override @Guarded(by = STARTED) HttpClient getHttpClient(); @Nullable @Override @Guarded(by = STARTED) Header createBasicAuthHeader(); @Override String getBearerToken(); @Override @Guarded(by = STARTED) RemoteConnectionStatus getStatus(); @Subscribe void on(final HttpClientConfigurationChangedEvent event); @Override void onStatusChanged(final RemoteConnectionStatus oldStatus, final RemoteConnectionStatus newStatus);  }