You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@directory.apache.org by Christos Papoulas <pa...@gmail.com> on 2016/06/08 11:33:17 UTC

pass certificate to LdapConnectionConfig

Hello list,

Is it possible to pass a certificate file like ssl-cert.pem to the 
LdapConnectionConfig? My sample code right now is:

public static LdapConnection createConnection(String host, int port,
             String user, String pass, boolean useSSL, boolean useSSLv3) 
throws IOException, LdapException {
         LdapConnectionConfig connectionConfig = new LdapConnectionConfig();

         if (host == null || host.isEmpty()) {
             throw new IllegalArgumentException("Hostname is not 
specified");
         }
         if(port <= 0) {
             throw new IllegalArgumentException("The ldap port is not 
valid");
         }
         connectionConfig.setLdapHost(host);
         connectionConfig.setLdapPort(port);

         if(user!= null && user.length() > 0) {
             connectionConfig.setName(user);
         }
         if(pass != null && pass.length() > 0) {
             connectionConfig.setCredentials(pass);
         }
         if(useSSL == true) {
             connectionConfig.setUseSsl(true);
         }
         if(useSSLv3 == true) {
             connectionConfig.setSslProtocol("SSLv3");
         }
         LdapConnection connection = new 
LdapNetworkConnection(connectionConfig);

         connection.connect();
         connection.bind();

         return connection;
}