Create system users from console http//localhost:4502/crx/explorer
User 1 : shasservice – user with no access permissions
User 2 : serviceuser – user with all the access permissions
Configure this in APCHE SLING SERVICE USER MAPPER SERVICE @System/console
Service mappings : com.demo.sehns.sehns:shasservice=serviceuser
Method #1 – TRYING FOR Session
private Session getSession(String srvServiceName) throws Exception{
Session session =null;
try{
log.info(“—-Getting session for—-“+srvServiceName);
ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(CommonUtils.getServiceMap(strServiceName));
session = resourceResolver.adaptTo(Session.class);
}catch(Exception e){
e.printStackTrace();
log.error(“—-Exception while getting session—-“+e.getMessage());
throw e;
}
return session;
}
METHOD #2 – returning service map data
public static Map getServiceMap(final String getServiceName) throws Exception {
try
{
Map params = new HashMap();
param.put(ResourceResolverFactory.SUBSERVICE, getServiceName);
return params;
}catch(Exception e){
log.error(“————Error —-“+e);
throw exception;
}
}
Here we can get the session object by following above method.
Thanks
Sony C