grails 中的字符串不是字符串吗?

发布于 2024-11-08 18:50:45 字数 828 浏览 0 评论 0原文

这个错误在我身上发生过无数次,通常我会找到一种不使用字符串的方法,但这非常令人沮丧。

时不时就会出现这样的错误:

执行控制器的操作[编辑] [edu.drexel.goodwin.events.web.EventController] 引发异常: groovy.lang.MissingMethodException:否 方法签名: grails.plugins.springsecurity.SpringSecurityService.ifAllGranted() 适用于参数类型: (java.lang.String) 值: [ROLE_SUPER_ADMIN]”

我正在使用的代码如下所示:

springSecurityService.ifAllGranted(new String("ROLE_SUPER_ADMIN")) 

我也尝试了以下所有方法均无济于事:

springSecurityService.ifAllGranted("ROLE_SUPER_ADMIN")
springSecurityService.ifAllGranted("""ROLE_SUPER_ADMIN""")
springSecurityService.ifAllGranted('ROLE_SUPER_ADMIN')
springSecurityService.ifAllGranted('''ROLE_SUPER_ADMIN''')

基本上就好像每个字符串变量都立即转换为存储在字符串中的值...但是如何做你真的使用字符串变量吗?

非常感谢你的帮助, -阿萨夫

This error has happened to me countless times, and usually I find a way to not use Strings, but it's incredibly frustrating.

Every now and then an error such as this one occurs:

Executing action [edit] of controller
[edu.drexel.goodwin.events.web.EventController]
caused exception:
groovy.lang.MissingMethodException: No
signature of method:
grails.plugins.springsecurity.SpringSecurityService.ifAllGranted()
is applicable for argument types:
(java.lang.String) values:
[ROLE_SUPER_ADMIN]"

The code I'm using looks like this:

springSecurityService.ifAllGranted(new String("ROLE_SUPER_ADMIN")) 

I've also tried all of the following to no avail:

springSecurityService.ifAllGranted("ROLE_SUPER_ADMIN")
springSecurityService.ifAllGranted("""ROLE_SUPER_ADMIN""")
springSecurityService.ifAllGranted('ROLE_SUPER_ADMIN')
springSecurityService.ifAllGranted('''ROLE_SUPER_ADMIN''')

It's basically as if EVERY string variable is immediately turned into the value stored in the string... but how do you actually use string variables?

Thank you very much for your help,
-Asaf

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

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

发布评论

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

评论(1

三岁铭 2024-11-15 18:50:45

我很确定问题不是字符串问题,而是“错误使用 API”问题。检查文档:

http://burtbeckwith.github.com /grails-spring-security-core/docs/manual/index.html

我在 SpringSecurityService 类上没有看到 ifAllGranted 。我相信它曾经存在于旧版本的 SpringSecurity(即 Acegi)中。

尝试使用 SpringSecurityUtils.ifAllGranted 而不是 springSecurityService 。如果您对它的工作原理感兴趣,请使用来源,卢克。

/**
     * Check if the current user has all of the specified roles.
     * @param roles  a comma-delimited list of role names
     * @return <code>true</code> if the user is authenticated and has all the roles
     */
    public static boolean ifAllGranted(final String roles) {
        Collection<GrantedAuthority> inferred = findInferredAuthorities(getPrincipalAuthorities());
        return inferred.containsAll(parseAuthoritiesString(roles));
    }

Im pretty sure the issue is not a String issue, its a "using the API incorrectly" issue. Check the documentation:

http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/index.html

Im not seeing ifAllGranted on the SpringSecurityService class. I believe it used to be there in older versions of SpringSecurity (i.e. Acegi).

Try using SpringSecurityUtils.ifAllGranted instead of springSecurityService. If you are interested in how it works, use the source, luke.

/**
     * Check if the current user has all of the specified roles.
     * @param roles  a comma-delimited list of role names
     * @return <code>true</code> if the user is authenticated and has all the roles
     */
    public static boolean ifAllGranted(final String roles) {
        Collection<GrantedAuthority> inferred = findInferredAuthorities(getPrincipalAuthorities());
        return inferred.containsAll(parseAuthoritiesString(roles));
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文