Mauli
Mauli

Reputation: 17203

Is there a standalone Java library which provides LDAP style parsing?

I'm looking for a standalone Java library which allows me to parse LDAP style filter expressions Is such thing available, or is it advisable to use ANTLR instead and build it by one self?

As background: the filter itself is submitted through a network, and I want to create say, the appropriate hibernate Criteria. I'm not doing anything with LDAP!

Any other ideas for a technology independent solution to transfer and transform user defined queries are also appreciated.

Upvotes: 3

Views: 3912

Answers (7)

dhalbrook
dhalbrook

Reputation: 11

OpenDS has a static method on a class called LDAPFilter called, simply, decode, which takes a string argument, like so:

LDAPFilter parsed = LDAPFilter.decode(filter);

The javadoc is here.

It's very similar to Apache DS's FilterParser, though working with the result is a little different as there's no real substantial inheritance hierarchy. One advantage I found was that it didn't rewrite extensible matching rule syntax, so if you're looking at this as a way to validate and normalize filters that's something to keep in mind.

A caveat is that both parsers expect whitespace to be filtered out beforehand, so make sure you run something like this on any input string beforehand:

filter.replaceAll("\\s?([\\(\\|&!=:\\)])\\s?", "$1");

Hope this helps.

Upvotes: 1

pmf
pmf

Reputation: 7759

Most OSGi containers also contain this functionality, since these kinds of filters are part of the OSGi specification.

Upvotes: 0

lexicalscope
lexicalscope

Reputation: 7328

You can use the apache directory server's shared LDAP library.

It is available in maven at

<dependency>
  <groupId>org.apache.directory.shared</groupId>
  <artifactId>shared-ldap</artifactId>
  <version>0.9.15</version>
</dependency>

And you can use it like:

final ExprNode filter = FilterParser.parse(filterString);

Upvotes: 2

phatmanace
phatmanace

Reputation: 5031

to clarify, are you set on them being LDAP syle queries, if you're not trying to query ldap.

have you looked at something like this?

http://josql.sourceforge.net/

Upvotes: 0

Ga&#235;l Marziou
Ga&#235;l Marziou

Reputation: 16294

You could also look at using Apache directory server either for using some of its classes like lavinio's suggestion for OpenLDAP or to embed it as part of your application.

Upvotes: 1

lavinio
lavinio

Reputation: 24329

Have you looked at jldap, as part of OpenLDAP?

The source is available, and there are classes for parsing both LDAP URLs and search expressions. It's more than you need, but you might be able to use just the objects without actually executing them against an LDAP server, if that's what you want to do.

Upvotes: 0

Jacob Adams
Jacob Adams

Reputation: 4004

The only LDAP parsing library I know of are the .NET ones System.DirectoryServices.* In theory you should be able to use this library in Mono to get technology independence (other than from mono or .net itself).

Upvotes: 0

Related Questions