Value Transcoders
In cases where LDAP attribute values represent concrete Java objects, a ValueTranscoder can be used to convert those types. The ValueTranscoder interface looks like:
public interface ValueTranscoder<T>
{
T decodeStringValue(String value);
T decodeBinaryValue(byte[] value);
String encodeStringValue(T value);
byte[] encodeBinaryValue(T value);
Class<T> getType();
}
Ldaptive provides the following value transcoder implementations:
CertificateValueTranscoder
Provides the ability to read a PEM encoded certificate from an LDAP attribute in order to create a java.security.cert.Certificate
object. Conversely, a java.security.cert.Certificate
can also be written to the directory as a PEM encoded certificate.
SearchOperation search = new SearchOperation(new DefaultConnectionFactory("ldap://directory.ldaptive.org"));
SearchResponse res = search.execute(SearchRequest.builder()
.dn("dc=ldaptive,dc=org")
.filter("(&(givenName=daniel)(sn=fisher))")
.returnAttributes("userCertificate;binary")
.build());
LdapEntry entry = res.getEntry();
Certificate cert = entry.getAttribute("userCertificate;binary").getValue(new CertificateValueTranscoder().decoder());
GeneralizedTimeValueTranscoder
Provides the ability to read a generalized time from an LDAP attribute in order to create a ZonedDateTime
object. Conversely, a ZonedDateTime
can also be written to the directory in generalized time format.
SearchOperation search = new SearchOperation(new DefaultConnectionFactory("ldap://directory.ldaptive.org"));
SearchResponse res = search.execute(SearchRequest.builder()
.dn("dc=ldaptive,dc=org")
.filter("(&(givenName=daniel)(sn=fisher))")
.returnAttributes("modifyTimestamp")
.build());
LdapEntry entry = res.getEntry();
ZonedDateTime modifyTimestamp = entry.getAttribute("modifyTimestamp").getValue(new GeneralizedTimeValueTranscoder().decoder());
UUIDValueTranscoder
Provides the ability to read a generalized time from an LDAP attribute in order to create a ZonedDateTime
object. Conversely, a ZonedDateTime
can also be written to the directory in generalized time format.
SearchOperation search = new SearchOperation(new DefaultConnectionFactory("ldap://directory.ldaptive.org"));
SearchResponse res = search.execute(SearchRequest.builder()
.dn("dc=ldaptive,dc=org")
.filter("(&(givenName=daniel)(sn=fisher))")
.returnAttributes("entryUUID")
.build());
LdapEntry entry = res.getEntry();
UUID modifyTimestamp = entry.getAttribute("entryUUID").getValue(new UUIDValueTranscoder().decoder());