javax.ws.rs.client.ClientBuilder.keyStore()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中javax.ws.rs.client.ClientBuilder.keyStore()方法的一些代码示例,展示了ClientBuilder.keyStore()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClientBuilder.keyStore()方法的具体详情如下:
包路径:javax.ws.rs.client.ClientBuilder
类名称:ClientBuilder
方法名:keyStore

ClientBuilder.keyStore介绍

[英]Set the client-side key store. Key store contains client's private keys, and the certificates with their corresponding public keys.

Setting a key store instance resets any #sslContext(javax.net.ssl.SSLContext)value previously specified.

Note that for improved security of working with password data and avoid storing passwords in Java string objects, the #keyStore(java.security.KeyStore,char[]) version of the method can be utilized. Also note that a custom key store is only required if you want to enable a custom setup of a 2-way SSL connections (client certificate authentication).
[中]设置客户端密钥存储。密钥存储包含客户端的私钥和证书及其相应的公钥。
设置密钥存储实例将重置以前指定的任何#sslContext(javax.net.ssl.sslContext)值。
请注意,为了提高使用密码数据的安全性并避免将密码存储在Java字符串对象中,可以使用该方法的#keyStore(Java.security.keyStore,char[])版本。还请注意,仅当您希望启用双向SSL连接(客户端证书身份验证)的自定义设置时,才需要自定义密钥存储。

代码示例

代码示例来源:origin: org.apache.geronimo.specs/geronimo-jaxrs_2.1_spec

