In Restful web services, how to get a username or password programmatically (basic authentication)

I have soothing web services in a Java EE application (ejb3) running on jboss. And I don’t know how to get the username or password programmatically, for example, when the service method is called. I want my members to see how smilar for jaxws

webServiceContext.getUserPrincipal().getName() 

or

(httpServletRequest) <-- request.getUserPrincipal()

I would be happy to hear the solutions, thanks.

+5
source share
1 answer

[SOLVED] I found a solution, here it is:

Using

@Context
 protected SecurityContext sc;

Or

Public TestResponse test(@Context SecurityContext sc){
   ..
   sc.getUserPrincipal.getName() //will return username
}
+5
source

All Articles