Search code examples
grailsspring-securitygsp

GSP if test returning false while checking if a logged user with Spring Security Core Plugin is the creator of a domain class instance


I am using Spring security core plugin.

I want to test if the logged user is the creator of a Note. Note is Grails domain class. Note.creator is User which is my User domain class for Spring Security Core plugin.

The next code does not work

<g:set var="loggedUserId"><sec:loggedInUserInfo field="id"/></g:set>
<g:if test="${note.creator.id == loggedUserId}">
   Never jumps here
</g:if>

However, If I include both values in separated lines, the output of both is the same

${note.creator.id}
${loggedUserId}

Any idea what I am missing? Thanks in advanced!


Solution

  • <g:if test="${note.creator.id.toString() == loggedUserId.toString()}">
    

    Try like that maybe, loggedInUserInfo returns a string and creatorId is supposedly a long, so equation without cast wouldn't be true.

    You should put logic like that into a taglib though.