public void setupAuthenticationCredentials(final String userName, final String password) { final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic( Objects.requireNonNull(userName), Objects.requireNonNull(password) ); client.register(feature); }
private ClientConfig _setCredentials(String userId, String password) { HttpAuthenticationFeature httpAuthenticationFeature = HttpAuthenticationFeature.basic(userId, password); ClientConfig clientConfig = new ClientConfig(); clientConfig.register(httpAuthenticationFeature); return clientConfig; }
@Override public void setConf(Configuration conf) { super.setConf(conf); if (conf == null) { // Configured gets passed null before real conf. Why? I don't know. return; } serverHostname = conf.get(REST_API_CLUSTER_MANAGER_HOSTNAME, DEFAULT_SERVER_HOSTNAME); serverUsername = conf.get(REST_API_CLUSTER_MANAGER_USERNAME, DEFAULT_SERVER_USERNAME); serverPassword = conf.get(REST_API_CLUSTER_MANAGER_PASSWORD, DEFAULT_SERVER_PASSWORD); clusterName = conf.get(REST_API_CLUSTER_MANAGER_CLUSTER_NAME, DEFAULT_CLUSTER_NAME); // Add filter to Client instance to enable server authentication. client.register(HttpAuthenticationFeature.basic(serverUsername, serverPassword)); }
client.property(ClientProperties.CONNECT_TIMEOUT, 2000) .register(new MoxyJsonFeature()) .register(HttpAuthenticationFeature.basic(App.getTwitterUserName(), App.getTwitterUserPassword())) .register(GZipEncoder.class);
private static Client initializeClient(DirectoryServerConfiguration directoryServerConfiguration) throws CertificateException { KeyStore trustStore = initializeKeyStore(directoryServerConfiguration.getReplicationCaCertificate()); SSLContext sslContext = SslConfigurator.newInstance() .securityProtocol("TLSv1.2") .trustStore(trustStore) .createSSLContext(); return ClientBuilder.newBuilder() .register(HttpAuthenticationFeature.basic("signal", directoryServerConfiguration.getReplicationPassword().getBytes())) .sslContext(sslContext) .build(); }
public HttpAuthenticationFeature getHttpAuthenticationFeature() { if (username == null) { return null; } return HttpAuthenticationFeature.basic(username, password); }
public Fetcher(String user, String password, String repoOwner, String repoName) { auth = HttpAuthenticationFeature.basic(user, password); this.repoName = repoName; this.repoOwner = repoOwner; }
@Override public void setAuthentcation(String userName, String password) { HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(userName, password); _client.register(feature); }
private void authenticate(Client client, String username, String password) { client.register(HttpAuthenticationFeature.basic(username, password)); }
private static ClientConfig buildConfigWithBasicAuth(String username, String password, int timeout) { ClientConfig config = buildConfig(timeout); /* * NOTE: don't use non-preemptive mode * In non-preemptive mode the authentication information is added * only when server refuses the request with 401 status code and * then the request is repeated. * Non-preemptive has negative impact on the performance. The advantage * is that it does not send credentials when they are not needed. * https://jersey.github.io/documentation/latest/client.html#d0e5461 */ config.register(HttpAuthenticationFeature.basic(username, password)); return config; }
public RestClient(String host, int port, boolean useSsl, String user, String password) { this.host = host; this.port = port; this.useSsl = useSsl; client = ClientBuilder.newClient(); client.register(new CsrfProtectionFilter()); if(user != null) { client.register(HttpAuthenticationFeature.basic(user, password)); } }
private Builder getInvocationBuilder() throws Exception { Client client = customizeClient(ClientBuilder.newClient()); client.register(HttpAuthenticationFeature.basic(getUserName(), getPassword())); WebTarget target = client.target(getUrl()); for (Map.Entry<String, String> e : getQueryParams().entrySet()) { target = target.queryParam(e.getKey(), e.getValue()); } return target.request(getResponseBodyMediaType()).header("X-Include-Resource-Links", "true").header("X-Requested-By", "MyClient"); }
public JerseyClient( final String apiKey, final Integer timeout ) { ClientConfig configuration = new ClientConfig(); if( timeout != null ) { configuration.property( ClientProperties.CONNECT_TIMEOUT, timeout ); configuration.property( ClientProperties.READ_TIMEOUT, timeout ); } this.httpClient = ClientBuilder.newClient( configuration ); HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basic( apiKey, StringUtils.EMPTY ); this.httpClient.register( authFeature ); }
public Client restClient() { return ClientBuilder.newBuilder() .register(HttpAuthenticationFeature.basic(username, password)) .property(ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE) .build(); }
@Override public void setConf(Configuration conf) { super.setConf(conf); if (conf == null) { // Configured gets passed null before real conf. Why? I don't know. return; } serverHostname = conf.get(REST_API_CLUSTER_MANAGER_HOSTNAME, DEFAULT_SERVER_HOSTNAME); serverUsername = conf.get(REST_API_CLUSTER_MANAGER_USERNAME, DEFAULT_SERVER_USERNAME); serverPassword = conf.get(REST_API_CLUSTER_MANAGER_PASSWORD, DEFAULT_SERVER_PASSWORD); clusterName = conf.get(REST_API_CLUSTER_MANAGER_CLUSTER_NAME, DEFAULT_CLUSTER_NAME); // Add filter to Client instance to enable server authentication. client.register(HttpAuthenticationFeature.basic(serverUsername, serverPassword)); }
public SwingAdminApp() { Configuration httpClientConfig = new ClientConfig(); ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(httpClientConfig); client = clientBuilder.build(); // Credentials for the Admin API client.register(HttpAuthenticationFeature.basic("admin", "Testing123")); }
/** * Returns a new Views Service client */ public ViewsService getViewService(CIMInstance instance) throws MalformedURLException, NoSuchAlgorithmException, KeyManagementException { URL baseUrl = getURL(instance); Client restClient = null; if (instance.isUseSSL()){ SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, null, new SecureRandom()); restClient = ClientBuilder.newBuilder() .sslContext(sslContext) .hostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()) .build(); } else { restClient = ClientBuilder.newClient(); } HttpAuthenticationFeature httpAuthenticationFeature = HttpAuthenticationFeature.basic(instance.getCoverityUser(), instance.getCoverityPassword()); restClient.register(httpAuthenticationFeature); return new ViewsService(baseUrl, restClient); }
/** * Creates a HTTP Jersey REST {@link Client} configured to authenticate (via * <a href="http://en.wikipedia.org/wiki/Basic_access_authentication">Basic * authentication<a/>) with a given user name and password. * * @param userName * The user name used to authenticate. * @param password * The password used to authenticate. * @return The created {@link Client}. */ public static Client httpBasicAuth(String userName, String password) { Client client = ClientBuilder.newBuilder().register(GsonMessageBodyReader.class) .register(GsonMessageBodyWriter.class).build(); client.register(HttpAuthenticationFeature.basic(userName, password)); return client; }
private static Client createClient(String httpAuthenticationUser, String httpAuthenticationPassword) { ClientConfig cc = new ClientConfig().register(new JacksonFeature()); Client client = ClientBuilder.newBuilder().withConfig(cc).build(); client.register(GZipEncoder.class); client.register(EncodingFilter.class); client.register(DeflateEncoder.class); if (!Strings.isNullOrEmpty(httpAuthenticationUser) && !Strings.isNullOrEmpty(httpAuthenticationPassword) ){ client.register(HttpAuthenticationFeature.basic(httpAuthenticationUser, httpAuthenticationPassword)); } JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(ObjectMapperBuilder.buildNewObjectMapper()); client.register(provider); return client; }
public ClientWrapper(final Map<String, String> headers, String userName, String password) { realClient = JerseyClientBuilder.newClient(); realClient.register(new MultiPartFeature()); realClient.register(new JettisonFeature()); realClient.register(new CsrfProtectionFilter()); if ((userName != null) && (password != null)) { realClient.register(HttpAuthenticationFeature.basic(userName, password)); } realClient.register(new ClientRequestFilter() { @Override public void filter(ClientRequestContext rc) throws IOException { for (Map.Entry<String, String> entry : headers.entrySet()) { rc.getHeaders().add(entry.getKey(), entry.getValue()); } } }); }