How resourceResolver getting current user session ? | Community
Skip to main content
vasimakram
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

Lokesh_Shivalingaiah
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
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

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

Ratna_Kumar
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.

Ratna_Kumar
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.

hksrivastava
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
February 21, 2017

Hi,

From your screenshot you written incorrect class for implementing the interface.
It must be "CustomerServiceImp" and not "s" 

//It must be CustomerServiceImp Implements CutomerService

~ Ratna.

hksrivastava
February 21, 2017

That was a typo while taking the screenshot.. but It was compiled with correct name..

Anyways, keeping the correct class name has even not solved the issue..

Prince_Shivhare
Community Advisor
Community Advisor
February 21, 2017

Hi,

is duplicated in the reactor 

looks like you have error on POM file.

please check your project artifact ID.

do you have same name of artifact ID and group ID ?

 

~ Prince

hksrivastava
February 21, 2017

Hi Prince,

No, I have checked it.. Its different..

below is the error log :

______________________________________________________________________

 

[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]
org.apache.maven.project.DuplicateProjectException: Project 'com.community.aem:slingjcr-bundle:1.0-SNAPSHOT' is duplicated in the reactor

        at org.apache.maven.project.ProjectSorter.<init>(ProjectSorter.java:93)
        at org.apache.maven.graph.DefaultProjectDependencyGraph.<init>(DefaultProjectDependencyGraph.java:56)
        at org.apache.maven.graph.DefaultGraphBuilder.dependencyGraph(DefaultGraphBuilder.java:109)
        at org.apache.maven.graph.DefaultGraphBuilder.build(DefaultGraphBuilder.java:92)
        at org.apache.maven.DefaultMaven.buildGraph(DefaultMaven.java:491)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:219)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DuplicateProjectException

____________________________________________________________________________________________________________________________