开发者

String in grails aren't strings?

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


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));
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