string - Grails中的字符串不是字符串吗?

标签 string grails

这个错误无数次发生在我身上,通常我会找到一种不使用Strings的方法,但这令人难以置信。

时常发生这样的错误:

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]"



我正在使用的代码如下所示:
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''')

基本上就像每个字符串变量都立即变成存储在字符串中的值一样……但是您实际上如何使用字符串变量呢?

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

最佳答案

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

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

我在ifAllGranted类上看不到SpringSecurityService。我相信它在SpringSecurity的较早版本(即Acegi)中曾经存在。

尝试使用SpringSecurityUtils.ifAllGranted代替springSecurityService。如果您对它的工作方式感兴趣,请使用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));
    }

关于string - Grails中的字符串不是字符串吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6060052/

相关文章:

javascript - 使用 Grails findByAll() 数组进行 jQuery 自动完成

jsf - 带有 GSP 或 JSF 的 Grails

c# - 计算字符串在不将其保存到磁盘的情况下占用的磁盘空间

c++ - 在这种情况下,Win32 错误代码 122 是否有点良性?

python - 从索引开始遍历 python 字符串

oracle - 保存Grails域对象时如何选择oracle current_timestamp

security - Grails项目登录插件

google-maps - Grails-从lat,lang找到位置

java - 如何确定空格中制表符的大小?

Python elementtree 很难提取数据