LDAP - how to select a binary attribute in Java

B

Bud

I'm using an InitialLdapContext object to perform a search on an
entry.

results = ctx.search(searchBase, searchFilter, ctls);

Using the same searchBase and searchFilter, if the ctls
(SearchControls) list of requested attributes are strings the
execution of the search will give me a results with the requested
attribute values. However, when the ctls has a binary attribute, that
attribute appears to be ignored in the results.

In my particular example I'm trying to acquire a "jpegPhoto" attribute
which is already identified as a binary item by the server. I have
tried specifying the attribute as binary using "jpegPhoto;binary" with
no better success. I have also tried insuring a binary object would
be returned by setting

ctls.setReturningObjFlag(true);

with no success.

Can someone suggest what the problem might be or how I might narrow
the problem down? If I use a LDAP browser (jXplorer or LDAP Studio) I
can view the stored jpegPhoto with no problem It appears that only my
program has the problem.

I did discover that jXplorer doesn't use the
javax.naming.ldap.InitialLdapContext to gain access to the server.
Can that be my issue?
 
B

Brandon McCombs

Bud said:
I'm using an InitialLdapContext object to perform a search on an
entry.

results = ctx.search(searchBase, searchFilter, ctls);

Using the same searchBase and searchFilter, if the ctls
(SearchControls) list of requested attributes are strings the
execution of the search will give me a results with the requested
attribute values. However, when the ctls has a binary attribute, that
attribute appears to be ignored in the results.

In my particular example I'm trying to acquire a "jpegPhoto" attribute
which is already identified as a binary item by the server. I have
tried specifying the attribute as binary using "jpegPhoto;binary" with
no better success. I have also tried insuring a binary object would
be returned by setting

ctls.setReturningObjFlag(true);

with no success.

jpegPhoto is one of the default binary attributes that are already
defined in JNDI so you shouldn't have to explicitly tell JNDI that it is
binary. With that said, I specify it for completeness in my code. Also,
specifying it as "jpegPhoto;binary" is incorrect unless the attribute is
literally defined as jpegPhoto;binary in the schema of the directory.
Since it is a standard binary attribute there shouldn't be any reason
for a standard directory server to do that. I know Sun, OpenLDAP, and
ADS do not (and my LDAP GUI client handles binary attributes just fine
with all 3 of those so I know).
Can someone suggest what the problem might be or how I might narrow
the problem down? If I use a LDAP browser (jXplorer or LDAP Studio) I
can view the stored jpegPhoto with no problem It appears that only my
program has the problem.

When you are parsing the attributes and their values from the
SearchResult object you have to put the value of the jpegPhoto attribute
into a byte array (byte[]) in order to properly use it. However, the
attribute will not even be returned if you do not specify it explicitly
(assuming you aren't just telling your directory server to return all
attributes by using the * character). It is also possible to not be
returned if the user you are using to connect to the server does not
have privileges to read jpegPhoto for all the objects that are returned
in the result set. Is jpegPhoto included in the returned attribute set?
I did discover that jXplorer doesn't use the
javax.naming.ldap.InitialLdapContext to gain access to the server.
Can that be my issue?

I don't know what jXplorer is so it's hard to say whether it's your
problem or not. How does that integrate into your code that you are
trying to get working? Is it your code or jXplorer that you are having
problems with?

THat's all I can say for now until I understand your situation more.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top