Example usage for javax.net.ssl X509KeyManager chooseClientAlias

List of usage examples for javax.net.ssl X509KeyManager chooseClientAlias

Introduction

In this page you can find the example usage for javax.net.ssl X509KeyManager chooseClientAlias.

Prototype

public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket);

Source Link

Document

Choose an alias to authenticate the client side of a secure socket given the public key type and the list of certificate issuer authorities recognized by the peer (if any).

Usage

From source file:de.betterform.connector.http.ssl.BetterFORMKeyStoreManager.java

public String chooseClientAlias(String[] keyType, Principal[] principals, Socket socket) {
    Iterator<X509KeyManager> iterator = this.customX509KeyManagers.iterator();
    while (iterator.hasNext()) {
        X509KeyManager x509KeyManager = iterator.next();
        if (x509KeyManager.chooseClientAlias(keyType, principals, socket) != null) {
            BetterFORMKeyStoreManager.LOGGER.trace(
                    "BetterFORMKeyStoreManager.chooseClientAlias: Found client alias in custom keystore: "
                            + x509KeyManager.toString());
            //Found client alias in a custom keystore return it.
            return x509KeyManager.chooseClientAlias(keyType, principals, socket);
        }/*from  www. j  av a 2s .co m*/
    }

    //Return client alias from JAVA VM keystor or null;
    return javaDefaultKeyManager.chooseClientAlias(keyType, principals, socket);
}

From source file:org.codice.ddf.cxf.SecureCxfClientFactoryTest.java

@Test
public void testAliasSelectorKeyManager() {
    X509KeyManager keyManager = mock(X509KeyManager.class);
    String alias = "testAlias";
    String[] aliases = new String[] { alias };
    when(keyManager.chooseClientAlias(any(), any(), any())).thenReturn(alias);
    when(keyManager.getClientAliases(any(), any())).thenReturn(aliases);

    AliasSelectorKeyManager aliasSelectorKeyManager = new AliasSelectorKeyManager(keyManager, alias);
    String chosenAlias = aliasSelectorKeyManager.chooseClientAlias(new String[] { "x509" }, null, null);
    assertThat(chosenAlias, is(alias));//from  ww  w . j  a  v  a2  s  .c  o  m
}