views:

105

answers:

3

Hello all,

I'm trying to build a Grails application which can do LDAP lookups. I've been following a few guides (link text and some others) but to no end I'm afraid.

Relevant source code: From config.groovy:

ldap {
directories    { 
    dir1 {
        url = "ldap://dc01"
        base = "ou=someou,dc=check,dc=nl"
        userDn = "cn=Administrator,cn=Users,dc=check,dc=nl"
        password = "wowthisisnothepassword"
    }
}

schemas = [
    ldapclient.GldapoSchemaClassForUser
]}

My domainclass:

package ldapclient
import gldapo.schema.annotation.GldapoNamingAttribute
import gldapo.schema.annotation.GldapoSynonymFor
import gldapo.schema.annotation.GldapoSchemaFilter

@GldapoSchemaFilter("(objectclass=person)")
class GldapoSchemaClassForUser {
   @GldapoNamingAttribute
   String uid

   @GldapoSynonymFor("cn")
   String name

   @GldapoSynonymFor("mail")
   String email

   @GldapoSynonymFor("uid")
   String username

   @GldapoSynonymFor("fullname")
   String fullName
}

And my controller:

package ldapclient

class AdController {
def defaultAction = "list"

List matches = GldapoSchemaClassForUser.findAll(
    filter: "(name=s*)"
)

def list = {
    [ "adMatches" : matches.list() ]
}}

Although my program conforms (for as far as I can tell) to what should work according to the many documents, I cannot run this. The error thrown:

Caused by: groovy.lang.MissingMethodException: No signature of method: static ldapclient.GldapoSchemaClassForUser.findAll() is applicable for argument types: (java.util.LinkedHashMap) values: [[filter:(name=s)]] at ldapclient.AdController.(AdController.groovy:6)*

Any clues what's going on / wrong? I'm on Grails 1.2.3 and using the most current version of the LDAP plugin. The project is clean (freshly created).

Thanks in advance!

+3  A: 

According to documentation, findAll method has only this definitions (where Book - is sample domain class):

Book.findAll()
Book.findAll( String query )
Book.findAll( String query, Collection positionalParams )
Book.findAll( String query, Collection positionalParams, Map paginateParams )
Book.findAll( String query, Map namedParams )
Book.findAll( String query, Map namedParams, Map paginateParams )
Book.findAll( Book example )

And your code:

List matches = GldapoSchemaClassForUser.findAll(
    filter: "(name=s*)"
)

Could be rewritten as:

List matches = GldapoSchemaClassForUser.findAllByNameLike("s%")

Or use criteria definition:

List matches = GldapoSchemaClassForUser.list() {
     like("name","s%")
}

To use filters - look at Hibernate-filter plugin

Olexandr
The Gldapp schema classes are not grails/hibernate domain classes so they don't have the same conventions. There is a DSL for the find and findAll (http://gldapo.codehaus.org/schemaclasses/searching.html), so the findAll(filter: "...") *should* be valid.
Chris
A: 

Where are your schema classes located? I have this plugin working fine (albeit with Grails 1.3.4). Note that your link to the plugin is an old-ish page. Here is the latest I believe: Grails LDAP Plugin.

Don't think there's much difference other than it looks like you can drop schema classes in the grails-app/ldap directory instead of having to specify them in Config - I do it the same way as you with schemas specified in the config, but might be worth trying them in the grails-app/ldap folder?

Chris
A: 

Thanks for the response; I just upgraded to Grails 1.3.4 and moved some files around. This did some good, though I still get this nasty error:

Error creating bean with name 'ldapclient.AdController': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [ldapclient.AdController]: Constructor threw exception; nested exception is groovy.lang.MissingMethodException: No signature of method: static ldapclient.GldapoSchemaClassForUser.findAll() is applicable for argument types: (java.util.LinkedHashMap) values: [[directory:dir1, filter:(uid=myname,ou=st,ou=ouou,dc=dc,dc=dcdc)]] Possible solutions: findAll(groovy.lang.Closure), find(groovy.lang.Closure)
RajDee