hi
after struggling with this issue , i found the solution
Solution overview:
- Extract pfx information
- Create system user.
- Map the system user.
- Add the certificate to this user.
- Create Servlet that will run under that user.
Prerequisites
- Certificate file
- Know the certificate keystore password (some time call passphrase)
Step 1 - extract key alias from certificate
The certificate in our case is in pfx format.
Using java “keytool” we will extract the key alias from the keystore
keytool -v -list -keystore cert.pfx
you will be prompt for the pfx password
value of the “alias name” , we will use it later
step 2
create system user.
Navigate to http://localhost:4502/crx/explorer/index.jsp

Click “User Administration”
Click “login”. And give the admin credential
Then click “Create System User”
Give user id , in the path use “/home/users/system”
Don’t forget to click the green V
Click “close”
Step 3 - map
Go to http://localhost:4502/system/console/configMgr
Find Apache Sling Service User Mapper Service Amendment

Click on the +
On the service mapping you need to supply the domain (you can take it from the pom.xml )
Then “:” then user name and the permission needed
״nameoftheuserhere"=content-writer-service (in case you need to write to aem , use “content-writer-service”

Click “Save”
Step 4 – add certificate to user
Navigate to tools->security->users
http://localhost:4502/security/users.html

Find your user. “nameoftheuser”
Create new KeyStore and give it password (we won’t use this password now but log it)

Use “Add Private Key from Keystore File” option
New alias – free choice , I put the user name for better clarity
Upload the pfx file in “keyStoreFile” and set the password of the pfx
On the “private key alias “ use the alias that you extracted before , and private key password use the same as keystore file password


Step 5. – running the servlet with the user
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.HashMap;
import org.osgi.framework.Constants;
import holdings888.core.utils.HttpsClient;
@8220494(service = Servlet.class,
property = {
Constants.SERVICE_DESCRIPTION + "=JSON Servlet to api",
"sling.servlet.paths=" + "/bin/readRules" })
public class RedirectionServlet extends SlingAllMethodsServlet {
@3214626
private ResourceResolverFactory resolverFactory;
private static final long serialVersionUID = 1L;
@9944223
protected void doGet(final SlingHttpServletRequest req,
final SlingHttpServletResponse resp) throws ServletException, IOException {
ResourceResolver resolver = null;
HashMap<String, Object> param = new HashMap<>();
param.put(ResourceResolverFactory.SUBSERVICE, "nameoftheuser");
resolver = resolverFactory.getServiceResourceResolver(param);
// make the call with any client implementation
String res = _client.Get(http://urltoapi)