Service user, resource resolver and session
Hello Everyone,
This is about service user/ system user, resource resolver and session.
In AEM if we want to read or write anything from backend we have two APIs Sling/resource API and jcr/node API. if we are using sling/resource api we need to have resources resolver and for jcr/node api we need to have jcr session. To get jcr session we use SlingRespositoy.loginService() and to get resource we use ResourceResolverFactory.getServiceResourceResolver() method.
Previously with aem if we need resource resolver or session we were using sling methods SlingRepository.loginAdministrative() and ResourceResolverFactory.getAdministrativeResourceResolver() but using this method we are getting the admin session sometimes we might not need to have admin session still we are using admin session. Now these methods are deprecated and replaced with SlingRepository.loginService() and ResourceResolverFactory.getServiceResourceResolver() lets see how to use these method to get session and resource resolver.
Now to get resource or session you must have a service user/system user with permission as per application need. Follow below step to create service user/system user.
go to --> http://localhost:4502/crx/explorer/index.jsp --> login -->user administration --> create system user --> give any userID --> save
After creation of system user give required permission to system user, for that go to http://localhost:4502/useradmin console search your system user in permissions tab give required permission using checkboxes --> click save
param.put(ResourceResolverFactory.SUBSERVICE, "subServiceName");
ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(param);
Session session=resolver.adaptTo(Session.class);
Comments
Post a Comment