Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

How to get the login-token created by cq into the component jsp

Avatar

Level 5
Level 5

How to get the login-token created by cq into the component jsp.

[img]session.PNG[/img]

1 Accepted Solution

Avatar

Correct answer by
Employee

Hmmm. The JCR Session interface doesn't define an invalidate() method, so I'm not sure exactly what you're referring to.

If you want to programmatically log out a user from a JSP, you should do this:

sling.getService(org.apache.sling.api.auth.Authenticator.class).logout(request, response);

See http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/auth/Authenticator.html for more information.

View solution in original post

7 Replies

Avatar

Employee

Can you explain why you want to do this?

Avatar

Level 5
Level 5

Hi Justin, I am trying to implement a custom signout functionality, where i tried to invalidating the session by "session.invalidate();", but in author mode found that the session is not invalidated. so trying to get all the cookies and the session data to delete, there got this question. whether is it possible to get the CQ created session data to read into the components .?

Avatar

Correct answer by
Employee

Hmmm. The JCR Session interface doesn't define an invalidate() method, so I'm not sure exactly what you're referring to.

If you want to programmatically log out a user from a JSP, you should do this:

sling.getService(org.apache.sling.api.auth.Authenticator.class).logout(request, response);

See http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/auth/Authenticator.html for more information.

Avatar

Level 2

Hi Justin,

We have requirement in our portal where after login into our site if we click on "sign-out" button page should be redirected to our site "login page" by removing user session. We are using OOTB userinfo component for this signout functionality ,  which will call OOTB sling servlet("/system/sling/logout.html") to remove the user session and redirect user to next login page. 

 

The problem we are facing here is in publish environment after sign-out its redirecting us to "geometrixx" page.To avoid this we changed the rootmapping configuration path , which solved our problem.

 

[img]cq root mapping conf.jpg[/img]

 

But now we are facing another issue , we hosted 2 more sites in the same instance which have "sign out" functionality there also.

 

How can we redirect users to corresponding login page in the 3 sites when they click on "sign out" link.

 

Regards,

Sagar

Avatar

Level 9

Hi Sagar,

Given scenario you have to write your own logout servlet which will redirect you to corresponding login page. you can manage the redirect setting in your site configuration property. 

Thanks,

Pawan

Avatar

Level 2

Thanks for the reply Pawan.

Even we started writing the custom servlet for this by passing the redirection URL from our component.

We got a sample code when we goggled for sample implementor class for Sling Authenticator interface but its has some complex logic (some sling API) in "login" and "logout" methods. We are not sure whether its  a best way to overwrite that logic again in our custom class or not. (We want to go with this option in worst case).

Other than trying with custom servlet is there any option like passing some parameter from userinfo component to OOTB servlet so that it redirects user to our site login page.

If we have to go with custom servlet only , Can you please provide us any link or code which will help us here.

 

Regards,

Sagar

Avatar

Level 2

Its working fine if we are passing one more parameter (resource) to sling logout servlet from userinfo component.

final String logoutPath = request.getContextPath() + "/system/sling/logout.html?resource=/content/mysite/../logout-page.html";

Regards,

Sagar