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

Prince_Shivhare
New Participant
February 21, 2017

This is when I am using maven archetype 10 project.

Prince_Shivhare
New Participant
February 21, 2017

Hi,

Please make sure project children POM file (Ex. Core , Apps)  artifact ID should not same.

Ex:

1) student\core\pom.xml

your artifact ID should be:

 <artifactId>student.core</artifactId>
    <packaging>bundle</packaging>
    <name>student - Core</name>
    <description>Core bundle for student</description>

2) student\ui.apps\pom.xml

your artifact ID should be:

<artifactId>student.ui.apps</artifactId>
    <packaging>content-package</packaging>
    <name>student - UI apps</name>
    <description>UI apps package for student</description>

I just did the same thing .. I kept the name of artifcat ID same for core and apps pom file. and got the same error.

please try this. 

 

~ Prince

hksrivastava
New Participant
February 21, 2017

pom.xml..

____________________________________________________________________

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd ">
    <modelVersion>4.0.0</modelVersion>
    <!-- ====================================================================== -->
    <!-- P A R E N T P R O J E C T D E S C R I P T I O N -->
    <!-- ====================================================================== -->
    <parent>
        <groupId>com.community.aem</groupId>
        <artifactId>slingjcr</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
 
    <!-- ====================================================================== -->
    <!-- P R O J E C T D E S C R I P T I O N -->
    <!-- ====================================================================== -->
 
    <artifactId>slingjcr-bundle</artifactId>
    <packaging>bundle</packaging>
    <name>My Project Bundle</name>
 
<dependencies>
         
          
        
      <dependency>
        <groupId>com.adobe.aem</groupId>
        <artifactId>aem-api</artifactId>
        <version>6.0.0.1</version>
        <scope>provided</scope>
    </dependency>
         
         
   <dependency>
    <groupId>org.apache.sling</groupId>
    <artifactId>org.apache.sling.api</artifactId>
    <version>2.8.0</version>
</dependency>
  
         
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.compendium</artifactId>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.scr.annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
           
            
        <dependency>
         <groupId>org.apache.felix</groupId>
     
         <artifactId>org.osgi.core</artifactId>
     
         <version>1.4.0</version>
      </dependency>
           
          
            
    <dependency>
    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>jackrabbit-core</artifactId>
    <version>2.4.3</version>
    </dependency>
         
    <dependency>
    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>jackrabbit-jcr-commons</artifactId>
    <version>2.4.3</version>
    </dependency>
   <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
             
     
           
      <dependency>
         <groupId>javax.jcr</groupId>
         <artifactId>jcr</artifactId>
         <version>2.0</version>
      </dependency>
         
       <dependency>
            <groupId>com.day.cq.wcm</groupId>
            <artifactId>cq-wcm-api</artifactId>
            <version>5.5.0</version>
            <scope>provided</scope>
        </dependency>
           
        <dependency>
            <groupId>com.day.cq</groupId>
            <artifactId>cq-commons</artifactId>
            <version>5.5.0</version>
            <scope>provided</scope>
        </dependency>
                 
    </dependencies> 
    <!-- ====================================================================== -->
    <!-- B U I L D D E F I N I T I O N -->
    <!-- ====================================================================== -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-scr-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-scr-descriptor</id>
                        <goals>
                            <goal>scr</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>com.community.aem.slingjcr-bundle</Bundle-SymbolicName>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>maven-sling-plugin</artifactId>
                <configuration>
                    <slingUrl>http://${crx.host}:${crx.port}/apps/myproject/install</slingUrl>
                    <usePut>true</usePut>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                 <configuration>
                    <excludePackageNames>
                        *.impl
                    </excludePackageNames>
                 </configuration>
            </plugin>
        </plugins>
    </build>
</project>

hksrivastava
New Participant
February 21, 2017

pom.xml..

____________________________________________________________________

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd ">
    <modelVersion>4.0.0</modelVersion>
    <!-- ====================================================================== -->
    <!-- P A R E N T P R O J E C T D E S C R I P T I O N -->
    <!-- ====================================================================== -->
    <parent>
        <groupId>com.community.aem</groupId>
        <artifactId>slingjcr</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
 
    <!-- ====================================================================== -->
    <!-- P R O J E C T D E S C R I P T I O N -->
    <!-- ====================================================================== -->
 
    <artifactId>slingjcr-bundle</artifactId>
    <packaging>bundle</packaging>
    <name>My Project Bundle</name>
 
<dependencies>
         
          
        
      <dependency>
        <groupId>com.adobe.aem</groupId>
        <artifactId>aem-api</artifactId>
        <version>6.0.0.1</version>
        <scope>provided</scope>
    </dependency>
         
         
   <dependency>
    <groupId>org.apache.sling</groupId>
    <artifactId>org.apache.sling.api</artifactId>
    <version>2.8.0</version>
</dependency>
  
         
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.compendium</artifactId>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.scr.annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
           
            
        <dependency>
         <groupId>org.apache.felix</groupId>
     
         <artifactId>org.osgi.core</artifactId>
     
         <version>1.4.0</version>
      </dependency>
           
          
            
    <dependency>
    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>jackrabbit-core</artifactId>
    <version>2.4.3</version>
    </dependency>
         
    <dependency>
    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>jackrabbit-jcr-commons</artifactId>
    <version>2.4.3</version>
    </dependency>
   <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
             
     
           
      <dependency>
         <groupId>javax.jcr</groupId>
         <artifactId>jcr</artifactId>
         <version>2.0</version>
      </dependency>
         
       <dependency>
            <groupId>com.day.cq.wcm</groupId>
            <artifactId>cq-wcm-api</artifactId>
            <version>5.5.0</version>
            <scope>provided</scope>
        </dependency>
           
        <dependency>
            <groupId>com.day.cq</groupId>
            <artifactId>cq-commons</artifactId>
            <version>5.5.0</version>
            <scope>provided</scope>
        </dependency>
                 
    </dependencies> 
    <!-- ====================================================================== -->
    <!-- B U I L D D E F I N I T I O N -->
    <!-- ====================================================================== -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-scr-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-scr-descriptor</id>
                        <goals>
                            <goal>scr</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>com.community.aem.slingjcr-bundle</Bundle-SymbolicName>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>maven-sling-plugin</artifactId>
                <configuration>
                    <slingUrl>http://${crx.host}:${crx.port}/apps/myproject/install</slingUrl>
                    <usePut>true</usePut>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                 <configuration>
                    <excludePackageNames>
                        *.impl
                    </excludePackageNames>
                 </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Prince_Shivhare
New Participant
February 21, 2017

Hi,

If you will check the link:  http://cwiki.apache.org/confluence/display/MAVEN/DuplicateProjectException

It is also saying the same thing: The coordinates for a project as given by its group id, artifact id and version must be unique within a reactor build.

 

Can you please post some more details or screenshot related to POM file?

 

~ Prince

Prince_Shivhare
New Participant
February 21, 2017

Hi,

if you will check the link: http://cwiki.apache.org/confluence/display/MAVEN/DuplicateProjectException

it is also saying the same thing: The coordinates for a project as given by its group id, artifact id and version must be unique within a reactor build.

Can you please post some more details or screenshot?

 

~ Prince

hksrivastava
New Participant
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

____________________________________________________________________________________________________________________________

Prince_Shivhare
New Participant
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
New Participant
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..

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