`
lyw985
  • 浏览: 39746 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Webservice用户密码过滤后继续获取Username

阅读更多
Apache CXF + WSS4J

Soap报文如下
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:mustUnderstand="1">
      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
        <wsse:Username>tom</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">123456</wsse:Password>
      </wsse:UsernameToken>
    </wsse:Security>
  </soap:Header>
  <soap:Body>
    <ns1:ListPowerPointTemplates>
    </ns1:ListPowerPointTemplates>
  </soap:Body>
</soap:Envelope>


在Webservice里还是需要UserName来进行具体操作的,但是这个Username已经找不到了,经过网上搜索了,总算在一个角落里找到这么一段代码
@Resource   //这个标签很重要
private WebServiceContext context;

//your Webservice method
public String method(){
    Principal principal = context.getUserPrincipal();
    String userName = principal.getName();
}


造福后来人

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics