Thanks Alex! That helped me a lot.
The problem was that my user has been a string instead of the named class. I didn’t know how to do that.
$paramLink comes from an input field of my user macro:
## @param Link:title=Internal Link|type=confluence-content|desc=Choose the local destination page. Choose either between a local or external link.
My code now looks something like this:
#set ($colonIndex = $paramLink.indexOf(":"))
#if ($colonIndex == -1)
#set ($spaceKey = $space.key)
#set ($pageName = $paramLink)
#set ($spaceKey = $paramLink.substring(0, $colonIndex))
#set ($pageNameIndex = $colonIndex + 1 )
#set ($pageName = $paramLink.substring($pageNameIndex))
#set ($page = $pageManager.getPage($spaceKey, $pageName))
$permissionHelper.canViewPage($action.remoteUser, $spaceKey, $pageName)
$page is used later to display some stuff. This code even handles pages that don’t get a nicely readable URL from Confluence.
Your suggestion to work with the ID is a much smoother approach but unfortunately
#set ($pageId = $page.getIdAsString())
does not work because the second parameter should be of type long as stated on https://docs.atlassian.com/atlassian-confluence/6.6.0/com/atlassian/confluence/security/PermissionHelper.html#canViewPage-com.atlassian.user.User-long-
Anyway, now everything seems to be fine. Thanks again!