.credentials(builder.clientId, builder.clientSecret) .build();
private WebTarget getRegistryWebTarget(ImageRef imageRef) { if (!webTargets.containsKey(imageRef.getRegistryUrl())) { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JavaTimeModule()); ClientConfig clientCOnfig = new ClientConfig(); clientCOnfig.connectorProvider(new HttpUrlConnectorProvider()); // TODO : This client doesn't handle mandatory Oauth2 Bearer token imposed by some registries implementations (ie : docker hub) Client client = ClientBuilder.newClient(clientCOnfig) .register(new JacksonJaxbJsonProvider(mapper, new Annotations[] {Annotations.JACKSON})) .register(JacksonFeature.class); String auth = config.getAuthFor(imageRef.getRegistryName()); if (auth != null) { String[] credentials = new String(Base64.getDecoder().decode(auth), StandardCharsets.UTF_8).split(":"); client.register(HttpAuthenticationFeature.basicBuilder().credentials(credentials[0], credentials[1])); } WebTarget webTarget = client.target(imageRef.getRegistryUrl()); webTargets.put(imageRef.getRegistryUrl(), webTarget); } return webTargets.get(imageRef.getRegistryUrl()); }
private Client newHttpClient() { final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder() .credentials(username, password).build(); final ClientConfig clientConfig = new ClientConfig(); clientConfig.register(feature); return ClientBuilder.newClient(clientConfig); }
.credentials(defaultUser, defaultUserPassword) .build();
protected JsonClient(final RemoteService remote) { this.remote = Objects.requireNonNull(remote, "The remote parameter is null"); final ClientConfig clientConfig = new ClientConfig(); clientConfig.register(JacksonJsonProvider.class).register(JacksonSmileProvider.class); if (remote.isCredential()) { final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder() .nonPreemptive() .credentials(remote.username, remote.password) .build(); clientConfig.register(feature); } final int timeout = remote.timeout != null ? remote.timeout : DEFAULT_TIMEOUT; client = ClientBuilder.newClient(clientConfig); client.property(ClientProperties.CONNECT_TIMEOUT, timeout); client.property(ClientProperties.READ_TIMEOUT, timeout); }
HttpAuthenticationFeature httpAuthenticationFeature() { return HttpAuthenticationFeature .basicBuilder() .credentials("api", apiKey()) .build(); } }
private void setupClient() { HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder() .credentials(username, password).build(); ClientConfig clientConfig = new ClientConfig(); clientConfig.register(feature); clientConfig.register(JsonToMapProvider.class); client = ClientBuilder.newClient(clientConfig); }