Lester
Lester

Reputation: 31

how to retrieve the liferay authToken using velocity

How to I retrieve the authToken for the current page in Liferay Velocity?

For example, in the HTML code there is the following but I do not know what is the coding to retrieve the corresponding value 0H4mKLWq for the auth Token assigned for the current session of the webpage.

The following is the string in the HTML:

Liferay.authToken="0H4mKLWq";

Upvotes: 3

Views: 547

Answers (1)

Ori Marko
Ori Marko

Reputation: 58832

In Freemarker you can do it using static method:

<#assign authTokenUtil = staticUtil["com.liferay.portal.security.auth.AuthTokenUtil"] />
${authTokenUtil.getToken(request)}

In velocity you can call static methods by adding AuthTokenUtil to context or loading it using Class.forName

#set($authTokenUtil=$String.class.forName('com.liferay.portal.security.auth.AuthTokenUtil'))

Upvotes: 2

Related Questions