How resourceResolver getting current user session ? | Community
Skip to main content
vasimakram
New Participant
October 16, 2015
Solved

How resourceResolver getting current user session ?

  • October 16, 2015
  • 16 replies
  • 6152 views

How resourceResolver work when we say resourceResolver.getResource("/etc/geometrixx") based on current user permissions ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

In AEM 6 - a better way is to create an dedicated account and use that. For example: 

Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;

try {
           
resolver = resolverFactory.getServiceResourceResolver(param);
session = resolver.adaptTo(Session.class);

 

See https://helpx.adobe.com/experience-manager/using/querying-experience-manager-sling.html

16 replies

hksrivastava
New Participant
February 21, 2017

Hi Ratna,

Thanks for your reply...

I followed exactly the same steps as shown in the video.. But while creating the osgi bundle, during mvn clean install, I m getting the below error :

_______________________________________________________________________________________________

C:\AEM4502\slingjcr>mvn clean install

[INFO] Scanning for projects...
[ERROR] [ERROR] Project 'com.community.aem:slingjcr-bundle:1.0-SNAPSHOT' is duplicated in the reactor @
[ERROR] Project 'com.community.aem:slingjcr-bundle:1.0-SNAPSHOT' is duplicated in the reactor -> [Help 1]
[ERROR][ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR][ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DuplicateProjectException

_________________________________________________________________________________

Screenshot of eclipse attached.

Ratna_Kumar
New Participant
February 20, 2017

Also, watch this video here: http://scottsdigitalcommunity.blogspot.in/2014/12/querying-adobe-experience-manager-6.html  - which contains step by step of the article 

~ Ratna.

Ratna_Kumar
New Participant
February 20, 2017

Hi,

BTW, What do you mean by creating snapshot means -  when you create a bundle, you see the error in error.log?

I have tested this article many times, it works for me. However, I will again retest it and once again check the same.

~ Ratna.

New Participant
February 20, 2017

Hi Smac,

 

I have followed the link https://helpx.adobe.com/experience-manager/using/querying-experience-manager-sling.html and tried to create the project for AEM 6.2

While creating the snapshot, m getting the following error :

SUBSERVICE cannot be resolved or is not a field    CustomerServiceImpl.java    /slingjcr-bundle/src/main/java/com/community/aem    line 74    Java Problem

The method getServiceResourceResolver(Map<String,Object>) is undefined for the type ResourceResolverFactory    CustomerServiceImpl.java    /slingjcr-bundle/src/main/java/com/community/aem    line 80    Java Problem

-----------------------------------------------------------------------------------------------------------------------------

param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;
  
try {
             
    //Invoke the adaptTo method to create a Session used to create a QueryManager
    resolver = resolverFactory.getServiceResourceResolver(param);
    session = resolver.adaptTo(Session.class);
      

Could you please suggeston this.

 

Thanks-

Hemant

Lokesh_Shivalingaiah
New Participant
October 16, 2015

its depends on how you have created the session before using resourceResolver.

Check this example [1]

 

[1] http://www.wemblog.com/2014/08/how-to-use-sessions-and-resource.html

smacdonald2008
smacdonald2008Accepted solution
New Participant
October 16, 2015

In AEM 6 - a better way is to create an dedicated account and use that. For example: 

Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;

try {
           
resolver = resolverFactory.getServiceResourceResolver(param);
session = resolver.adaptTo(Session.class);

 

See https://helpx.adobe.com/experience-manager/using/querying-experience-manager-sling.html