Thursday, 23 May 2013

ldaptive 1.0 test

ldaptive is a java ldap library which replaces vt-ldap shipped with shibboleth and grouper.

There are some nice surprises, like the handling of the ldap extended operation of Password Modify and Password Policy, used by openldap to check if a user's password is locked or need to be changed.

I have tried a ldapsearch authenticated with SASL TLS/EXTERNAL:

require 'java'
require 'logback-core-1.0.9.jar'
require 'logback-classic-1.0.9.jar'
require 'slf4j-api-1.7.4.jar'
require 'ldaptive-1.0.jar'
import 'org.slf4j.Logger'
import 'org.slf4j.LoggerFactory'
import 'ch.qos.logback.classic.LoggerContext'
import 'ch.qos.logback.core.util.StatusPrinter'
java_import "org.ldaptive.DefaultConnectionFactory"
java_import "org.ldaptive.ConnectionConfig"
java_import "org.ldaptive.SearchOperation"
java_import "org.ldaptive.SearchRequest"
java_import "org.ldaptive.SearchResult"
java_import "org.ldaptive.LdapEntry"
java_import "org.ldaptive.LdapAttribute"
java_import "org.ldaptive.io.ValueTranscoder"
java_import "org.ldaptive.ssl.KeyStoreCredentialConfig"
java_import "org.ldaptive.ssl.SslConfig"
java_import "org.ldaptive.sasl.ExternalConfig"
java_import "org.ldaptive.BindOperation"
java_import "org.ldaptive.BindRequest"
class NoOpStringValueTranscoder
include org.ldaptive.io.ValueTranscoder
def decodeStringValue(string)
string
end
def getType
"a_string".class
end
end
logger = LoggerFactory.getLogger("lsearch")
conn_config = ConnectionConfig.new("ldap://ldap.test.com")
conn_config.setUseStartTLS(true)
cred_config = KeyStoreCredentialConfig.new
cred_config.setKeyStore("file:cluster.keystore")
cred_config.setKeyStorePassword("secret")
conn_config.setSslConfig(SslConfig.new(cred_config))
conn = DefaultConnectionFactory.getConnection(conn_config)
conn.open
bind = BindOperation.new conn
bind.execute(BindRequest.new(ExternalConfig.new))
search = SearchOperation.new(conn)
result = search.execute(
SearchRequest.new("dc=test,dc=com","uid=a_user", "mail", "isMemberOf")
).result
ldap_entry = result.entry
p ldap_entry
p ldap_entry.getDn
ldap_entry.attributes.each do |attr|
puts "#{attr.name} => #{attr.getValues(NoOpStringValueTranscoder.new).join(", ")}"
end
view raw lsearch.rb hosted with ❤ by GitHub

Please note that the private key password (the one you set to create the pkcs12) and the keystore password have to be the same.