Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Retrieving user context when service was invoked via REST

Avatar

Level 3

Hi,

I have created a custom component with several operations which are exposed via REST endpoint.  My question is how do I retrieve the user context from the REST call that uses Basic Authenttication (set in the header) and then pass that user context for Java API to use accordingly?

Thanks in advance.

2 Replies

Avatar

Former Community Member

You can't set or get user context for your service using web services.

You'll have to,

1. Create an instance of ServiceClientFactory.

2. Authenticate using AuthenticationManager Service and get the AuthResult.

3. Initialize the Context by passing the AuthResult as shown below,

ServiceClientFactory factory = ServiceClientFactory.createInstance(properties);

AuthenticationManager authenticationManager = new AuthenticationManagerServiceClient(factory);

AuthResult authResult = null;

  try {

        authResult = authenticationManager.authenticate("administrator", "password".getBytes());

     } catch (UMException e) {

          throw new RuntimeException(e);

     }

   com.adobe.idp.Context context = new com.adobe.idp.Context();

   context.initPrincipal(authResult);

Avatar

Level 3

Hm, so, I would have to pass the username/password as part of the request to invoke each REST call, correct?