Grails find / findAll 操作不起作用?

发布于 2024-09-26 06:42:40 字数 2333 浏览 3 评论 0原文

我正在尝试构建一个可以执行 LDAP 查找的 Grails 应用程序。我一直在遵循一些指南(链接文本 和其他一些指南)但恐怕没有尽头。

相关源码: 来自 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
]}

我的域类:

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
}

和我的控制器:

package ldapclient

class AdController {
def defaultAction = "list"

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

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

虽然我的程序符合(据我所知)根据许多文档应该工作的内容,但我无法运行它。抛出的错误:

由以下原因引起:groovy.lang.MissingMethodException:没有方法签名:static ldapclient.GldapoSchemaClassForUser.findAll() 适用于参数类型:(java.util.LinkedHashMap) 值:[[filter:(name =s)]] 在 ldapclient.AdController.(AdController.groovy:6)*

有任何线索发生了什么/错误吗?我使用的是 Grails 1.2.3 并使用最新版本的 LDAP 插件。该项目是干净的(新创建的)。

提前致谢!


感谢您的回复;我刚刚升级到 Grails 1.3.4 并移动了一些文件。这确实有一些好处,但我仍然遇到这个令人讨厌的错误:

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)

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!


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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乖乖哒 2024-10-03 06:42:40

您的架构类位于哪里?我有这个插件工作正常(尽管使用 Grails 1.3.4)。请注意,您的插件链接是一个旧页面。这是我认为的最新版本:Grails LDAP 插件

不要认为有太大区别,除了看起来您可以将架构类放入 grails-app/ldap 目录中,而不必在 Config 中指定它们 - 我的做法与您相同配置中指定的模式,但可能值得在 grails-app/ldap 文件夹中尝试它们?

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?

夏の忆 2024-10-03 06:42:40

根据文档,findAll方法只有这个定义(其中Book - 是示例域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 )

并且您的代码:

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

可以重写为:

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

或使用 条件定义

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

要使用过滤器 - 请查看 Hibernate-filter 插件

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

喵星人汪星人 2024-10-03 06:42:40

我在使用 grails 2.2 和 ldap 插件 0.8.2 的几天里遇到了同样的问题。在深入研究 gldapo 邮件列表存档后,我发现出现这种情况是因为模式类没有注入 gldapo 行为,因此 find/findAll() 方法未正确解析。请参阅此线程 - http://markmail.org/message/v5ulptrxzfoq4ml7

我错过了使用 'import myPkg我的 grails Config.groovy 脚本中的 .SchemaClass' 。

I had the same problem for a couple of days using grails 2.2 with ldap plugin 0.8.2. After digging through the gldapo mailing list archive, I found out that this occurs because the schema class is not injected with Gldapo behavior and hence the find/findAll() methods are not resolved correctly. Refer to this thread - http://markmail.org/message/v5ulptrxzfoq4ml7

I had missed using 'import myPkg.SchemaClass' in my grails Config.groovy script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文