Expand my Community achievements bar.

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

Custom SAML Drop Credential Current User Fetching Problem

Avatar

Community Advisor

Hi Members,

I am trying to implement a custom SAML implementation. I Implemented (extractCredentials & requestCredentials) methods successfully. Users can access the page, and each other behaviors are working as expected.
But in the dropCredentials methods I am facing a problem.
What I did I have a Custom Servlet for the Logout URL, from this servlet I did this,


LogOutServlet.java

String logoutUrl = "/system/sling/logout.html?resource=/content/aem-demo/fr";
response.sendRedirect(logoutUrl);

For Debug Purpose,

Authorizable user = request.getResourceResolver().adaptTo(Authorizable.class);

Here is the user I got my current login user 'user2'

By the servlet code, the expected AuthenticationHandler dropCredentials method is triggered. In this method, I tried to,

@Override
public void dropCredentials(HttpServletRequest request, HttpServletResponse response) {
if (this.handleLogout && request instanceof SlingHttpServletRequest) {
SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;
Authorizable user = slingRequest.getResourceResolver().adaptTo(Authorizable.class);
String protectedResponse = user.getProperty("samlResponse")[0].getString();
}
}

But here the user is assigned for 'anonymous' where my login/expected user is 'user2'

What did I do wrong? Thanks in Advance for your help.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Just found the problem. The mistake I was made, that I deleted the login-token cookie before fetching the user. That is why I was getting anonymous user instead of user2.

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Just found the problem. The mistake I was made, that I deleted the login-token cookie before fetching the user. That is why I was getting anonymous user instead of user2.