Fórum
Liferay7: WebContent Freemarker template check DLFileEntryPermissions
Thomas Kellerer, modificado 6 Anos atrás.
Liferay7: WebContent Freemarker template check DLFileEntryPermissions
Expert Postagens: 490 Data de Entrada: 09/06/08 Postagens Recentes
We have a WebContent structure that shows download links to documents (the structure has a repeatable field of type "document-library")
We have a Freemarker template that displays these structures. Inside the template we would like to validate that the current user really has access to the linked documents.
I already have a workaround in place to retrieve the actual file name from the download item which involves parsing the URL from the download entry. I can successfully obtain the underlying DLFileEntry using the DLFileEntryService.
However I can't find a reliable way to check if the current user is allowed to view/download that file.
Currently I use this code to obtain the DLFileEntry object:
However the mayView variable is always true, even if the user does not have the permission to do so (when clicking on the link an error is displayed - which is correct).
I also tried "DOWNLOAD" instead of "VIEW" when calling the permission checker, but that resulted in always returning FALSE.
What am I missing? How can I validate that the current user is allowed to view/download a document?
We have a Freemarker template that displays these structures. Inside the template we would like to validate that the current user really has access to the linked documents.
I already have a workaround in place to retrieve the actual file name from the download item which involves parsing the URL from the download entry. I can successfully obtain the underlying DLFileEntry using the DLFileEntryService.
However I can't find a reliable way to check if the current user is allowed to view/download that file.
Currently I use this code to obtain the DLFileEntry object:
<#assign data = cur_link.getData()
counter = 0 />
<#list data?split("/") as x>
<#if counter == 2>
<#assign groupId = x?number >
<!--#if-->
<#if counter == 4>
<#assign fname = x?replace("+", " ") />
<!--#if-->
<#if counter == 5>
<#-- Liferay sometimes appends a ?t=123456789 to the URL, so we need to take care of that as well -->
<#assign uuId = x?keep_before("?") >
<!--#if-->
<#assign counter = counter+1 >
<!--#list-->
<#if groupId?? && uuId??>
<#assign file = dlService.getFileEntryByUuidAndGroupId(uuId,groupId) />
<#assign mayView = permissionChecker.hasPermission(file.getGroupId(), "com.liferay.document.library.kernel.model.DLFileEntry", file.getPrimaryKey(), "VIEW")/>
<!--#if-->
However the mayView variable is always true, even if the user does not have the permission to do so (when clicking on the link an error is displayed - which is correct).
I also tried "DOWNLOAD" instead of "VIEW" when calling the permission checker, but that resulted in always returning FALSE.
What am I missing? How can I validate that the current user is allowed to view/download a document?
Thomas Kellerer, modificado 6 Anos atrás.
RE: Liferay7: WebContent Freemarker template check DLFileEntryPermissions
Expert Postagens: 490 Data de Entrada: 09/06/08 Postagens Recentes
After poking around in the Liferay Source I stumbled over DLFileEntryPermission which looked promising:
<#assign fileEntryPermission = serviceLocator.findService('com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission') />
and then once I got the DLFileEntry instance, I tried:<#assign mayView = fileEntryPermission.contains(permissionChecker, file.getFileEntryId(), "VIEW")/>
But that again always returns TRUE, even if the user has no access to the document.