Tudor Vintilescu
Tudor Vintilescu

Reputation: 1460

Using Spring Security principal property in a tag (e.g.<a>)

I am trying to use the user id, stored as a principal property inside the Spring Security Authentication token in a HTML tag such as :

<a href="/users/${id}">Profile page</a> 

I am only aware of two alternatives to use the id from the Spring Security principal object:

  1. Use the dedicated taglib's authentication tag (wouldn't work here, as JSP doesn't allow nested tags as far as I know).

  2. Use a scriptlet, which I would really like to avoid. If anybody is aware of a an elegant one doing the job, I would be interested anyway.

I would like to be able to use something along the lines of EL.

Upvotes: 0

Views: 617

Answers (1)

Debojit Saikia
Debojit Saikia

Reputation: 10632

You can use JSTL c:set for this:

<c:set var="id"><security:authentication property="username" /></c:set>
<a href="/users/${id}">Profile page</a> 

Upvotes: 2

Related Questions