How to use loginService(String subServiceName, String workspace) method of SlingRepository Class | Community
Skip to main content
sateesha8038436
New Participant
October 16, 2015
Solved

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

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
October 16, 2015

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

2 replies

smacdonald2008
Level 10
October 16, 2015

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

Translate
Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
October 16, 2015

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

Translate