当前位置: 代码迷 >> Web前端 >> Webservice用户密码过滤后持续获取Username
  详细解决方案

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

热度:181   发布时间:2012-09-09 09:27:54.0
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();
}


造福后来人

  相关解决方案