Hi @pradeep_varmape
Can you please check this
https://medium.com/@lars.auffarth/building-an-aem-custom-authentication-handler-for-okta-openid-connect-2d9d42c0161
I just tried with ChatGPT, can you also try this.
ChatGPT Response
Extending the out-of-the-box (OOTB) AEM com.adobe.granite.auth.saml.SamlAuthenticationHandler requires creating a custom OSGi service that inherits from this class. This can allow you to add or override functionality to meet your specific requirements.
Here's a step-by-step guide to extending the SamlAuthenticationHandler in AEM:
Create a new class in your AEM project that extends SamlAuthenticationHandler.
package com.yourcompany.aem.custom.auth.saml;
import com.adobe.granite.auth.saml.SamlAuthenticationHandler;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.auth.Authenticator;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.api.scripting.SlingScriptHelperProvider;
import org.osgi.service.component.ComponentContext;
import javax.jcr.Session;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
@Component(
immediate = true,
label = "Custom SAML Authentication Handler",
description = "Custom SAML Authentication Handler that extends the OOTB SAML Authentication Handler"
)
@Service(Authenticator.class)
public class CustomSamlAuthenticationHandler extends SamlAuthenticationHandler {
@Override
protected void activate(ComponentContext context) {
super.activate(context);
// Custom activation logic if needed
}
@Override
protected void deactivate(ComponentContext context) {
// Custom deactivation logic if needed
super.deactivate(context);
}
@Override
public boolean authenticate(HttpServletRequest request, HttpServletResponse response) {
// Custom authentication logic if needed
return super.authenticate(request, response);
}
@Override
public void dropCredentials(HttpServletRequest request, HttpServletResponse response) {
// Custom drop credentials logic if needed
super.dropCredentials(request, response);
}
@Override
public void login(HttpServletRequest request, HttpServletResponse response) {
// Custom login logic if needed
super.login(request, response);
}
}
Create an OSGi configuration file for your custom authentication handler.
// Create a file named `com.yourcompany.aem.custom.auth.saml.CustomSamlAuthenticationHandler.config`
enabled=B"true"
path="[/content]"
service.ranking=5000