How to design a page having different content for logged in and non-logged in users?

Avatar

Avatar
Validate 1
Level 1
Kamal_Kishor
Level 1

Likes

0 likes

Total Posts

11 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Give Back
Applaud 5
View profile

Avatar
Validate 1
Level 1
Kamal_Kishor
Level 1

Likes

0 likes

Total Posts

11 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Give Back
Applaud 5
View profile
Kamal_Kishor
Level 1

09-06-2021

We have a requirement to show different content (few links in header section) on a page for logged in and non-logged in users. URL of the page will remain same for both users.

How to design such pages in AEM. How the caching and validation of users would work on each page requests?

 

@asutosh_jena , @Arun_Patidar , @markus_bulla_adobe , @Vijayalakshmi_S , @PulkitJain , @Vaibhavi , @Ritesh_M  

View Entire Topic

Avatar

Avatar
Affirm 50
Employee
markus_bulla_adobe
Employee

Likes

148 likes

Total Posts

131 posts

Correct reply

62 solutions
Top badges earned
Affirm 50
Boost 100
Applaud 25
Affirm 25
Boost 50
View profile

Avatar
Affirm 50
Employee
markus_bulla_adobe
Employee

Likes

148 likes

Total Posts

131 posts

Correct reply

62 solutions
Top badges earned
Affirm 50
Boost 100
Applaud 25
Affirm 25
Boost 50
View profile
markus_bulla_adobe
Employee

09-06-2021

Hi @Kamal_Kishor!

 

Depending on the exact use case, there are different approaches to this kind of requirement.

1. You have two groups of users (logged-in vs. anonymous)

2. You have personalized content (menu looks different for every user depending on his permissions).

 

There are general integration strategies for this requirement.
Let me first outline the differences in cache-ability for 1 and 2:

 

For 1, the menu is totally cache-able.
For example, you could add a selector to the URL for user with and without permissions (menu.anonymous.html vs. menu.logged-in.html). With this approach, the application will make the decision which menu to integrate for a certain user. You would want to ensure that this mechanism is somewhat secured and can't be tampered with from the public. Please note: this can also be scaled to a certain amount of different groups (= variations of the menu) but I would keep the number as low as possible (probably a low 2-digit number as maximum).

For 2, you won't be able to cache it. You would need to cache a dedicated page for each user and that most probably will outweigh any gains achieved by caching in the first place.

 

Coming to the integration strategies:

  • Loading and integrating the menu client side (via JavaScript/Ajax)
    This approach is commonly used when it comes to personalized content or integration of data from 3rd party systems (e. g. integrating a shopping cart, a "Welcome, John Smith" banner, or similar)
  • Integration on Apache HTTPD/Dispatcher level
    For certain use cases, Server Side Includes (SSI) on web server level can be leveraged. This can be handled dynamically e. g. based on a users session, headers or other environment variables available to the web server. For permission related use cases it is usually necessary to somehow integrate Apache with the system managing the authorizations. I've seen setups handling authentication and authorization on Apache level through certain Apache modules and leveraging the resulting information in SSIs.
  • Sling Dynamic Includes
    Probably the best fit for most use cases and commonly recommended is the approach of Sling Dynamic Includes. It combines SSI (see above) in a more integrated way with AEM/Sling.

 

Update:

Two more things to consider:

  • Depending on the level of security that is required, don't just look at the links but also put access control for the actual target pages in place.
  • Is the header section the only place where you have links to these target places?
    Things may get quite complicated if there are other links to these protected pages spread across the website, e. g. content editors adding these links to regular pages.

 

Hope that helps!