You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Jess Johnson <je...@gmail.com> on 2013/03/29 06:19:07 UTC
Retrieving binary data from LDAP server using Groovy
I'm having difficulty retrieving binary data from an OpenLDAP server and
was hoping someone could point me in the right direction. I read on the
message board that binary data comes back as incomplete or corrupted unless
the client specifies what attribute is binary.
I wrote similar functionality in another language to test and everything
worked as expected. I'm able to retrieve all other values (Strings) except
binary data.
def ldap = org.apache.directory.groovyldap.LDAP.newInstance('ldap://
some.server.com/ou=People,o=Acme')
ldap.eachEntry (filter: 'id=1234567') { entry ->
def image = entry.image.getBytes()
new File('/var/dir/something.jpg').withOutputStream {
it.write image
}
}
Where would I specify the attribute "image" is binary?
Thanks,
Jess
Re: Retrieving binary data from LDAP server using Groovy
Posted by Jess Johnson <je...@gmail.com>.
Hi Stefan,
Thank you for your help, it worked!
For those people that come across this problem in a Grails project, here's
the steps to set a specific entry to binary format.
1. Create a new properties file call "jndi.properties" and add it to your
grails-app/conf directory (all property files in this folder are
automatically included in the classpath)
2. Add a line in the properties file with the name of the image variable:
java.naming.ldap.attributes.binary=some_custom_image
3. Save the file and run the Grails application
4. Here is some sample code to save a binary entry to a file:
def ldap = org.apache.directory.groovyldap.LDAP.newInstance('ldap://
some.server.com/ou=People,o=Acme')
ldap.eachEntry (filter: 'id=1234567') { entry ->
def image = entry.image
new File('/var/dir/something.jpg').withOutputStream {
it.write image
}
}
On Mon, Apr 1, 2013 at 7:55 AM, Stefan Zoerner <st...@labeo.de> wrote:
> Hi Jess!
>
> The problem here is that that Groovy LDAP uses JNDI under the hood. The
> same probem would occur with JNDI.
> See: http://docs.oracle.com/javase/jndi/tutorial/ldap/misc/attrs.html (to
> be more precise: "Specifying Additional Nonstring Attributes")
>
> Groovy LDAP works fine with binary attributes which are binary for JNDI by
> default (e.g. jpegphoto). "image" is not in the list, you have to add it
> manually.
> In JNDI, you would set a property to specify which attributes are binary:
>
> ...
> env.put("java.naming.ldap.attributes.binary", "image");
> ...
> Later create JNDI InitialContext with env
>
> The problem is that LDAP Groovy hides the creation of both the env and
> InitialContexts.
>
> I see two (fast) options:
> a) change Groovy LDAP source by yourself and add the env property in class
> LDAP (file LDAP.java, method createEnvironment())
> b) add a jndi.properties file to the classpath, which would be mixed with
> the env Groovy LDAP uses
>
> content of the file for b) only one line:
>
> java.naming.ldap.attributes.binary=image
>
> Please let me know if workaround b) works for you, or if you need more
> help.
> We can add a feature to Groovy LDAP for that, which would make perfect
> sense to me.
>
> Greetings from Hamburg,
> StefanZ
>
>
>
>
> Am 29.03.2013 06:19, schrieb Jess Johnson:
>
> I'm having difficulty retrieving binary data from an OpenLDAP server and
> was hoping someone could point me in the right direction. I read on the
> message board that binary data comes back as incomplete or corrupted unless
> the client specifies what attribute is binary.
>
> I wrote similar functionality in another language to test and everything
> worked as expected. I'm able to retrieve all other values (Strings) except
> binary data.
>
> def ldap = org.apache.directory.groovyldap.LDAP.newInstance('ldap://
> some.server.com/ou=People,o=Acme')
> ldap.eachEntry (filter: 'id=1234567') { entry ->
>
> def image = entry.image.getBytes()
>
> new File('/var/dir/something.jpg').withOutputStream {
> it.write image
> }
> }
>
> Where would I specify the attribute "image" is binary?
>
> Thanks,
> Jess
>
>
>
Re: Retrieving binary data from LDAP server using Groovy
Posted by Stefan Zoerner <st...@labeo.de>.
Hi Jess!
The problem here is that that Groovy LDAP uses JNDI under the hood. The
same probem would occur with JNDI.
See: http://docs.oracle.com/javase/jndi/tutorial/ldap/misc/attrs.html
(to be more precise: "Specifying Additional Nonstring Attributes")
Groovy LDAP works fine with binary attributes which are binary for JNDI
by default (e.g. jpegphoto). "image" is not in the list, you have to add
it manually.
In JNDI, you would set a property to specify which attributes are binary:
...
env.put("java.naming.ldap.attributes.binary", "image");
...
Later create JNDI InitialContext with env
The problem is that LDAP Groovy hides the creation of both the env and
InitialContexts.
I see two (fast) options:
a) change Groovy LDAP source by yourself and add the env property in
class LDAP (file LDAP.java, method createEnvironment())
b) add a jndi.properties file to the classpath, which would be mixed
with the env Groovy LDAP uses
content of the file for b) only one line:
java.naming.ldap.attributes.binary=image
Please let me know if workaround b) works for you, or if you need more help.
We can add a feature to Groovy LDAP for that, which would make perfect
sense to me.
Greetings from Hamburg,
StefanZ
Am 29.03.2013 06:19, schrieb Jess Johnson:
> I'm having difficulty retrieving binary data from an OpenLDAP server
> and was hoping someone could point me in the right direction. I read
> on the message board that binary data comes back as incomplete or
> corrupted unless the client specifies what attribute is binary.
>
> I wrote similar functionality in another language to test and
> everything worked as expected. I'm able to retrieve all other values
> (Strings) except binary data.
>
> def ldap =
> org.apache.directory.groovyldap.LDAP.newInstance('ldap://some.server.com/ou=People,o=Acme
> <http://some.server.com/ou=People,o=Acme>')
> ldap.eachEntry (filter: 'id=1234567') { entry ->
> def image = entry.image.getBytes()
> new File('/var/dir/something.jpg').withOutputStream {
> it.write image
> }
> }
>
> Where would I specify the attribute "image" is binary?
>
> Thanks,
> Jess