[英]Accessing UserName from the Web Service Implementation Class in Java
After authenticating a user using CXF WSAuthentication Interceptor... I need the username in the service implementation (Business Logic). 使用CXF WSAuthentication Interceptor对用户进行身份验证之后,...在服务实现(业务逻辑)中需要用户名。 Wondering if there is a easy way to get access to the Username in the Implementation class? 想知道是否有一种简单的方法可以访问Implementation类中的Username?
declare these in your implementation class: 在实现类中声明这些:
@Resource
private WebServiceContext wsContext;
then in any method do: 然后以任何方法执行:
Principal p = wsContext.getUserPrinciple();
String username = p.getName();
@Resource instructs the web service stack to inject the web service context into your wsContext attribute. @Resource指示Web服务堆栈将Web服务上下文注入到wsContext属性中。
Why not create a user object and place it somewhere in the memory (in a static Map or List etc) with the userName in the wsse:security while while doing the authentication itself? 在进行身份验证时,为什么不创建用户对象并将其以wsse:security中的userName放置在内存中的某个位置(在静态Map或List等中)呢? Once you reach the Service endpoint implementation class, you loose the MessageContext and hence its difficult to read the headers. 到达Service终结点实现类后,您将松开MessageContext,因此很难读取标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.