How to restrict users to access some of the pages in website | Community
Skip to main content
Level 3
March 1, 2024
Solved

How to restrict users to access some of the pages in website

  • March 1, 2024
  • 2 replies
  • 689 views

Hi Team,

 

I have a website in AEM Cloud, where once the user is authenticated, I want them to see page according to their permissions.

How can I restrict the users to see only some of the page in navigation bar but not all as per their permission in authenticated group.

 

Thanks,

SD 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi @sdusane 

we had implement same using:
CUG : To protect page(s)/tree

LinkTransformer : To add a hide class or custom data attribute 'cug-protected-link' to all protected links while generating page. Alternatively you can do same in sling model if this is just for navigation component. we had to apply this globally so went with sling rewrite pipeline.

Servlet : Calling a servlet(POST with all the 'cug-protected-link'  links ) on page load, servlet will return a json response with payload links and visibility status based on user(current session).

 

based on servlet response unhide 'cug-protected-link'.

considering creating dictionary with expiry in user's localStorge will help to reduce number of call to server and help with performance.


2 replies

AMANATH_ULLAH
Community Advisor
Community Advisor
March 1, 2024

@sdusane 

You can use sling model to fetch the groups associated with the user and check if user is part of the required group.

Then you can show/hide html elements conditionally in navigation bar by calling that sling model in sightly code using use API

Amanath Ullah
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
March 1, 2024

Hi @sdusane 

we had implement same using:
CUG : To protect page(s)/tree

LinkTransformer : To add a hide class or custom data attribute 'cug-protected-link' to all protected links while generating page. Alternatively you can do same in sling model if this is just for navigation component. we had to apply this globally so went with sling rewrite pipeline.

Servlet : Calling a servlet(POST with all the 'cug-protected-link'  links ) on page load, servlet will return a json response with payload links and visibility status based on user(current session).

 

based on servlet response unhide 'cug-protected-link'.

considering creating dictionary with expiry in user's localStorge will help to reduce number of call to server and help with performance.


Arun Patidar