2

I am building a site on Liferay 7. By default, all the authenticated users inherit the Guest permissions (anonymous users).

There is even a label in the permissions section:

"Under the current configuration, all users automatically inherit permissions from the Guest role."

Why do I need this?

I would like to display X content only for anonymous users and when the user logs in, then I would like to display different content.

enter image description here


This is how my content permissions for anonymous users are configured:

enter image description here

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
angelcazares
  • 107
  • 1
  • 2
  • 10

4 Answers4

2

Why do I need this?

Permissions are not the catch-all for showing different content. If a guest is not allowed to see something, but needs to log in - that's fine. It's authenticated content, and you'll need to sign in.

If an authenticated user has no permission to see certain content, but just needs to log out in order to see it: What kind of permission is that? Let me answer that for you: It's not permission. It's rather targeted content and while it might be mimicked with permissions, this mimicry is nothing more than mimicry.

One way to implement such a requirement is through structured Web Content (you sound as if you want to show different Web Content articles). The template has access to the full API and can check if the current user is signed in or not - and show different content based on this fact.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
2

Although I agree with people that say this is not the best path, yes you can do it - just to address the question at hands.

Set this to true if resources should assume that all users have the Guest role. Set this to false if resources will not assume that all users have the Guest role and, thus, do not automatically inherit permissions that belong to the Guest role.

Setting this property to false may require users to grant permissions to roles like Site Member and User.
Defaults:

    permissions.check.guest.enabled=true
Victor
  • 3,520
  • 3
  • 38
  • 58
  • Thanks, Sadly this will change the behavior of all the portal, not only where I want to use it. I think Liferay team missed an opportunity here. IBM WCM handles much better anonymous and authenticated users. Thank you very much – angelcazares Jan 14 '18 at 18:22
1

If you want to achieve role permission using code level as like in xxxlocalserviceImpl class.You can use below code for allow permission for the guest user.

In case of document and media allow permission to guest and registerUser in Liferay 7 using rest webservice you can use this code for allow permission to upload and download the document using this code.

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
                                DLFileEntry.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,
                                String.valueOf(dlFileEntry.getFileEntryId()), guestRole.getRoleId(),
                                new String[] { ActionKeys.VIEW });
Ravikant
  • 149
  • 1
  • 5
0

To answer your question - you can not configure that per specific asset! By default an authenticated user can not have less permissions than an unauthenticated one. You can change that behavior for all assets using permissions.check.guest.enabled=false as @Victor correctly pointed out!

Milen Dyankov
  • 2,972
  • 14
  • 25
  • Not quite true. Technically they can, I would say they should not. – Victor Jan 13 '18 at 12:47
  • How would you CONFIGURE that? I agree you can change the behavior but OOTB if an asset is available to "guest" it's available to everyone. AFAIK there is no way to retract permission given by one role from another role via configuration. – Milen Dyankov Jan 16 '18 at 23:34
  • Specifically for this case, there is: permissions.check.guest.enabled – Victor Jan 17 '18 at 00:56
  • Oh yea, you are right. Totally forgot about this option. Yet I would strongly advise against using it as it applies to all assets which would likely add quite some permission management overhead. – Milen Dyankov Jan 22 '18 at 17:50