すでに生成されたSOAPエンベロープのセキュリティヘッダーにユーザー名トークンを挿入することは私に2つのヘッダを与えます!
-
19-09-2019 - |
質問
私はすでに形成されたSOAPリクエストエンベロープのヘッダーにユーザー名トークンを追加するためにWSS4Jを使用しています。
ここでは、SOAPリクエストは、次のようになります
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://sample03.samples.rampart.apache.org/xsd">
<soapenv:Header/>
<soapenv:Body>
<xsd:echo>
<xsd:param0>hurro kitty</xsd:param0>
</xsd:echo>
</soapenv:Body></soapenv:Envelope>
これは私のコード(文字列、要求は、要求は、上記)である
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource inStream = new InputSource();
inStream.setCharacterStream(new StringReader(request));
Document document = builder.parse(inStream);
WSSecUsernameToken usernametoken = new WSSecUsernameToken();
usernametoken.setPasswordType(WSConstants.PASSWORD_TEXT);
usernametoken.setUserInfo(username, password);
WSSecHeader secHeader = new WSSecHeader("", false);
secHeader.insertSecurityHeader(document);
usernametoken.build(document, secHeader);
これは私の結果(正常名前空間されていない挿入されたヘッダに気付くだけでなく、2つのヘッダがある)である
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://sample03.samples.rampart.apache.org/xsd">
<Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-2765109" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>bob</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">bobPW</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</Header>
<soapenv:Header/>
<soapenv:Body>
<xsd:echo>
<xsd:param0>hurro kitty</xsd:param0>
</xsd:echo>
</soapenv:Body></soapenv:Envelope>
私が間違って何をしているのですか?
解決
あなたが最初のXMLを構築している場合は、私が間違って何をしているのですか?
、あなたはのDocumentBuilderFactoryが名前空間を認識していることを確認する必要があります。 WSSecurityは、SOAP名前空間でSOAPヘッダーを見つけようとしているが、それは利用できません。次の行を追加すると、それを修正する必要があります:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
...
所属していません StackOverflow