0

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.

Badmiral
  • 1,549
  • 3
  • 35
  • 74

2 Answers2

3

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/>
MKB
  • 7,587
  • 9
  • 45
  • 71
1

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.

Joshua Moore
  • 24,706
  • 6
  • 50
  • 73