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

时间:2011-02-16 08:10:52

标签: rest ejb-3.0 restful-authentication basic-authentication

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

webServiceContext.getUserPrincipal().getName() 

(httpServletRequest) <-- request.getUserPrincipal()

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

1 个答案:

答案 0 :(得分:5)

[解决] 我找到了解决方案,就在这里;

使用

@Context
 protected SecurityContext sc;

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