public ClientBuilder keyStore(final KeyStore keyStore, final String password) {
  return keyStore(keyStore, password.toCharArray());
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-jaxrs_2.0_spec

public ClientBuilder keyStore(final KeyStore keyStore, final String password) {
  return keyStore(keyStore, password.toCharArray());
}

代码示例来源:origin: org.apache.aries.spec/org.apache.aries.javax.jax.rs-api

public ClientBuilder keyStore(final KeyStore keyStore, final String password) {
  return keyStore(keyStore, password.toCharArray());
}

代码示例来源:origin: apache/meecrowave

public ClientBuilder keyStore(final KeyStore keyStore, final String password) {
  return keyStore(keyStore, password.toCharArray());
}

代码示例来源:origin: org.apache.meecrowave/meecrowave-specs-api

public ClientBuilder keyStore(final KeyStore keyStore, final String password) {
  return keyStore(keyStore, password.toCharArray());
}

代码示例来源:origin: org.jboss.spec.javax.ws.rs/jboss-jaxrs-api_2.0_spec

/**
 * Set the client-side key store. Key store contains client's private keys, and the certificates with their
 * corresponding public keys.
 * <p>
 * Setting a key store instance resets any {@link #sslContext(javax.net.ssl.SSLContext) SSL context instance}
 * value previously specified.
 * </p>
 * <p>
 * Note that for improved security of working with password data and avoid storing passwords in Java string
 * objects, the {@link #keyStore(java.security.KeyStore, char[])} version of the method can be utilized.
 * Also note that a custom key store is only required if you want to enable a custom setup of a 2-way SSL
 * connections (client certificate authentication).
 * </p>
 *
 * @param keyStore client-side key store. Must not be {@code null}.
 * @param password client key password. Must not be {@code null}.
 * @return an updated client builder instance.
 * @throws NullPointerException in case any of the supplied parameters is {@code null}.
 * @see #sslContext
 * @see #keyStore(java.security.KeyStore, char[])
 * @see #trustStore
 */
public ClientBuilder keyStore(final KeyStore keyStore, final String password) {
  return keyStore(keyStore, password.toCharArray());
}

代码示例来源:origin: javax/javaee-web-api

/**
 * Set the client-side key store. Key store contains client's private keys, and the certificates with their
 * corresponding public keys.
 * <p>
 * Setting a key store instance resets any {@link #sslContext(javax.net.ssl.SSLContext) SSL context instance}
 * value previously specified.
 * </p>
 * <p>
 * Note that for improved security of working with password data and avoid storing passwords in Java string
 * objects, the {@link #keyStore(java.security.KeyStore, char[])} version of the method can be utilized.
 * Also note that a custom key store is only required if you want to enable a custom setup of a 2-way SSL
 * connections (client certificate authentication).
 * </p>
 *
 * @param keyStore client-side key store. Must not be {@code null}.
 * @param password client key password. Must not be {@code null}.
 * @return an updated client builder instance.
 * @throws NullPointerException in case any of the supplied parameters is {@code null}.
 * @see #sslContext
 * @see #keyStore(java.security.KeyStore, char[])
 * @see #trustStore
 */
public ClientBuilder keyStore(final KeyStore keyStore, final String password) {
  return keyStore(keyStore, password.toCharArray());
}

代码示例来源:origin: com.github.jmnarloch/spring-jax-rs-client-proxy

/**
 * Registers the key store to be used.
 *
 * @param keyStore the key store
 * @param password the password
 * @return the builder instance
 */
public ClientBuilderConfigurer keyStore(KeyStore keyStore, char[] password) {
  builder().keyStore(keyStore, password);
  return this;
}

代码示例来源:origin: com.github.jmnarloch/spring-jax-rs-client-proxy

/**
 * Registers the key store to be used.
 *
 * @param keyStore the key store
 * @param password the password
 * @return the builder instance
 */
public ClientBuilderConfigurer keyStore(KeyStore keyStore, String password) {
  builder().keyStore(keyStore, password);
  return this;
}

代码示例来源:origin: symphonyoss/symphony-java-client

/**
 * Create custom client with specific keystore.  This ignores the need for a truststore.
 *
 * @param clientKeyStore     Client (BOT) keystore file
 * @param clientKeyStorePass Client (BOT) keystore password
 * @return Custom HttpClient
 * @throws Exception Generally IOExceptions thrown from instantiation.
 */
public static Client getClient(String clientKeyStore, String clientKeyStorePass) throws Exception {
  KeyStore cks = KeyStore.getInstance("PKCS12");
  loadKeyStore(cks, clientKeyStore, clientKeyStorePass);
  return ClientBuilder.newBuilder().keyStore(cks, clientKeyStorePass.toCharArray()).build();
}

代码示例来源:origin: org.symphonyoss.symphony/symphony-client

/**
 * Create custom client with specific keystore.  This ignores the need for a truststore.
 *
 * @param clientKeyStore     Client (BOT) keystore file
 * @param clientKeyStorePass Client (BOT) keystore password
 * @return Custom HttpClient
 * @throws Exception Generally IOExceptions thrown from instantiation.
 */
public static Client getClient(String clientKeyStore, String clientKeyStorePass) throws Exception {
  KeyStore cks = KeyStore.getInstance("PKCS12");
  loadKeyStore(cks, clientKeyStore, clientKeyStorePass);
  return ClientBuilder.newBuilder().keyStore(cks, clientKeyStorePass.toCharArray()).build();
}

代码示例来源:origin: symphonyoss/symphony-java-client

/**
 * Create custom client with specific keystore.  This ignores the need for a truststore.
 *
 * @param clientKeyStore     Client (BOT) keystore file
 * @param clientKeyStorePass Client (BOT) keystore password
 * @param clientConfig       Client configuration to use when initializing client
 * @return Custom HttpClient
 * @throws Exception Generally IOExceptions thrown from instantiation.
 */
public static Client getClient(String clientKeyStore, String clientKeyStorePass, ClientConfig clientConfig) throws Exception {
  KeyStore cks = KeyStore.getInstance("PKCS12");
  loadKeyStore(cks, clientKeyStore, clientKeyStorePass);
  return ClientBuilder.newBuilder().keyStore(cks, clientKeyStorePass.toCharArray()).withConfig(clientConfig).build();
}

代码示例来源:origin: org.symphonyoss.symphony/symphony-client

/**
 * Create custom client with specific keystore.  This ignores the need for a truststore.
 *
 * @param clientKeyStore     Client (BOT) keystore file
 * @param clientKeyStorePass Client (BOT) keystore password
 * @param clientConfig       Client configuration to use when initializing client
 * @return Custom HttpClient
 * @throws Exception Generally IOExceptions thrown from instantiation.
 */
public static Client getClient(String clientKeyStore, String clientKeyStorePass, ClientConfig clientConfig) throws Exception {
  KeyStore cks = KeyStore.getInstance("PKCS12");
  loadKeyStore(cks, clientKeyStore, clientKeyStorePass);
  return ClientBuilder.newBuilder().keyStore(cks, clientKeyStorePass.toCharArray()).withConfig(clientConfig).build();
}

代码示例来源:origin: org.symphonyoss.symphony/symphony-client

/**
 * Create custom client with specific keystores.
 *
 * @param clientKeyStore     Client (BOT) keystore file
 * @param clientKeyStorePass Client (BOT) keystore password
 * @param trustStore         Truststore file
 * @param trustStorePass     Truststore password
 * @return Custom HttpClient
 * @throws Exception Generally IOExceptions thrown from instantiation.
 */
public static Client getClient(String clientKeyStore, String clientKeyStorePass, String trustStore, String trustStorePass) throws Exception {
  KeyStore cks = KeyStore.getInstance("PKCS12");
  KeyStore tks = KeyStore.getInstance("JKS");
  loadKeyStore(cks, clientKeyStore, clientKeyStorePass);
  loadKeyStore(tks, trustStore, trustStorePass);
  return ClientBuilder.newBuilder().keyStore(cks, clientKeyStorePass.toCharArray()).trustStore(tks).build();
}

代码示例来源:origin: org.symphonyoss.symphony/symphony-client

/**
 * Create custom client with specific keystores.
 *
 * @param clientKeyStore     Client (BOT) keystore
 * @param clientKeyStorePass Client (BOT) keystore password
 * @param trustStore         Truststore
 * @param trustStorePass     Truststore password
 * @param clientConfig       - HttpClient configuration to use when constructing the client
 * @return Custom HttpClient
 * @throws Exception Generally IOExceptions thrown from instantiation.
 */
public static Client getClient(KeyStore clientKeyStore, String clientKeyStorePass, KeyStore trustStore, String trustStorePass, ClientConfig clientConfig) throws Exception {
  return ClientBuilder.newBuilder().keyStore(clientKeyStore, clientKeyStorePass.toCharArray()).trustStore(trustStore).withConfig(clientConfig).build();
}

代码示例来源:origin: symphonyoss/symphony-java-client

/**
 * Create custom client with specific keystores.
 *
 * @param clientKeyStore     Client (BOT) keystore
 * @param clientKeyStorePass Client (BOT) keystore password
 * @param trustStore         Truststore
 * @param trustStorePass     Truststore password
 * @param clientConfig       - HttpClient configuration to use when constructing the client
 * @return Custom HttpClient
 * @throws Exception Generally IOExceptions thrown from instantiation.
 */
public static Client getClient(KeyStore clientKeyStore, String clientKeyStorePass, KeyStore trustStore, String trustStorePass, ClientConfig clientConfig) throws Exception {
  return ClientBuilder.newBuilder().keyStore(clientKeyStore, clientKeyStorePass.toCharArray()).trustStore(trustStore).withConfig(clientConfig).build();
}

代码示例来源:origin: symphonyoss/symphony-java-client

/**
 * Create custom client with specific keystores.
 *
 * @param clientKeyStore     Client (BOT) keystore file
 * @param clientKeyStorePass Client (BOT) keystore password
 * @param trustStore         Truststore file
 * @param trustStorePass     Truststore password
 * @return Custom HttpClient
 * @throws Exception Generally IOExceptions thrown from instantiation.
 */
public static Client getClient(String clientKeyStore, String clientKeyStorePass, String trustStore, String trustStorePass) throws Exception {
  KeyStore cks = KeyStore.getInstance("PKCS12");
  KeyStore tks = KeyStore.getInstance("JKS");
  loadKeyStore(cks, clientKeyStore, clientKeyStorePass);
  loadKeyStore(tks, trustStore, trustStorePass);
  return ClientBuilder.newBuilder().keyStore(cks, clientKeyStorePass.toCharArray()).trustStore(tks).build();
}

代码示例来源:origin: hopshadoop/hopsworks

public static <T> ClientWrapper<T> httpsInstance(KeyStore keystore, KeyStore truststore,
 String password, HostnameVerifier hostnameVerifier, Class<T> resultClass) {
 Client client = ClientBuilder.newBuilder().trustStore(truststore).keyStore(keystore, password.toCharArray()).
  hostnameVerifier(hostnameVerifier).build();
 return new ClientWrapper(client, resultClass);
}

代码示例来源:origin: org.symphonyoss.symphony.apps/symphony-app-authentication-api

/**
 * Initializes HTTP Client given the application ID.
 *
 * @param appId Application identifier
 * @return HTTP client
 */
private Client initHttpClient(String appId) {
 KeystoreProvider keystoreProvider = keystoreProviderFactory.getComponent();
 KeystoreSettings appKeystore = keystoreProvider.getApplicationKeystore(appId);
 final ClientConfig clientConfig = new ClientConfig();
 clientConfig.property(ClientProperties.CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT);
 clientConfig.property(ClientProperties.READ_TIMEOUT, DEFAULT_READ_TIMEOUT);
 return clientBuilder.withConfig(clientConfig)
   .keyStore(appKeystore.getData(), appKeystore.getPassword())
   .build();
}

代码示例来源:origin: apache/cxf

@Test
public void testGetBook() throws Exception {
  ClientBuilder builder = ClientBuilder.newBuilder();
  try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", this.getClass())) {
    KeyStore trustStore = loadStore(keystore, "password");
    builder.trustStore(trustStore);
  }
  builder.hostnameVerifier(new AllowAllHostnameVerifier());
  try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Morpit.jks", this.getClass())) {
    KeyStore keyStore = loadStore(keystore, "password");
    builder.keyStore(keyStore, "password");
  }
  Client client = builder.build();
  client.register(new LoggingFeature());
  WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123");
  Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class);
  assertEquals(123, b.getId());
}

相关文章