Search in sources :

Example 1 with TrustAndStoreTrustManager

use of org.jboss.as.test.manualmode.security.TrustAndStoreTrustManager in project wildfly by wildfly.

the class LdapsInitializer method init.

public static IoFilterChainBuilder init(LdapServer server, TcpTransport transport) throws LdapException {
    SSLContext sslCtx;
    try {
        // Initialize the SSLContext to work with our key managers.
        sslCtx = SSLContext.getInstance("TLS");
        sslCtx.init(server.getKeyManagerFactory().getKeyManagers(), new TrustManager[] { new TrustAndStoreTrustManager() }, new SecureRandom());
    } catch (Exception e) {
        throw new LdapException(I18n.err(I18n.ERR_683), e);
    }
    DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
    SslFilter sslFilter = new SslFilter(sslCtx);
    List<String> cipherSuites = transport.getCipherSuite();
    if ((cipherSuites != null) && !cipherSuites.isEmpty()) {
        sslFilter.setEnabledCipherSuites(cipherSuites.toArray(new String[cipherSuites.size()]));
    }
    sslFilter.setWantClientAuth(true);
    // The protocols
    List<String> enabledProtocols = transport.getEnabledProtocols();
    if ((enabledProtocols != null) && !enabledProtocols.isEmpty()) {
        sslFilter.setEnabledProtocols(enabledProtocols.toArray(new String[enabledProtocols.size()]));
    } else {
        // Be sure we disable SSLV3
        sslFilter.setEnabledProtocols(new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" });
    }
    // The remaining SSL parameters
    sslFilter.setNeedClientAuth(transport.isNeedClientAuth());
    //sslFilter.setWantClientAuth(transport.isWantClientAuth());
    chain.addLast("sslFilter", sslFilter);
    return chain;
}
Also used : SslFilter(org.apache.mina.filter.ssl.SslFilter) TrustAndStoreTrustManager(org.jboss.as.test.manualmode.security.TrustAndStoreTrustManager) SecureRandom(java.security.SecureRandom) DefaultIoFilterChainBuilder(org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder) SSLContext(javax.net.ssl.SSLContext) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Aggregations

SecureRandom (java.security.SecureRandom)1 SSLContext (javax.net.ssl.SSLContext)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 DefaultIoFilterChainBuilder (org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder)1 SslFilter (org.apache.mina.filter.ssl.SslFilter)1 TrustAndStoreTrustManager (org.jboss.as.test.manualmode.security.TrustAndStoreTrustManager)1