留言板

User data and session lost when calling URL from XSL

Valentin SAROT,修改在12 年前。

User data and session lost when calling URL from XSL

New Member 帖子: 2 加入日期: 11-5-6 最近的帖子
Hi everyone,
Since 2 days I'm facing a curious problem I can't fix.

I use Spring Portlet and Liferay Community 6.0.6

I have a portlet with a resource mapping 'renderPdf' generating a XML fragment, returning to a XSL view, which aim is to generate PDF content (with FOP).
This stylesheet should be able to know user roles and permissions to hide some parts of the output document.
To do this, I generate a new resourceURL pointing on the same portlet, method 'getUserPermissions'
I pass this URL to the XSL stylesheet which loads permissions using the document() function.
When I come in the 'getUserPermissions' method, all User data (current user, current session, etc..., ) are lost.
Actually, I think this data are sent from pages in a cookie, and XSL document() function does not send this cookie.
I've tried to add 'doAsUserId' in the URL parameter, adding encrypted userId, but it does not work.
Below is my code :

Portlet.java :


...
	@ResourceMapping("detail.pdf")
	protected ModelAndView renderPdf(ResourceRequest request, ResourceResponse response, Model model) {

		ResourceURL permissionsUrl = response.createResourceURL();
		permissionsUrl.setResourceID("getUserPermissions.xml");

		SomeBean someBean = getSomeBean();
		String xml = xstreamMarshaller.getXStream().toXML(someBean);
		model.addAttribute(FopPdfView.SOURCE_MODEL_KEY, xml);
		model.addAttribute("permissionsUrl", permissionsUrl);
		model.addAttribute("lang", request.getLocale().getLanguage());
		return new ModelAndView(request.getResourceID(), model.asMap());
	}

	@ResourceMapping("getUserPermissions.xml")
	protected ModelAndView getUserPermissions(ResourceRequest request, ResourceResponse response, Model model) {
		ThemeDisplay td = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
		User user = td.getUser();
		// Here, user contains guest user
		...
	}


And the associated XSL stylesheet :

<!--?xml version="1.0" encoding="UTF-8"?-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
	<xsl:output method="xml" indent="yes" />
	
	<xsl:include href="servlet-context://WEB-INF/xsl/styles.xsl" />
	
	<xsl:param name="lang" />
	<xsl:param name="permissionsUrl" />
	
	<xsl:variable name="messages" select="document('servlet-context://WEB-INF/xsl/notary_localization.xml')/messages" />
	<xsl:variable name="permissions" select="document($permissionsUrl)/map" />

	...
</xsl:stylesheet>


My question is : I can I get in the getUserPermissions() method conserving my user data ? If not possible, how can I get Permissions of a specific user, knowing his ID ?
Thanks for your help.
Valentin SAROT,修改在12 年前。

RE: User data and session lost when calling URL from XSL

New Member 帖子: 2 加入日期: 11-5-6 最近的帖子
Nobody inspired? emoticon