在Restful Web服务中如何以编程方式获取用户名或密码(基本身份验证)

Jav*_*tar 5 rest restful-authentication basic-authentication ejb-3.0

我在jboss上运行的Java EE应用程序(ejb3)中有宁静的Web服务.并且不知道如何以编程方式获取用户名或密码,例如调用服务方法时我希望能够将此用户主体作为smilar到jaxws

webServiceContext.getUserPrincipal().getName() 
Run Code Online (Sandbox Code Playgroud)

要么

(httpServletRequest) <-- request.getUserPrincipal()
Run Code Online (Sandbox Code Playgroud)

我很高兴听到解决方案,谢谢.

Jav*_*tar 5

[求助]我找到了解决方案,这里是;

使用

@Context
 protected SecurityContext sc;
Run Code Online (Sandbox Code Playgroud)

要么

Public TestResponse test(@Context SecurityContext sc){
   ..
   sc.getUserPrincipal.getName() //will return username
}
Run Code Online (Sandbox Code Playgroud)