سؤال

Currently have this:

<sec:ifLoggedIn>
     <sec:username/><br/>
     <sec:roles/><br/>
      <g:link controller="logout" action="index">Logout</g:link>
</sec:ifLoggedIn>
<sec:ifNotLoggedIn>
    <h1>Who are you?</h1><br/>
    <g:link controller="login" action="auth">LOGIN</g:link>
</sec:ifNotLoggedIn>

Which gives the error:

Tag [roles] does not exist.   No tag library found for namespace: sec

However when I remove <sec:roles/><br/> it works fine. Why is this? This is only a problem in production, on intellij everything is great.

هل كانت مفيدة؟

المحلول

No tag roles exists in spring security core plugin. If you want to show user roles in the view then you can create your own tag.

class TestTagLib {

    static final namespace = 'myTag'
    def springSecurityService

    def userAuthorities = { attrs ->
        out << springSecurityService.principal.authorities 
        //or out << springSecurityService.authentication.authorities
    }
}

and use it in you view as

<myTag:userAuthorities/>

نصائح أخرى

According to the documentation for the spring security core Grails plugin, there is no tag "roles". That's why it errors. Intellij likely just ignores this tag completely.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top