Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How to use loginService(String subServiceName, String workspace) method of SlingRepository Class

Avatar

Level 1

Hi All,

        We are upgrading from 5.4 to 6.1 .

  To get JCR Session we used the below code

          SlingRepository repo = sling.getService(SlingRepository.class);

         Session session = repo.loginAdministrative(null);

Now while upgrading we want to use

loginService(String subServiceName, String workspace)

method of SlingRepository class as loginAdministrative method is deprecated .But we are not able to use it .

 We are using this

          Session session = repo.loginService(null,null);

We don't know what to send for subServiceName argument .

If anyone used this method please mention your code.

Thanks in advance

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

As @scott mentioned, you can assign the user for a service and use that credentials to login 

or you can also get session with the respective login like below

Session session = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));

View solution in original post

2 Replies

Avatar

Level 10

You can create a dedicated user account for AEM OSGi services to use. Then you can use:

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);

This is how you create a session in AEM 6:

Querying Adobe Experience Manager 6 data using the Sling getServiceResourceResolver method

Avatar

Correct answer by
Community Advisor

As @scott mentioned, you can assign the user for a service and use that credentials to login 

or you can also get session with the respective login like below

Session session = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));