I have project running spring with tiles2 and Thymeleaf template engine. In tiles I want to display an authentication navbar depending if the user is authenticated or not, to do so I'm using apache-tiles EL to choose which navbar will be selected. here is my tiles definition
`<definition name="abstract.layout" template="/layouts/abstractLayout" templateType="thymeleaf" >
<put-attribute name="navbar" type="definition" expression="${principal} !=null ? 'authenticated.navbar' : 'guest.navbar'" />
<put-attribute name="title" value="company" type="string" />
<put-attribute name="description" value="E-Commerce Platform" type="string" />
<put-attribute name="sidebar" value="/layouts/fragments/sidebar/sidebar::content" type="thymeleaf" />
<put-attribute name="footer" value="/layouts/fragments/footer::content" type="thymeleaf" />
<put-list-attribute name="thirdPartyCssFiles" >
</put-list-attribute>
<put-list-attribute name="customCssFiles">
</put-list-attribute>
<put-list-attribute name="pluginJsFiles">
</put-list-attribute>
<put-list-attribute name="customJsFiles">
</put-list-attribute>
</definition>`
When I'm evaluating the tile, the variable ${principal} isn't found in the evaluation context.
My questions are:
- How to get the spring-security principal object and how to know if the user is authenticated?
- Is there a way to use SPEL instead of EL or ONGL in expressions?
Thank you