DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
// Add a ;binary attribute
byte[] newValue = new byte[]
{ 0x00, 0x01, 0x02, 0x03 };
Attributes attrs = new BasicAttributes( "userCertificate;binary", newValue );
ctx.modifyAttributes( RDN_TORI_AMOS, DirContext.ADD_ATTRIBUTE, attrs );
// Search entry an request ;binary attribute
SearchControls sctls = new SearchControls();
sctls.setSearchScope( SearchControls.OBJECT_SCOPE );
sctls.setReturningAttributes( new String[]
{ "userCertificate;binary" } );
String filter = "(objectClass=*)";
String base = RDN_TORI_AMOS;
// Test that ;binary attribute is present
NamingEnumeration<SearchResult> enm = ctx.search( base, filter, sctls );
assertTrue( enm.hasMore() );
while ( enm.hasMore() )
{
SearchResult sr = enm.next();
attrs = sr.getAttributes();
Attribute attr = attrs.get( "userCertificate" );
assertNotNull( attr );
assertTrue( attr.contains( newValue ) );
byte[] certificate = ( byte[] ) attr.get();
assertTrue( Arrays.equals( newValue, certificate ) );
assertEquals( 1, attr.size() );