grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Taglib does not work in main layout

Open mobilemindtech opened this issue 8 months ago • 1 comments

Hi,

I'm upgrading a project to version 7.0.0-M3 and I noticed that a taglib that is called in the main layout doesn't work correctly. For example:

class AuthService {

	def springSecurityService // injected by Spring	

	def getCurrRoles() {
		def auth = springSecurityService.authentication 
		def roles = auth?.authorities?.collect { it.authority }	 ?: []
		log.info "roles = $roles"
		roles
	}		

	def getUser(){
	    def principal = springSecurityService.getPrincipal()
	    if(!principal || "anonymousUser".equals(principal.toString())){
	      return null         
	    }
	    User.findWhere(username: springSecurityService.getPrincipal().username) 
	}	
}

class AuthTagLib {

	static namespace =  "auth"
	def authService

	def roles = { attrs, body -> 
		out << authService.currRoles
	}	

	def user = { attrs, body -> 
		out << authService.user
	}	
}

When I call (logged in) <auth:roles /> <auth:user /> from any page the values ​​return correctly, but when I call it from main.gsp it returns a empty list and null respectively. In version 6 the taglib responded correctly. Thanks!

mobilemindtech avatar Apr 01 '25 22:04 mobilemindtech

Related: https://github.com/apache/grails-spring-security/issues/1104

matrei avatar Apr 02 '25 09:04 matrei