cancel
Showing results for 
Search instead for 
Did you mean: 

What's the difference between ImpersonationService and SessionService

Former Member
0 Kudos

Hi all,

When should I use an ImpersonationContext with ImpersonationService and when sould I use executeInLocalView with SessionService ?

Like with the ImpersonationService :

 ImpersonationContext context = new ImpersonationContext();
 context.setCatalogVersions(Arrays.asList(catalog));
 context.setCurrency(currency);
 context.setSite(site);
 
 impersonationService.executeInContext(context, () -> myContextAwareFunction());

With the sessionService :

 sessionService.executeInLocalView(new SessionExecutionBody()
 {
     @Override
     public void executeWithoutResult()
     {
         // set current currency
         // set current baseStore
     }
 }


For instance in a Job task, I need to work in a specific baseStore and currency.

Thanks, JL

Accepted Solutions (1)

Accepted Solutions (1)

former_member348752
Participant

The ImpersonationService uses SessionService behind the scenes.

The ImpersonationService - if using a commerce-licensed Hybris, is an easier way to indicate catalog, currency, user group, and session for running a method within a specific user context.

Former Member
0 Kudos

Thanks ! Nice and clear answer

Answers (0)