@Override @Nullable public RegistryAuthenticator handleHttpResponseException( HttpResponseException httpResponseException) throws HttpResponseException, RegistryErrorException { // Only valid for status code of '401 Unauthorized'. if (httpResponseException.getStatusCode() != HttpStatusCodes.STATUS_CODE_UNAUTHORIZED) { throw httpResponseException; } // Checks if the 'WWW-Authenticate' header is present. String authenticationMethod = httpResponseException.getHeaders().getAuthenticate(); if (authenticationMethod == null) { throw new RegistryErrorExceptionBuilder(getActionDescription(), httpResponseException) .addReason("'WWW-Authenticate' header not found") .build(); } // Parses the header to retrieve the components. try { return RegistryAuthenticator.fromAuthenticationMethod( authenticationMethod, registryEndpointRequestProperties); } catch (RegistryAuthenticationFailedException ex) { throw new RegistryErrorExceptionBuilder(getActionDescription(), ex) .addReason("Failed get authentication method from 'WWW-Authenticate' header") .build(); } } }
@Override @Nullable public RegistryAuthenticator handleHttpResponseException( HttpResponseException httpResponseException) throws HttpResponseException, RegistryErrorException { // Only valid for status code of '401 Unauthorized'. if (httpResponseException.getStatusCode() != HttpStatusCodes.STATUS_CODE_UNAUTHORIZED) { throw httpResponseException; } // Checks if the 'WWW-Authenticate' header is present. String authenticationMethod = httpResponseException.getHeaders().getAuthenticate(); if (authenticationMethod == null) { throw new RegistryErrorExceptionBuilder(getActionDescription(), httpResponseException) .addReason("'WWW-Authenticate' header not found") .build(); } // Parses the header to retrieve the components. try { return RegistryAuthenticator.fromAuthenticationMethod( authenticationMethod, registryEndpointRequestProperties); } catch (RegistryAuthenticationFailedException ex) { throw new RegistryErrorExceptionBuilder(getActionDescription(), ex) .addReason("Failed get authentication method from 'WWW-Authenticate' header") .build(); } } }
@Override @Nullable public RegistryAuthenticator handleHttpResponseException( HttpResponseException httpResponseException) throws HttpResponseException, RegistryErrorException { // Only valid for status code of '401 Unauthorized'. if (httpResponseException.getStatusCode() != HttpStatusCodes.STATUS_CODE_UNAUTHORIZED) { throw httpResponseException; } // Checks if the 'WWW-Authenticate' header is present. String authenticationMethod = httpResponseException.getHeaders().getAuthenticate(); if (authenticationMethod == null) { throw new RegistryErrorExceptionBuilder(getActionDescription(), httpResponseException) .addReason("'WWW-Authenticate' header not found") .build(); } // Parses the header to retrieve the components. try { return RegistryAuthenticator.fromAuthenticationMethod( authenticationMethod, registryEndpointRequestProperties); } catch (RegistryAuthenticationFailedException ex) { throw new RegistryErrorExceptionBuilder(getActionDescription(), ex) .addReason("Failed get authentication method from 'WWW-Authenticate' header") .build(); } } }
assertEquals(ImmutableList.of("UserAgent"), headers.get("User-Agent")); assertEquals(ImmutableList.of("UserAgent"), headers.get("user-agent")); assertEquals("Authenticate", headers.getAuthenticate()); assertEquals(Long.valueOf(456L), headers.getAge());