2 Replies Latest reply: Sep 6, 2012 4:01 PM by Clookes RSS

    Retrieving user context when service was invoked via REST

    Clookes Community Member

      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.

        • 1. Re: Retrieving user context when service was invoked via REST
          Amit Pugalia techies

          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);
          
          
          • 2. Re: Retrieving user context when service was invoked via REST
            Clookes Community Member

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