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>
@Resource //这个标签很重要private WebServiceContext context;//your Webservice methodpublic String method(){ Principal principal = context.getUserPrincipal(); String userName = principal.getName();}