How to get principal name from HTTPRequest in CXF JAX-RS webservice method called from android app.

Posted by johnrock on Stack Overflow See other posts from Stack Overflow or by johnrock
Published on 2010-02-13T06:01:59Z Indexed on 2010/05/02 6:07 UTC
Read the original article Hit count: 458

Filed under:
|
|

How can I get the principal name, session and ideally check if the principal is authenticated with the Spring Security context inside a CXF JAX-RS webservice method receiving a call from an Android client? This is the code I am currently working with. I have commented where and what I am trying to get.

Android code to call webservice:

httpclient.getCredentialsProvider().setCredentials(
          new AuthScope("192.168.1.101", 80), 
          new UsernamePasswordCredentials("joesmith", "mypasswd"));

 HttpGet httpget = new HttpGet(WEBSERVICE_URL+"/makePayload");
  httpget.setHeader("User-Agent", userAgent);
  httpget.setHeader("Content-Type", "application/xml");

  HttpResponse response;

  try {
      response = httpclient.execute(httpget);
      HttpEntity entity = response.getEntity();

      ... parse xml from response


      }

CXF, Spring webservice code:

@GET
@Path("/getPayload")
@Produces("application/XML")
public Response makePayload(@Context Request request){

         //Get user principal name
         //Get session?
         //Get Spring security context?

         Payload payload = new Payload();
         payload.setUsersOnline(new Long(200));

         return Response.ok().entity(payload).build();

 }

© Stack Overflow or respective owner

Related posts about cxf

Related posts about webservice