In Restful web services how to get username or password programmatically (basic authentication)
Asked Answered
L

1

6

I have restful web services in a Java EE application (ejb3) running on jboss. And do not know how to get username or password programmatically, like when service method is called I want to be able to get this user principals as smilar to jaxws

webServiceContext.getUserPrincipal().getName() 

or

(httpServletRequest) <-- request.getUserPrincipal()

I would be glad to hear the solutions, thanks.

Levitation answered 16/2, 2011 at 8:10 Comment(0)
L
5

[SOLVED] I have found the solution, here it is;

Use

@Context
 protected SecurityContext sc;

Or

Public TestResponse test(@Context SecurityContext sc){
   ..
   sc.getUserPrincipal.getName() //will return username
}
Levitation answered 24/2, 2011 at 11:25 Comment(2)
Did you also got the password via an injected context??Amphipod
It was ages ago actually but as I remember, yes, I was able to get both username and password! Maybe sc.getUserPrincipal.getPassword()?Levitation

© 2022 - 2024 — McMap. All rights reserved.