You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2011/12/06 11:24:32 UTC
svn commit: r1210847 [35/42] - in /webservices/wss4j/site: ./ apidocs/
apidocs/org/apache/ws/security/ apidocs/org/apache/ws/security/action/
apidocs/org/apache/ws/security/action/class-use/
apidocs/org/apache/ws/security/class-use/ apidocs/org/apache/...
Modified: webservices/wss4j/site/xref/org/apache/ws/security/processor/SignatureProcessor.html
URL: http://svn.apache.org/viewvc/webservices/wss4j/site/xref/org/apache/ws/security/processor/SignatureProcessor.html?rev=1210847&r1=1210846&r2=1210847&view=diff
==============================================================================
--- webservices/wss4j/site/xref/org/apache/ws/security/processor/SignatureProcessor.html (original)
+++ webservices/wss4j/site/xref/org/apache/ws/security/processor/SignatureProcessor.html Tue Dec 6 10:23:54 2011
@@ -73,466 +73,513 @@
<a name="63" href="#63">63</a> <strong class="jxr_keyword">import</strong> javax.xml.crypto.dsig.keyinfo.KeyValue;
<a name="64" href="#64">64</a>
<a name="65" href="#65">65</a> <strong class="jxr_keyword">import</strong> java.security.Key;
-<a name="66" href="#66">66</a> <strong class="jxr_keyword">import</strong> java.security.PublicKey;
-<a name="67" href="#67">67</a> <strong class="jxr_keyword">import</strong> java.security.Principal;
-<a name="68" href="#68">68</a> <strong class="jxr_keyword">import</strong> java.security.cert.X509Certificate;
-<a name="69" href="#69">69</a> <strong class="jxr_keyword">import</strong> java.util.HashMap;
-<a name="70" href="#70">70</a> <strong class="jxr_keyword">import</strong> java.util.List;
-<a name="71" href="#71">71</a> <strong class="jxr_keyword">import</strong> java.util.Map;
-<a name="72" href="#72">72</a>
-<a name="73" href="#73">73</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../org/apache/ws/security/processor/SignatureProcessor.html">SignatureProcessor</a> implements <a href="../../../../../org/apache/ws/security/processor/Processor.html">Processor</a> {
-<a name="74" href="#74">74</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">static</strong> org.apache.commons.logging.Log LOG =
-<a name="75" href="#75">75</a> org.apache.commons.logging.LogFactory.getLog(SignatureProcessor.<strong class="jxr_keyword">class</strong>);
-<a name="76" href="#76">76</a>
-<a name="77" href="#77">77</a> <strong class="jxr_keyword">private</strong> XMLSignatureFactory signatureFactory = XMLSignatureFactory.getInstance(<span class="jxr_string">"DOM"</span>);
+<a name="66" href="#66">66</a> <strong class="jxr_keyword">import</strong> java.security.NoSuchProviderException;
+<a name="67" href="#67">67</a> <strong class="jxr_keyword">import</strong> java.security.PublicKey;
+<a name="68" href="#68">68</a> <strong class="jxr_keyword">import</strong> java.security.Principal;
+<a name="69" href="#69">69</a> <strong class="jxr_keyword">import</strong> java.security.cert.X509Certificate;
+<a name="70" href="#70">70</a> <strong class="jxr_keyword">import</strong> java.util.ArrayList;
+<a name="71" href="#71">71</a> <strong class="jxr_keyword">import</strong> java.util.HashMap;
+<a name="72" href="#72">72</a> <strong class="jxr_keyword">import</strong> java.util.List;
+<a name="73" href="#73">73</a> <strong class="jxr_keyword">import</strong> java.util.Map;
+<a name="74" href="#74">74</a>
+<a name="75" href="#75">75</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../org/apache/ws/security/processor/SignatureProcessor.html">SignatureProcessor</a> implements <a href="../../../../../org/apache/ws/security/processor/Processor.html">Processor</a> {
+<a name="76" href="#76">76</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">static</strong> org.apache.commons.logging.Log LOG =
+<a name="77" href="#77">77</a> org.apache.commons.logging.LogFactory.getLog(SignatureProcessor.<strong class="jxr_keyword">class</strong>);
<a name="78" href="#78">78</a>
-<a name="79" href="#79">79</a> <strong class="jxr_keyword">private</strong> KeyInfoFactory keyInfoFactory = KeyInfoFactory.getInstance(<span class="jxr_string">"DOM"</span>);
-<a name="80" href="#80">80</a>
-<a name="81" href="#81">81</a> <strong class="jxr_keyword">public</strong> List<WSSecurityEngineResult> handleToken(
-<a name="82" href="#82">82</a> Element elem,
-<a name="83" href="#83">83</a> <a href="../../../../../org/apache/ws/security/handler/RequestData.html">RequestData</a> data,
-<a name="84" href="#84">84</a> <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo
-<a name="85" href="#85">85</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="86" href="#86">86</a> <strong class="jxr_keyword">if</strong> (LOG.isDebugEnabled()) {
-<a name="87" href="#87">87</a> LOG.debug(<span class="jxr_string">"Found signature element"</span>);
-<a name="88" href="#88">88</a> }
-<a name="89" href="#89">89</a> Element keyInfoElement =
-<a name="90" href="#90">90</a> WSSecurityUtil.getDirectChildElement(
-<a name="91" href="#91">91</a> elem,
-<a name="92" href="#92">92</a> <span class="jxr_string">"KeyInfo"</span>,
-<a name="93" href="#93">93</a> WSConstants.SIG_NS
-<a name="94" href="#94">94</a> );
-<a name="95" href="#95">95</a> X509Certificate[] certs = <strong class="jxr_keyword">null</strong>;
-<a name="96" href="#96">96</a> Principal principal = <strong class="jxr_keyword">null</strong>;
-<a name="97" href="#97">97</a> PublicKey publicKey = <strong class="jxr_keyword">null</strong>;
-<a name="98" href="#98">98</a> byte[] secretKey = <strong class="jxr_keyword">null</strong>;
-<a name="99" href="#99">99</a> String signatureMethod = getSignatureMethod(elem);
-<a name="100" href="#100">100</a>
-<a name="101" href="#101">101</a> <a href="../../../../../org/apache/ws/security/validate/Validator.html">Validator</a> validator = data.getValidator(WSSecurityEngine.SIGNATURE);
-<a name="102" href="#102">102</a> <strong class="jxr_keyword">if</strong> (keyInfoElement == <strong class="jxr_keyword">null</strong>) {
-<a name="103" href="#103">103</a> certs = getDefaultCerts(data.getSigCrypto());
-<a name="104" href="#104">104</a> principal = certs[0].getSubjectX500Principal();
-<a name="105" href="#105">105</a> } <strong class="jxr_keyword">else</strong> {
-<a name="106" href="#106">106</a> List<Element> strElements =
-<a name="107" href="#107">107</a> WSSecurityUtil.getDirectChildElements(
-<a name="108" href="#108">108</a> keyInfoElement,
-<a name="109" href="#109">109</a> SecurityTokenReference.SECURITY_TOKEN_REFERENCE,
-<a name="110" href="#110">110</a> WSConstants.WSSE_NS
-<a name="111" href="#111">111</a> );
-<a name="112" href="#112">112</a> <strong class="jxr_keyword">if</strong> (data.getWssConfig().isWsiBSPCompliant()) {
-<a name="113" href="#113">113</a> <strong class="jxr_keyword">if</strong> (strElements.isEmpty()) {
-<a name="114" href="#114">114</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="115" href="#115">115</a> WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"noSecurityTokenReference"</span>
-<a name="116" href="#116">116</a> );
-<a name="117" href="#117">117</a> } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (strElements.size() > 1) {
-<a name="118" href="#118">118</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="119" href="#119">119</a> WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"badSecurityTokenReference"</span>
-<a name="120" href="#120">120</a> );
-<a name="121" href="#121">121</a> }
-<a name="122" href="#122">122</a> }
-<a name="123" href="#123">123</a>
-<a name="124" href="#124">124</a> <strong class="jxr_keyword">if</strong> (strElements.isEmpty()) {
-<a name="125" href="#125">125</a> publicKey = parseKeyValue(keyInfoElement);
-<a name="126" href="#126">126</a> <strong class="jxr_keyword">if</strong> (validator != <strong class="jxr_keyword">null</strong>) {
-<a name="127" href="#127">127</a> <a href="../../../../../org/apache/ws/security/validate/Credential.html">Credential</a> credential = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/validate/Credential.html">Credential</a>();
-<a name="128" href="#128">128</a> credential.setPublicKey(publicKey);
-<a name="129" href="#129">129</a> principal = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/PublicKeyPrincipal.html">PublicKeyPrincipal</a>(publicKey);
-<a name="130" href="#130">130</a> credential.setPrincipal(principal);
-<a name="131" href="#131">131</a> validator.validate(credential, data);
-<a name="132" href="#132">132</a> }
-<a name="133" href="#133">133</a> } <strong class="jxr_keyword">else</strong> {
-<a name="134" href="#134">134</a> <a href="../../../../../org/apache/ws/security/str/STRParser.html">STRParser</a> strParser = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/str/SignatureSTRParser.html">SignatureSTRParser</a>();
-<a name="135" href="#135">135</a> Map<String, Object> parameters = <strong class="jxr_keyword">new</strong> HashMap<String, Object>();
-<a name="136" href="#136">136</a> parameters.put(SignatureSTRParser.SIGNATURE_METHOD, signatureMethod);
-<a name="137" href="#137">137</a> parameters.put(
-<a name="138" href="#138">138</a> SignatureSTRParser.SECRET_KEY_LENGTH, <strong class="jxr_keyword">new</strong> Integer(data.getWssConfig().getSecretKeyLength())
-<a name="139" href="#139">139</a> );
-<a name="140" href="#140">140</a> strParser.parseSecurityTokenReference(
-<a name="141" href="#141">141</a> strElements.get(0), data, wsDocInfo, parameters
-<a name="142" href="#142">142</a> );
-<a name="143" href="#143">143</a> principal = strParser.getPrincipal();
-<a name="144" href="#144">144</a> certs = strParser.getCertificates();
-<a name="145" href="#145">145</a> publicKey = strParser.getPublicKey();
-<a name="146" href="#146">146</a> secretKey = strParser.getSecretKey();
-<a name="147" href="#147">147</a>
-<a name="148" href="#148">148</a> <strong class="jxr_keyword">boolean</strong> trusted = strParser.isTrustedCredential();
-<a name="149" href="#149">149</a> <strong class="jxr_keyword">if</strong> (trusted && LOG.isDebugEnabled()) {
-<a name="150" href="#150">150</a> LOG.debug(<span class="jxr_string">"Direct Trust for SAML/BST credential"</span>);
-<a name="151" href="#151">151</a> }
-<a name="152" href="#152">152</a> <strong class="jxr_keyword">if</strong> (!trusted && (publicKey != <strong class="jxr_keyword">null</strong> || certs != <strong class="jxr_keyword">null</strong>) && (validator != <strong class="jxr_keyword">null</strong>)) {
-<a name="153" href="#153">153</a> <a href="../../../../../org/apache/ws/security/validate/Credential.html">Credential</a> credential = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/validate/Credential.html">Credential</a>();
-<a name="154" href="#154">154</a> credential.setPublicKey(publicKey);
-<a name="155" href="#155">155</a> credential.setCertificates(certs);
-<a name="156" href="#156">156</a> credential.setPrincipal(principal);
-<a name="157" href="#157">157</a> validator.validate(credential, data);
-<a name="158" href="#158">158</a> }
-<a name="159" href="#159">159</a> }
-<a name="160" href="#160">160</a> }
-<a name="161" href="#161">161</a>
-<a name="162" href="#162">162</a> <em class="jxr_comment">//</em>
-<a name="163" href="#163">163</a> <em class="jxr_comment">// Check that we have a certificate, a public key or a secret key with which to</em>
-<a name="164" href="#164">164</a> <em class="jxr_comment">// perform signature verification</em>
-<a name="165" href="#165">165</a> <em class="jxr_comment">//</em>
-<a name="166" href="#166">166</a> <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0 || certs[0] == <strong class="jxr_keyword">null</strong>)
-<a name="167" href="#167">167</a> && secretKey == <strong class="jxr_keyword">null</strong>
-<a name="168" href="#168">168</a> && publicKey == <strong class="jxr_keyword">null</strong>) {
-<a name="169" href="#169">169</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK);
-<a name="170" href="#170">170</a> }
-<a name="171" href="#171">171</a>
-<a name="172" href="#172">172</a> XMLSignature xmlSignature =
-<a name="173" href="#173">173</a> verifyXMLSignature(elem, certs, publicKey, secretKey, signatureMethod, wsDocInfo);
-<a name="174" href="#174">174</a> byte[] signatureValue = xmlSignature.getSignatureValue().getValue();
-<a name="175" href="#175">175</a> String c14nMethod = xmlSignature.getSignedInfo().getCanonicalizationMethod().getAlgorithm();
-<a name="176" href="#176">176</a> <em class="jxr_comment">// The c14n algorithm must be as specified by the BSP spec</em>
-<a name="177" href="#177">177</a> <strong class="jxr_keyword">if</strong> (data.getWssConfig().isWsiBSPCompliant()
-<a name="178" href="#178">178</a> && !WSConstants.C14N_EXCL_OMIT_COMMENTS.equals(c14nMethod)) {
-<a name="179" href="#179">179</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="180" href="#180">180</a> WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"badC14nAlgo"</span>
-<a name="181" href="#181">181</a> );
-<a name="182" href="#182">182</a> }
-<a name="183" href="#183">183</a> List<WSDataRef> dataRefs =
-<a name="184" href="#184">184</a> buildProtectedRefs(
-<a name="185" href="#185">185</a> elem.getOwnerDocument(), xmlSignature.getSignedInfo(), data.getWssConfig(), wsDocInfo
-<a name="186" href="#186">186</a> );
-<a name="187" href="#187">187</a> <strong class="jxr_keyword">if</strong> (dataRefs.size() == 0) {
-<a name="188" href="#188">188</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK);
-<a name="189" href="#189">189</a> }
-<a name="190" href="#190">190</a>
-<a name="191" href="#191">191</a> <strong class="jxr_keyword">int</strong> actionPerformed = WSConstants.SIGN;
-<a name="192" href="#192">192</a> <strong class="jxr_keyword">if</strong> (principal instanceof WSUsernameTokenPrincipal) {
-<a name="193" href="#193">193</a> actionPerformed = WSConstants.UT_SIGN;
-<a name="194" href="#194">194</a> }
-<a name="195" href="#195">195</a>
-<a name="196" href="#196">196</a> <a href="../../../../../org/apache/ws/security/WSSecurityEngineResult.html">WSSecurityEngineResult</a> result = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityEngineResult.html">WSSecurityEngineResult</a>(
-<a name="197" href="#197">197</a> actionPerformed, principal,
-<a name="198" href="#198">198</a> certs, dataRefs, signatureValue);
-<a name="199" href="#199">199</a> result.put(WSSecurityEngineResult.TAG_SIGNATURE_METHOD, signatureMethod);
-<a name="200" href="#200">200</a> result.put(WSSecurityEngineResult.TAG_CANONICALIZATION_METHOD, c14nMethod);
-<a name="201" href="#201">201</a> result.put(WSSecurityEngineResult.TAG_ID, elem.getAttribute(<span class="jxr_string">"Id"</span>));
-<a name="202" href="#202">202</a> result.put(WSSecurityEngineResult.TAG_SECRET, secretKey);
-<a name="203" href="#203">203</a> result.put(WSSecurityEngineResult.TAG_PUBLIC_KEY, publicKey);
-<a name="204" href="#204">204</a> <strong class="jxr_keyword">if</strong> (validator != <strong class="jxr_keyword">null</strong>) {
-<a name="205" href="#205">205</a> result.put(WSSecurityEngineResult.TAG_VALIDATED_TOKEN, Boolean.TRUE);
-<a name="206" href="#206">206</a> }
-<a name="207" href="#207">207</a> wsDocInfo.addResult(result);
-<a name="208" href="#208">208</a> wsDocInfo.addTokenElement(elem);
-<a name="209" href="#209">209</a> <strong class="jxr_keyword">return</strong> java.util.Collections.singletonList(result);
-<a name="210" href="#210">210</a> }
-<a name="211" href="#211">211</a>
-<a name="212" href="#212">212</a> <em class="jxr_javadoccomment">/**</em>
-<a name="213" href="#213">213</a> <em class="jxr_javadoccomment"> * Get the default certificates from the KeyStore</em>
-<a name="214" href="#214">214</a> <em class="jxr_javadoccomment"> * @param crypto The Crypto object containing the default alias</em>
-<a name="215" href="#215">215</a> <em class="jxr_javadoccomment"> * @return The default certificates</em>
-<a name="216" href="#216">216</a> <em class="jxr_javadoccomment"> * @throws WSSecurityException</em>
-<a name="217" href="#217">217</a> <em class="jxr_javadoccomment"> */</em>
-<a name="218" href="#218">218</a> <strong class="jxr_keyword">private</strong> X509Certificate[] getDefaultCerts(
-<a name="219" href="#219">219</a> <a href="../../../../../org/apache/ws/security/components/crypto/Crypto.html">Crypto</a> crypto
-<a name="220" href="#220">220</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="221" href="#221">221</a> <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</strong>) {
-<a name="222" href="#222">222</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILURE, <span class="jxr_string">"noSigCryptoFile"</span>);
-<a name="223" href="#223">223</a> }
-<a name="224" href="#224">224</a> <strong class="jxr_keyword">if</strong> (crypto.getDefaultX509Identifier() != <strong class="jxr_keyword">null</strong>) {
-<a name="225" href="#225">225</a> <a href="../../../../../org/apache/ws/security/components/crypto/CryptoType.html">CryptoType</a> cryptoType = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/components/crypto/CryptoType.html">CryptoType</a>(CryptoType.TYPE.ALIAS);
-<a name="226" href="#226">226</a> cryptoType.setAlias(crypto.getDefaultX509Identifier());
-<a name="227" href="#227">227</a> <strong class="jxr_keyword">return</strong> crypto.getX509Certificates(cryptoType);
-<a name="228" href="#228">228</a> } <strong class="jxr_keyword">else</strong> {
-<a name="229" href="#229">229</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="230" href="#230">230</a> WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"unsupportedKeyInfo"</span>
-<a name="231" href="#231">231</a> );
-<a name="232" href="#232">232</a> }
-<a name="233" href="#233">233</a> }
-<a name="234" href="#234">234</a>
-<a name="235" href="#235">235</a> <strong class="jxr_keyword">private</strong> PublicKey parseKeyValue(
-<a name="236" href="#236">236</a> Element keyInfoElement
-<a name="237" href="#237">237</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="238" href="#238">238</a> KeyValue keyValue = <strong class="jxr_keyword">null</strong>;
-<a name="239" href="#239">239</a> <strong class="jxr_keyword">try</strong> {
-<a name="240" href="#240">240</a> <em class="jxr_comment">//</em>
-<a name="241" href="#241">241</a> <em class="jxr_comment">// Look for a KeyValue object</em>
-<a name="242" href="#242">242</a> <em class="jxr_comment">//</em>
-<a name="243" href="#243">243</a> keyValue = getKeyValue(keyInfoElement);
-<a name="244" href="#244">244</a> } <strong class="jxr_keyword">catch</strong> (javax.xml.crypto.MarshalException ex) {
-<a name="245" href="#245">245</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">null</strong>, ex);
-<a name="246" href="#246">246</a> }
-<a name="247" href="#247">247</a>
-<a name="248" href="#248">248</a> <strong class="jxr_keyword">if</strong> (keyValue != <strong class="jxr_keyword">null</strong>) {
-<a name="249" href="#249">249</a> <strong class="jxr_keyword">try</strong> {
-<a name="250" href="#250">250</a> <em class="jxr_comment">//</em>
-<a name="251" href="#251">251</a> <em class="jxr_comment">// Look for a Public Key in Key Value</em>
-<a name="252" href="#252">252</a> <em class="jxr_comment">//</em>
-<a name="253" href="#253">253</a> <strong class="jxr_keyword">return</strong> keyValue.getPublicKey();
-<a name="254" href="#254">254</a> } <strong class="jxr_keyword">catch</strong> (java.security.KeyException ex) {
-<a name="255" href="#255">255</a> LOG.error(ex.getMessage(), ex);
-<a name="256" href="#256">256</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">null</strong>, ex);
-<a name="257" href="#257">257</a> }
-<a name="258" href="#258">258</a> } <strong class="jxr_keyword">else</strong> {
-<a name="259" href="#259">259</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="260" href="#260">260</a> WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"unsupportedKeyInfo"</span>
-<a name="261" href="#261">261</a> );
-<a name="262" href="#262">262</a> }
-<a name="263" href="#263">263</a> }
-<a name="264" href="#264">264</a>
-<a name="265" href="#265">265</a> <em class="jxr_javadoccomment">/**</em>
-<a name="266" href="#266">266</a> <em class="jxr_javadoccomment"> * Get the KeyValue object from the KeyInfo DOM element if it exists</em>
-<a name="267" href="#267">267</a> <em class="jxr_javadoccomment"> */</em>
-<a name="268" href="#268">268</a> <strong class="jxr_keyword">private</strong> KeyValue getKeyValue(
-<a name="269" href="#269">269</a> Element keyInfoElement
-<a name="270" href="#270">270</a> ) <strong class="jxr_keyword">throws</strong> MarshalException {
-<a name="271" href="#271">271</a> XMLStructure keyInfoStructure = <strong class="jxr_keyword">new</strong> DOMStructure(keyInfoElement);
-<a name="272" href="#272">272</a> KeyInfo keyInfo = keyInfoFactory.unmarshalKeyInfo(keyInfoStructure);
-<a name="273" href="#273">273</a> List<?> list = keyInfo.getContent();
-<a name="274" href="#274">274</a>
-<a name="275" href="#275">275</a> <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i < list.size(); i++) {
-<a name="276" href="#276">276</a> XMLStructure xmlStructure = (XMLStructure) list.get(i);
-<a name="277" href="#277">277</a> <strong class="jxr_keyword">if</strong> (xmlStructure instanceof KeyValue) {
-<a name="278" href="#278">278</a> <strong class="jxr_keyword">return</strong> (KeyValue)xmlStructure;
-<a name="279" href="#279">279</a> }
-<a name="280" href="#280">280</a> }
-<a name="281" href="#281">281</a> <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
-<a name="282" href="#282">282</a> }
-<a name="283" href="#283">283</a>
-<a name="284" href="#284">284</a>
-<a name="285" href="#285">285</a> <em class="jxr_javadoccomment">/**</em>
-<a name="286" href="#286">286</a> <em class="jxr_javadoccomment"> * Verify the WS-Security signature.</em>
-<a name="287" href="#287">287</a> <em class="jxr_javadoccomment"> * </em>
-<a name="288" href="#288">288</a> <em class="jxr_javadoccomment"> * The functions at first checks if then <code>KeyInfo</code> that is</em>
-<a name="289" href="#289">289</a> <em class="jxr_javadoccomment"> * contained in the signature contains standard X509 data. If yes then</em>
-<a name="290" href="#290">290</a> <em class="jxr_javadoccomment"> * get the certificate data via the standard <code>KeyInfo</code> methods.</em>
-<a name="291" href="#291">291</a> <em class="jxr_javadoccomment"> * </em>
-<a name="292" href="#292">292</a> <em class="jxr_javadoccomment"> * Otherwise, if the <code>KeyInfo</code> info does not contain X509 data, check</em>
-<a name="293" href="#293">293</a> <em class="jxr_javadoccomment"> * if we can find a <code>wsse:SecurityTokenReference</code> element. If yes, the next</em>
-<a name="294" href="#294">294</a> <em class="jxr_javadoccomment"> * step is to check how to get the certificate. Two methods are currently supported</em>
-<a name="295" href="#295">295</a> <em class="jxr_javadoccomment"> * here:</em>
-<a name="296" href="#296">296</a> <em class="jxr_javadoccomment"> * <ul></em>
-<a name="297" href="#297">297</a> <em class="jxr_javadoccomment"> * <li> A URI reference to a binary security token contained in the <code>wsse:Security</em>
-<a name="298" href="#298">298</a> <em class="jxr_javadoccomment"> * </code> header. If the dereferenced token is</em>
-<a name="299" href="#299">299</a> <em class="jxr_javadoccomment"> * of the correct type the contained certificate is extracted.</em>
-<a name="300" href="#300">300</a> <em class="jxr_javadoccomment"> * </li></em>
-<a name="301" href="#301">301</a> <em class="jxr_javadoccomment"> * <li> Issuer name an serial number of the certificate. In this case the method</em>
-<a name="302" href="#302">302</a> <em class="jxr_javadoccomment"> * looks up the certificate in the keystore via the <code>crypto</code> parameter.</em>
-<a name="303" href="#303">303</a> <em class="jxr_javadoccomment"> * </li></em>
-<a name="304" href="#304">304</a> <em class="jxr_javadoccomment"> * </ul></em>
-<a name="305" href="#305">305</a> <em class="jxr_javadoccomment"> * </em>
-<a name="306" href="#306">306</a> <em class="jxr_javadoccomment"> * @param elem the XMLSignature DOM Element.</em>
-<a name="307" href="#307">307</a> <em class="jxr_javadoccomment"> * @param crypto the object that implements the access to the keystore and the</em>
-<a name="308" href="#308">308</a> <em class="jxr_javadoccomment"> * handling of certificates.</em>
-<a name="309" href="#309">309</a> <em class="jxr_javadoccomment"> * @param protectedRefs A list of (references) to the signed elements</em>
-<a name="310" href="#310">310</a> <em class="jxr_javadoccomment"> * @param cb CallbackHandler instance to extract key passwords</em>
-<a name="311" href="#311">311</a> <em class="jxr_javadoccomment"> * @return the subject principal of the validated X509 certificate (the</em>
-<a name="312" href="#312">312</a> <em class="jxr_javadoccomment"> * authenticated subject). The calling function may use this</em>
-<a name="313" href="#313">313</a> <em class="jxr_javadoccomment"> * principal for further authentication or authorization.</em>
-<a name="314" href="#314">314</a> <em class="jxr_javadoccomment"> * @throws WSSecurityException</em>
-<a name="315" href="#315">315</a> <em class="jxr_javadoccomment"> */</em>
-<a name="316" href="#316">316</a> <strong class="jxr_keyword">private</strong> XMLSignature verifyXMLSignature(
-<a name="317" href="#317">317</a> Element elem,
-<a name="318" href="#318">318</a> X509Certificate[] certs,
-<a name="319" href="#319">319</a> PublicKey publicKey,
-<a name="320" href="#320">320</a> byte[] secretKey,
-<a name="321" href="#321">321</a> String signatureMethod,
-<a name="322" href="#322">322</a> <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo
-<a name="323" href="#323">323</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="324" href="#324">324</a> <strong class="jxr_keyword">if</strong> (LOG.isDebugEnabled()) {
-<a name="325" href="#325">325</a> LOG.debug(<span class="jxr_string">"Verify XML Signature"</span>);
-<a name="326" href="#326">326</a> }
-<a name="327" href="#327">327</a>
-<a name="328" href="#328">328</a> <em class="jxr_comment">//</em>
-<a name="329" href="#329">329</a> <em class="jxr_comment">// Perform the signature verification and build up a List of elements that the</em>
-<a name="330" href="#330">330</a> <em class="jxr_comment">// signature refers to</em>
-<a name="331" href="#331">331</a> <em class="jxr_comment">//</em>
-<a name="332" href="#332">332</a> Key key = <strong class="jxr_keyword">null</strong>;
-<a name="333" href="#333">333</a> <strong class="jxr_keyword">if</strong> (certs != <strong class="jxr_keyword">null</strong> && certs[0] != <strong class="jxr_keyword">null</strong>) {
-<a name="334" href="#334">334</a> key = certs[0].getPublicKey();
-<a name="335" href="#335">335</a> } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (publicKey != <strong class="jxr_keyword">null</strong>) {
-<a name="336" href="#336">336</a> key = publicKey;
-<a name="337" href="#337">337</a> } <strong class="jxr_keyword">else</strong> {
-<a name="338" href="#338">338</a> key = WSSecurityUtil.prepareSecretKey(signatureMethod, secretKey);
-<a name="339" href="#339">339</a> }
-<a name="340" href="#340">340</a>
-<a name="341" href="#341">341</a> XMLValidateContext context = <strong class="jxr_keyword">new</strong> DOMValidateContext(key, elem);
-<a name="342" href="#342">342</a> context.setProperty(<span class="jxr_string">"javax.xml.crypto.dsig.cacheReference"</span>, Boolean.TRUE);
-<a name="343" href="#343">343</a> context.setProperty(STRTransform.TRANSFORM_WS_DOC_INFO, wsDocInfo);
-<a name="344" href="#344">344</a>
-<a name="345" href="#345">345</a> <strong class="jxr_keyword">try</strong> {
-<a name="346" href="#346">346</a> XMLSignature xmlSignature = signatureFactory.unmarshalXMLSignature(context);
-<a name="347" href="#347">347</a> setElementsOnContext(xmlSignature, (DOMValidateContext)context, wsDocInfo, elem.getOwnerDocument());
-<a name="348" href="#348">348</a> <strong class="jxr_keyword">boolean</strong> signatureOk = xmlSignature.validate(context);
-<a name="349" href="#349">349</a> <strong class="jxr_keyword">if</strong> (signatureOk) {
-<a name="350" href="#350">350</a> <strong class="jxr_keyword">return</strong> xmlSignature;
-<a name="351" href="#351">351</a> }
-<a name="352" href="#352">352</a> <em class="jxr_comment">//</em>
-<a name="353" href="#353">353</a> <em class="jxr_comment">// Log the exact signature error</em>
-<a name="354" href="#354">354</a> <em class="jxr_comment">//</em>
-<a name="355" href="#355">355</a> <strong class="jxr_keyword">if</strong> (LOG.isDebugEnabled()) {
-<a name="356" href="#356">356</a> LOG.debug(<span class="jxr_string">"XML Signature verification has failed"</span>);
-<a name="357" href="#357">357</a> <strong class="jxr_keyword">boolean</strong> signatureValidationCheck =
-<a name="358" href="#358">358</a> xmlSignature.getSignatureValue().validate(context);
-<a name="359" href="#359">359</a> LOG.debug(<span class="jxr_string">"Signature Validation check: "</span> + signatureValidationCheck);
-<a name="360" href="#360">360</a> java.util.Iterator<?> referenceIterator =
-<a name="361" href="#361">361</a> xmlSignature.getSignedInfo().getReferences().iterator();
-<a name="362" href="#362">362</a> <strong class="jxr_keyword">while</strong> (referenceIterator.hasNext()) {
-<a name="363" href="#363">363</a> <a href="../../../../../org/apache/ws/security/message/token/Reference.html">Reference</a> reference = (Reference)referenceIterator.next();
-<a name="364" href="#364">364</a> <strong class="jxr_keyword">boolean</strong> referenceValidationCheck = reference.validate(context);
-<a name="365" href="#365">365</a> String id = reference.getId();
-<a name="366" href="#366">366</a> <strong class="jxr_keyword">if</strong> (id == <strong class="jxr_keyword">null</strong>) {
-<a name="367" href="#367">367</a> id = reference.getURI();
-<a name="368" href="#368">368</a> }
-<a name="369" href="#369">369</a> LOG.debug(<span class="jxr_string">"Reference "</span> + id + <span class="jxr_string">" check: "</span> + referenceValidationCheck);
-<a name="370" href="#370">370</a> }
-<a name="371" href="#371">371</a> }
-<a name="372" href="#372">372</a> } <strong class="jxr_keyword">catch</strong> (Exception ex) {
-<a name="373" href="#373">373</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="374" href="#374">374</a> WSSecurityException.FAILED_CHECK, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">null</strong>, ex
-<a name="375" href="#375">375</a> );
-<a name="376" href="#376">376</a> }
-<a name="377" href="#377">377</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK);
-<a name="378" href="#378">378</a> }
-<a name="379" href="#379">379</a>
-<a name="380" href="#380">380</a> <em class="jxr_javadoccomment">/**</em>
-<a name="381" href="#381">381</a> <em class="jxr_javadoccomment"> * Retrieve the Reference elements and set them on the ValidateContext</em>
-<a name="382" href="#382">382</a> <em class="jxr_javadoccomment"> * @param xmlSignature the XMLSignature object to get the references from</em>
-<a name="383" href="#383">383</a> <em class="jxr_javadoccomment"> * @param context the ValidateContext</em>
-<a name="384" href="#384">384</a> <em class="jxr_javadoccomment"> * @param wsDocInfo the WSDocInfo object where tokens are stored</em>
-<a name="385" href="#385">385</a> <em class="jxr_javadoccomment"> * @param doc the owner document from which to find elements</em>
-<a name="386" href="#386">386</a> <em class="jxr_javadoccomment"> * @throws WSSecurityException</em>
-<a name="387" href="#387">387</a> <em class="jxr_javadoccomment"> */</em>
-<a name="388" href="#388">388</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> setElementsOnContext(
-<a name="389" href="#389">389</a> XMLSignature xmlSignature,
-<a name="390" href="#390">390</a> DOMValidateContext context,
-<a name="391" href="#391">391</a> <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo,
-<a name="392" href="#392">392</a> Document doc
-<a name="393" href="#393">393</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="394" href="#394">394</a> java.util.Iterator<?> referenceIterator =
-<a name="395" href="#395">395</a> xmlSignature.getSignedInfo().getReferences().iterator();
-<a name="396" href="#396">396</a> <a href="../../../../../org/apache/ws/security/message/CallbackLookup.html">CallbackLookup</a> callbackLookup = wsDocInfo.getCallbackLookup();
-<a name="397" href="#397">397</a> <strong class="jxr_keyword">if</strong> (callbackLookup == <strong class="jxr_keyword">null</strong>) {
-<a name="398" href="#398">398</a> callbackLookup = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/message/DOMCallbackLookup.html">DOMCallbackLookup</a>(doc);
-<a name="399" href="#399">399</a> }
-<a name="400" href="#400">400</a> <strong class="jxr_keyword">while</strong> (referenceIterator.hasNext()) {
-<a name="401" href="#401">401</a> <a href="../../../../../org/apache/ws/security/message/token/Reference.html">Reference</a> reference = (Reference)referenceIterator.next();
-<a name="402" href="#402">402</a> String uri = reference.getURI();
-<a name="403" href="#403">403</a> Element element = callbackLookup.getElement(uri, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">true</strong>);
-<a name="404" href="#404">404</a> <strong class="jxr_keyword">if</strong> (element == <strong class="jxr_keyword">null</strong>) {
-<a name="405" href="#405">405</a> element = wsDocInfo.getTokenElement(uri);
-<a name="406" href="#406">406</a> }
-<a name="407" href="#407">407</a> <strong class="jxr_keyword">if</strong> (element != <strong class="jxr_keyword">null</strong>) {
-<a name="408" href="#408">408</a> WSSecurityUtil.storeElementInContext(((DOMValidateContext)context), element);
-<a name="409" href="#409">409</a> }
-<a name="410" href="#410">410</a> }
-<a name="411" href="#411">411</a> }
-<a name="412" href="#412">412</a>
-<a name="413" href="#413">413</a> <em class="jxr_javadoccomment">/**</em>
-<a name="414" href="#414">414</a> <em class="jxr_javadoccomment"> * Get the signature method algorithm URI from the associated signature element.</em>
-<a name="415" href="#415">415</a> <em class="jxr_javadoccomment"> * @param signatureElement The signature element</em>
-<a name="416" href="#416">416</a> <em class="jxr_javadoccomment"> * @return the signature method URI</em>
-<a name="417" href="#417">417</a> <em class="jxr_javadoccomment"> */</em>
-<a name="418" href="#418">418</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">static</strong> String getSignatureMethod(
-<a name="419" href="#419">419</a> Element signatureElement
-<a name="420" href="#420">420</a> ) {
-<a name="421" href="#421">421</a> Element signedInfoElement =
-<a name="422" href="#422">422</a> WSSecurityUtil.getDirectChildElement(
-<a name="423" href="#423">423</a> signatureElement,
-<a name="424" href="#424">424</a> <span class="jxr_string">"SignedInfo"</span>,
-<a name="425" href="#425">425</a> WSConstants.SIG_NS
-<a name="426" href="#426">426</a> );
-<a name="427" href="#427">427</a> <strong class="jxr_keyword">if</strong> (signedInfoElement != <strong class="jxr_keyword">null</strong>) {
-<a name="428" href="#428">428</a> Element signatureMethodElement =
-<a name="429" href="#429">429</a> WSSecurityUtil.getDirectChildElement(
-<a name="430" href="#430">430</a> signedInfoElement,
-<a name="431" href="#431">431</a> <span class="jxr_string">"SignatureMethod"</span>,
-<a name="432" href="#432">432</a> WSConstants.SIG_NS
-<a name="433" href="#433">433</a> );
-<a name="434" href="#434">434</a> <strong class="jxr_keyword">if</strong> (signatureMethodElement != <strong class="jxr_keyword">null</strong>) {
-<a name="435" href="#435">435</a> <strong class="jxr_keyword">return</strong> signatureMethodElement.getAttributeNS(<strong class="jxr_keyword">null</strong>, <span class="jxr_string">"Algorithm"</span>);
-<a name="436" href="#436">436</a> }
-<a name="437" href="#437">437</a> }
-<a name="438" href="#438">438</a> <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
-<a name="439" href="#439">439</a> }
-<a name="440" href="#440">440</a>
-<a name="441" href="#441">441</a>
-<a name="442" href="#442">442</a> <em class="jxr_javadoccomment">/**</em>
-<a name="443" href="#443">443</a> <em class="jxr_javadoccomment"> * This method digs into the Signature element to get the elements that</em>
-<a name="444" href="#444">444</a> <em class="jxr_javadoccomment"> * this Signature covers. Build the QName of these Elements and return them</em>
-<a name="445" href="#445">445</a> <em class="jxr_javadoccomment"> * to caller</em>
-<a name="446" href="#446">446</a> <em class="jxr_javadoccomment"> * @param doc The owning document</em>
-<a name="447" href="#447">447</a> <em class="jxr_javadoccomment"> * @param signedInfo The SignedInfo object</em>
-<a name="448" href="#448">448</a> <em class="jxr_javadoccomment"> * @param wssConfig A WSSConfig instance</em>
-<a name="449" href="#449">449</a> <em class="jxr_javadoccomment"> * @param protectedRefs A list of protected references</em>
-<a name="450" href="#450">450</a> <em class="jxr_javadoccomment"> * @return A list of protected references</em>
-<a name="451" href="#451">451</a> <em class="jxr_javadoccomment"> * @throws WSSecurityException</em>
-<a name="452" href="#452">452</a> <em class="jxr_javadoccomment"> */</em>
-<a name="453" href="#453">453</a> <strong class="jxr_keyword">private</strong> List<WSDataRef> buildProtectedRefs(
-<a name="454" href="#454">454</a> Document doc,
-<a name="455" href="#455">455</a> SignedInfo signedInfo,
-<a name="456" href="#456">456</a> <a href="../../../../../org/apache/ws/security/WSSConfig.html">WSSConfig</a> wssConfig,
-<a name="457" href="#457">457</a> <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo
-<a name="458" href="#458">458</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="459" href="#459">459</a> List<WSDataRef> protectedRefs = <strong class="jxr_keyword">new</strong> java.util.ArrayList<WSDataRef>();
-<a name="460" href="#460">460</a> List<?> referencesList = signedInfo.getReferences();
-<a name="461" href="#461">461</a> <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i < referencesList.size(); i++) {
-<a name="462" href="#462">462</a> <a href="../../../../../org/apache/ws/security/message/token/Reference.html">Reference</a> siRef = (Reference)referencesList.get(i);
-<a name="463" href="#463">463</a> String uri = siRef.getURI();
-<a name="464" href="#464">464</a>
-<a name="465" href="#465">465</a> <strong class="jxr_keyword">if</strong> (!<span class="jxr_string">""</span>.equals(uri)) {
-<a name="466" href="#466">466</a> Element se = <strong class="jxr_keyword">null</strong>;
-<a name="467" href="#467">467</a>
-<a name="468" href="#468">468</a> List<?> transformsList = siRef.getTransforms();
-<a name="469" href="#469">469</a>
-<a name="470" href="#470">470</a> <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> j = 0; j < transformsList.size(); j++) {
-<a name="471" href="#471">471</a>
-<a name="472" href="#472">472</a> Transform transform = (Transform)transformsList.get(j);
-<a name="473" href="#473">473</a>
-<a name="474" href="#474">474</a> <strong class="jxr_keyword">if</strong> (STRTransform.TRANSFORM_URI.equals(transform.getAlgorithm())) {
-<a name="475" href="#475">475</a> NodeSetData data = (NodeSetData)siRef.getDereferencedData();
-<a name="476" href="#476">476</a> <strong class="jxr_keyword">if</strong> (data != <strong class="jxr_keyword">null</strong>) {
-<a name="477" href="#477">477</a> java.util.Iterator<?> iter = data.iterator();
-<a name="478" href="#478">478</a>
-<a name="479" href="#479">479</a> Node securityTokenReference = <strong class="jxr_keyword">null</strong>;
-<a name="480" href="#480">480</a> <strong class="jxr_keyword">while</strong> (iter.hasNext()) {
-<a name="481" href="#481">481</a> Node node = (Node)iter.next();
-<a name="482" href="#482">482</a> <strong class="jxr_keyword">if</strong> (<span class="jxr_string">"SecurityTokenReference"</span>.equals(node.getLocalName())) {
-<a name="483" href="#483">483</a> securityTokenReference = node;
-<a name="484" href="#484">484</a> <strong class="jxr_keyword">break</strong>;
-<a name="485" href="#485">485</a> }
-<a name="486" href="#486">486</a> }
-<a name="487" href="#487">487</a>
-<a name="488" href="#488">488</a> <strong class="jxr_keyword">if</strong> (securityTokenReference != <strong class="jxr_keyword">null</strong>) {
-<a name="489" href="#489">489</a> <a href="../../../../../org/apache/ws/security/message/token/SecurityTokenReference.html">SecurityTokenReference</a> secTokenRef =
-<a name="490" href="#490">490</a> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/message/token/SecurityTokenReference.html">SecurityTokenReference</a>(
-<a name="491" href="#491">491</a> (Element)securityTokenReference,
-<a name="492" href="#492">492</a> wssConfig.isWsiBSPCompliant()
-<a name="493" href="#493">493</a> );
-<a name="494" href="#494">494</a> se = STRTransformUtil.dereferenceSTR(doc, secTokenRef, wsDocInfo);
-<a name="495" href="#495">495</a> }
-<a name="496" href="#496">496</a> }
-<a name="497" href="#497">497</a> }
-<a name="498" href="#498">498</a> }
-<a name="499" href="#499">499</a>
-<a name="500" href="#500">500</a> <strong class="jxr_keyword">if</strong> (se == <strong class="jxr_keyword">null</strong>) {
-<a name="501" href="#501">501</a> <a href="../../../../../org/apache/ws/security/message/CallbackLookup.html">CallbackLookup</a> callbackLookup = wsDocInfo.getCallbackLookup();
-<a name="502" href="#502">502</a> <strong class="jxr_keyword">if</strong> (callbackLookup == <strong class="jxr_keyword">null</strong>) {
-<a name="503" href="#503">503</a> callbackLookup = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/message/DOMCallbackLookup.html">DOMCallbackLookup</a>(doc);
-<a name="504" href="#504">504</a> }
-<a name="505" href="#505">505</a> se = callbackLookup.getElement(uri, <strong class="jxr_keyword">null</strong>, false);
-<a name="506" href="#506">506</a> }
-<a name="507" href="#507">507</a> <strong class="jxr_keyword">if</strong> (se == <strong class="jxr_keyword">null</strong>) {
-<a name="508" href="#508">508</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK);
-<a name="509" href="#509">509</a> }
-<a name="510" href="#510">510</a>
-<a name="511" href="#511">511</a> <a href="../../../../../org/apache/ws/security/WSDataRef.html">WSDataRef</a> ref = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSDataRef.html">WSDataRef</a>();
-<a name="512" href="#512">512</a> ref.setWsuId(uri);
-<a name="513" href="#513">513</a> ref.setProtectedElement(se);
-<a name="514" href="#514">514</a> ref.setAlgorithm(signedInfo.getSignatureMethod().getAlgorithm());
-<a name="515" href="#515">515</a> ref.setDigestAlgorithm(siRef.getDigestMethod().getAlgorithm());
-<a name="516" href="#516">516</a> ref.setXpath(ReferenceListProcessor.getXPath(se));
-<a name="517" href="#517">517</a> protectedRefs.add(ref);
-<a name="518" href="#518">518</a> }
-<a name="519" href="#519">519</a> }
-<a name="520" href="#520">520</a> <strong class="jxr_keyword">return</strong> protectedRefs;
-<a name="521" href="#521">521</a> }
-<a name="522" href="#522">522</a>
+<a name="79" href="#79">79</a> <strong class="jxr_keyword">private</strong> XMLSignatureFactory signatureFactory;
+<a name="80" href="#80">80</a> <strong class="jxr_keyword">private</strong> KeyInfoFactory keyInfoFactory;
+<a name="81" href="#81">81</a>
+<a name="82" href="#82">82</a> <strong class="jxr_keyword">public</strong> <a href="../../../../../org/apache/ws/security/processor/SignatureProcessor.html">SignatureProcessor</a>() {
+<a name="83" href="#83">83</a> <em class="jxr_comment">// Try to install the Santuario Provider - fall back to the JDK provider if this does</em>
+<a name="84" href="#84">84</a> <em class="jxr_comment">// not work</em>
+<a name="85" href="#85">85</a> <strong class="jxr_keyword">try</strong> {
+<a name="86" href="#86">86</a> signatureFactory = XMLSignatureFactory.getInstance(<span class="jxr_string">"DOM"</span>, <span class="jxr_string">"ApacheXMLDSig"</span>);
+<a name="87" href="#87">87</a> } <strong class="jxr_keyword">catch</strong> (NoSuchProviderException ex) {
+<a name="88" href="#88">88</a> signatureFactory = XMLSignatureFactory.getInstance(<span class="jxr_string">"DOM"</span>);
+<a name="89" href="#89">89</a> }
+<a name="90" href="#90">90</a> <strong class="jxr_keyword">try</strong> {
+<a name="91" href="#91">91</a> keyInfoFactory = KeyInfoFactory.getInstance(<span class="jxr_string">"DOM"</span>, <span class="jxr_string">"ApacheXMLDSig"</span>);
+<a name="92" href="#92">92</a> } <strong class="jxr_keyword">catch</strong> (NoSuchProviderException ex) {
+<a name="93" href="#93">93</a> keyInfoFactory = KeyInfoFactory.getInstance(<span class="jxr_string">"DOM"</span>);
+<a name="94" href="#94">94</a> }
+<a name="95" href="#95">95</a> }
+<a name="96" href="#96">96</a>
+<a name="97" href="#97">97</a> <strong class="jxr_keyword">public</strong> List<WSSecurityEngineResult> handleToken(
+<a name="98" href="#98">98</a> Element elem,
+<a name="99" href="#99">99</a> <a href="../../../../../org/apache/ws/security/handler/RequestData.html">RequestData</a> data,
+<a name="100" href="#100">100</a> <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo
+<a name="101" href="#101">101</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="102" href="#102">102</a> <strong class="jxr_keyword">if</strong> (LOG.isDebugEnabled()) {
+<a name="103" href="#103">103</a> LOG.debug(<span class="jxr_string">"Found signature element"</span>);
+<a name="104" href="#104">104</a> }
+<a name="105" href="#105">105</a> Element keyInfoElement =
+<a name="106" href="#106">106</a> WSSecurityUtil.getDirectChildElement(
+<a name="107" href="#107">107</a> elem,
+<a name="108" href="#108">108</a> <span class="jxr_string">"KeyInfo"</span>,
+<a name="109" href="#109">109</a> WSConstants.SIG_NS
+<a name="110" href="#110">110</a> );
+<a name="111" href="#111">111</a> X509Certificate[] certs = <strong class="jxr_keyword">null</strong>;
+<a name="112" href="#112">112</a> Principal principal = <strong class="jxr_keyword">null</strong>;
+<a name="113" href="#113">113</a> PublicKey publicKey = <strong class="jxr_keyword">null</strong>;
+<a name="114" href="#114">114</a> byte[] secretKey = <strong class="jxr_keyword">null</strong>;
+<a name="115" href="#115">115</a> String signatureMethod = getSignatureMethod(elem);
+<a name="116" href="#116">116</a>
+<a name="117" href="#117">117</a> <a href="../../../../../org/apache/ws/security/validate/Validator.html">Validator</a> validator = data.getValidator(WSSecurityEngine.SIGNATURE);
+<a name="118" href="#118">118</a> <strong class="jxr_keyword">if</strong> (keyInfoElement == <strong class="jxr_keyword">null</strong>) {
+<a name="119" href="#119">119</a> certs = getDefaultCerts(data.getSigCrypto());
+<a name="120" href="#120">120</a> principal = certs[0].getSubjectX500Principal();
+<a name="121" href="#121">121</a> } <strong class="jxr_keyword">else</strong> {
+<a name="122" href="#122">122</a> List<Element> strElements =
+<a name="123" href="#123">123</a> WSSecurityUtil.getDirectChildElements(
+<a name="124" href="#124">124</a> keyInfoElement,
+<a name="125" href="#125">125</a> SecurityTokenReference.SECURITY_TOKEN_REFERENCE,
+<a name="126" href="#126">126</a> WSConstants.WSSE_NS
+<a name="127" href="#127">127</a> );
+<a name="128" href="#128">128</a> <strong class="jxr_keyword">if</strong> (data.getWssConfig().isWsiBSPCompliant()) {
+<a name="129" href="#129">129</a> <strong class="jxr_keyword">if</strong> (strElements.isEmpty()) {
+<a name="130" href="#130">130</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="131" href="#131">131</a> WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"noSecurityTokenReference"</span>
+<a name="132" href="#132">132</a> );
+<a name="133" href="#133">133</a> } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (strElements.size() > 1) {
+<a name="134" href="#134">134</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="135" href="#135">135</a> WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"badSecurityTokenReference"</span>
+<a name="136" href="#136">136</a> );
+<a name="137" href="#137">137</a> }
+<a name="138" href="#138">138</a> }
+<a name="139" href="#139">139</a>
+<a name="140" href="#140">140</a> <strong class="jxr_keyword">if</strong> (strElements.isEmpty()) {
+<a name="141" href="#141">141</a> publicKey = parseKeyValue(keyInfoElement);
+<a name="142" href="#142">142</a> <strong class="jxr_keyword">if</strong> (validator != <strong class="jxr_keyword">null</strong>) {
+<a name="143" href="#143">143</a> <a href="../../../../../org/apache/ws/security/validate/Credential.html">Credential</a> credential = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/validate/Credential.html">Credential</a>();
+<a name="144" href="#144">144</a> credential.setPublicKey(publicKey);
+<a name="145" href="#145">145</a> principal = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/PublicKeyPrincipal.html">PublicKeyPrincipal</a>(publicKey);
+<a name="146" href="#146">146</a> credential.setPrincipal(principal);
+<a name="147" href="#147">147</a> validator.validate(credential, data);
+<a name="148" href="#148">148</a> }
+<a name="149" href="#149">149</a> } <strong class="jxr_keyword">else</strong> {
+<a name="150" href="#150">150</a> <a href="../../../../../org/apache/ws/security/str/STRParser.html">STRParser</a> strParser = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/str/SignatureSTRParser.html">SignatureSTRParser</a>();
+<a name="151" href="#151">151</a> Map<String, Object> parameters = <strong class="jxr_keyword">new</strong> HashMap<String, Object>();
+<a name="152" href="#152">152</a> parameters.put(SignatureSTRParser.SIGNATURE_METHOD, signatureMethod);
+<a name="153" href="#153">153</a> parameters.put(
+<a name="154" href="#154">154</a> SignatureSTRParser.SECRET_KEY_LENGTH, <strong class="jxr_keyword">new</strong> Integer(data.getWssConfig().getSecretKeyLength())
+<a name="155" href="#155">155</a> );
+<a name="156" href="#156">156</a> strParser.parseSecurityTokenReference(
+<a name="157" href="#157">157</a> strElements.get(0), data, wsDocInfo, parameters
+<a name="158" href="#158">158</a> );
+<a name="159" href="#159">159</a> principal = strParser.getPrincipal();
+<a name="160" href="#160">160</a> certs = strParser.getCertificates();
+<a name="161" href="#161">161</a> publicKey = strParser.getPublicKey();
+<a name="162" href="#162">162</a> secretKey = strParser.getSecretKey();
+<a name="163" href="#163">163</a>
+<a name="164" href="#164">164</a> <strong class="jxr_keyword">boolean</strong> trusted = strParser.isTrustedCredential();
+<a name="165" href="#165">165</a> <strong class="jxr_keyword">if</strong> (trusted && LOG.isDebugEnabled()) {
+<a name="166" href="#166">166</a> LOG.debug(<span class="jxr_string">"Direct Trust for SAML/BST credential"</span>);
+<a name="167" href="#167">167</a> }
+<a name="168" href="#168">168</a> <strong class="jxr_keyword">if</strong> (!trusted && (publicKey != <strong class="jxr_keyword">null</strong> || certs != <strong class="jxr_keyword">null</strong>) && (validator != <strong class="jxr_keyword">null</strong>)) {
+<a name="169" href="#169">169</a> <a href="../../../../../org/apache/ws/security/validate/Credential.html">Credential</a> credential = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/validate/Credential.html">Credential</a>();
+<a name="170" href="#170">170</a> credential.setPublicKey(publicKey);
+<a name="171" href="#171">171</a> credential.setCertificates(certs);
+<a name="172" href="#172">172</a> credential.setPrincipal(principal);
+<a name="173" href="#173">173</a> validator.validate(credential, data);
+<a name="174" href="#174">174</a> }
+<a name="175" href="#175">175</a> }
+<a name="176" href="#176">176</a> }
+<a name="177" href="#177">177</a>
+<a name="178" href="#178">178</a> <em class="jxr_comment">//</em>
+<a name="179" href="#179">179</a> <em class="jxr_comment">// Check that we have a certificate, a public key or a secret key with which to</em>
+<a name="180" href="#180">180</a> <em class="jxr_comment">// perform signature verification</em>
+<a name="181" href="#181">181</a> <em class="jxr_comment">//</em>
+<a name="182" href="#182">182</a> <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0 || certs[0] == <strong class="jxr_keyword">null</strong>)
+<a name="183" href="#183">183</a> && secretKey == <strong class="jxr_keyword">null</strong>
+<a name="184" href="#184">184</a> && publicKey == <strong class="jxr_keyword">null</strong>) {
+<a name="185" href="#185">185</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK);
+<a name="186" href="#186">186</a> }
+<a name="187" href="#187">187</a>
+<a name="188" href="#188">188</a> XMLSignature xmlSignature =
+<a name="189" href="#189">189</a> verifyXMLSignature(elem, certs, publicKey, secretKey, signatureMethod, wsDocInfo);
+<a name="190" href="#190">190</a> byte[] signatureValue = xmlSignature.getSignatureValue().getValue();
+<a name="191" href="#191">191</a> String c14nMethod = xmlSignature.getSignedInfo().getCanonicalizationMethod().getAlgorithm();
+<a name="192" href="#192">192</a> <em class="jxr_comment">// The c14n algorithm must be as specified by the BSP spec</em>
+<a name="193" href="#193">193</a> <strong class="jxr_keyword">if</strong> (data.getWssConfig().isWsiBSPCompliant()
+<a name="194" href="#194">194</a> && !WSConstants.C14N_EXCL_OMIT_COMMENTS.equals(c14nMethod)) {
+<a name="195" href="#195">195</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="196" href="#196">196</a> WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"badC14nAlgo"</span>
+<a name="197" href="#197">197</a> );
+<a name="198" href="#198">198</a> }
+<a name="199" href="#199">199</a> List<WSDataRef> dataRefs =
+<a name="200" href="#200">200</a> buildProtectedRefs(
+<a name="201" href="#201">201</a> elem.getOwnerDocument(), xmlSignature.getSignedInfo(), data.getWssConfig(), wsDocInfo
+<a name="202" href="#202">202</a> );
+<a name="203" href="#203">203</a> <strong class="jxr_keyword">if</strong> (dataRefs.size() == 0) {
+<a name="204" href="#204">204</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK);
+<a name="205" href="#205">205</a> }
+<a name="206" href="#206">206</a>
+<a name="207" href="#207">207</a> <strong class="jxr_keyword">int</strong> actionPerformed = WSConstants.SIGN;
+<a name="208" href="#208">208</a> <strong class="jxr_keyword">if</strong> (principal instanceof WSUsernameTokenPrincipal) {
+<a name="209" href="#209">209</a> actionPerformed = WSConstants.UT_SIGN;
+<a name="210" href="#210">210</a> }
+<a name="211" href="#211">211</a>
+<a name="212" href="#212">212</a> <a href="../../../../../org/apache/ws/security/WSSecurityEngineResult.html">WSSecurityEngineResult</a> result = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityEngineResult.html">WSSecurityEngineResult</a>(
+<a name="213" href="#213">213</a> actionPerformed, principal,
+<a name="214" href="#214">214</a> certs, dataRefs, signatureValue);
+<a name="215" href="#215">215</a> result.put(WSSecurityEngineResult.TAG_SIGNATURE_METHOD, signatureMethod);
+<a name="216" href="#216">216</a> result.put(WSSecurityEngineResult.TAG_CANONICALIZATION_METHOD, c14nMethod);
+<a name="217" href="#217">217</a> result.put(WSSecurityEngineResult.TAG_ID, elem.getAttribute(<span class="jxr_string">"Id"</span>));
+<a name="218" href="#218">218</a> result.put(WSSecurityEngineResult.TAG_SECRET, secretKey);
+<a name="219" href="#219">219</a> result.put(WSSecurityEngineResult.TAG_PUBLIC_KEY, publicKey);
+<a name="220" href="#220">220</a> <strong class="jxr_keyword">if</strong> (validator != <strong class="jxr_keyword">null</strong>) {
+<a name="221" href="#221">221</a> result.put(WSSecurityEngineResult.TAG_VALIDATED_TOKEN, Boolean.TRUE);
+<a name="222" href="#222">222</a> }
+<a name="223" href="#223">223</a> wsDocInfo.addResult(result);
+<a name="224" href="#224">224</a> wsDocInfo.addTokenElement(elem);
+<a name="225" href="#225">225</a> <strong class="jxr_keyword">return</strong> java.util.Collections.singletonList(result);
+<a name="226" href="#226">226</a> }
+<a name="227" href="#227">227</a>
+<a name="228" href="#228">228</a> <em class="jxr_javadoccomment">/**</em>
+<a name="229" href="#229">229</a> <em class="jxr_javadoccomment"> * Get the default certificates from the KeyStore</em>
+<a name="230" href="#230">230</a> <em class="jxr_javadoccomment"> * @param crypto The Crypto object containing the default alias</em>
+<a name="231" href="#231">231</a> <em class="jxr_javadoccomment"> * @return The default certificates</em>
+<a name="232" href="#232">232</a> <em class="jxr_javadoccomment"> * @throws WSSecurityException</em>
+<a name="233" href="#233">233</a> <em class="jxr_javadoccomment"> */</em>
+<a name="234" href="#234">234</a> <strong class="jxr_keyword">private</strong> X509Certificate[] getDefaultCerts(
+<a name="235" href="#235">235</a> <a href="../../../../../org/apache/ws/security/components/crypto/Crypto.html">Crypto</a> crypto
+<a name="236" href="#236">236</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="237" href="#237">237</a> <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</strong>) {
+<a name="238" href="#238">238</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILURE, <span class="jxr_string">"noSigCryptoFile"</span>);
+<a name="239" href="#239">239</a> }
+<a name="240" href="#240">240</a> <strong class="jxr_keyword">if</strong> (crypto.getDefaultX509Identifier() != <strong class="jxr_keyword">null</strong>) {
+<a name="241" href="#241">241</a> <a href="../../../../../org/apache/ws/security/components/crypto/CryptoType.html">CryptoType</a> cryptoType = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/components/crypto/CryptoType.html">CryptoType</a>(CryptoType.TYPE.ALIAS);
+<a name="242" href="#242">242</a> cryptoType.setAlias(crypto.getDefaultX509Identifier());
+<a name="243" href="#243">243</a> <strong class="jxr_keyword">return</strong> crypto.getX509Certificates(cryptoType);
+<a name="244" href="#244">244</a> } <strong class="jxr_keyword">else</strong> {
+<a name="245" href="#245">245</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="246" href="#246">246</a> WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"unsupportedKeyInfo"</span>
+<a name="247" href="#247">247</a> );
+<a name="248" href="#248">248</a> }
+<a name="249" href="#249">249</a> }
+<a name="250" href="#250">250</a>
+<a name="251" href="#251">251</a> <strong class="jxr_keyword">private</strong> PublicKey parseKeyValue(
+<a name="252" href="#252">252</a> Element keyInfoElement
+<a name="253" href="#253">253</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="254" href="#254">254</a> KeyValue keyValue = <strong class="jxr_keyword">null</strong>;
+<a name="255" href="#255">255</a> <strong class="jxr_keyword">try</strong> {
+<a name="256" href="#256">256</a> <em class="jxr_comment">//</em>
+<a name="257" href="#257">257</a> <em class="jxr_comment">// Look for a KeyValue object</em>
+<a name="258" href="#258">258</a> <em class="jxr_comment">//</em>
+<a name="259" href="#259">259</a> keyValue = getKeyValue(keyInfoElement);
+<a name="260" href="#260">260</a> } <strong class="jxr_keyword">catch</strong> (javax.xml.crypto.MarshalException ex) {
+<a name="261" href="#261">261</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">null</strong>, ex);
+<a name="262" href="#262">262</a> }
+<a name="263" href="#263">263</a>
+<a name="264" href="#264">264</a> <strong class="jxr_keyword">if</strong> (keyValue != <strong class="jxr_keyword">null</strong>) {
+<a name="265" href="#265">265</a> <strong class="jxr_keyword">try</strong> {
+<a name="266" href="#266">266</a> <em class="jxr_comment">//</em>
+<a name="267" href="#267">267</a> <em class="jxr_comment">// Look for a Public Key in Key Value</em>
+<a name="268" href="#268">268</a> <em class="jxr_comment">//</em>
+<a name="269" href="#269">269</a> <strong class="jxr_keyword">return</strong> keyValue.getPublicKey();
+<a name="270" href="#270">270</a> } <strong class="jxr_keyword">catch</strong> (java.security.KeyException ex) {
+<a name="271" href="#271">271</a> LOG.error(ex.getMessage(), ex);
+<a name="272" href="#272">272</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">null</strong>, ex);
+<a name="273" href="#273">273</a> }
+<a name="274" href="#274">274</a> } <strong class="jxr_keyword">else</strong> {
+<a name="275" href="#275">275</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="276" href="#276">276</a> WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"unsupportedKeyInfo"</span>
+<a name="277" href="#277">277</a> );
+<a name="278" href="#278">278</a> }
+<a name="279" href="#279">279</a> }
+<a name="280" href="#280">280</a>
+<a name="281" href="#281">281</a> <em class="jxr_javadoccomment">/**</em>
+<a name="282" href="#282">282</a> <em class="jxr_javadoccomment"> * Get the KeyValue object from the KeyInfo DOM element if it exists</em>
+<a name="283" href="#283">283</a> <em class="jxr_javadoccomment"> */</em>
+<a name="284" href="#284">284</a> <strong class="jxr_keyword">private</strong> KeyValue getKeyValue(
+<a name="285" href="#285">285</a> Element keyInfoElement
+<a name="286" href="#286">286</a> ) <strong class="jxr_keyword">throws</strong> MarshalException {
+<a name="287" href="#287">287</a> XMLStructure keyInfoStructure = <strong class="jxr_keyword">new</strong> DOMStructure(keyInfoElement);
+<a name="288" href="#288">288</a> KeyInfo keyInfo = keyInfoFactory.unmarshalKeyInfo(keyInfoStructure);
+<a name="289" href="#289">289</a> List<?> list = keyInfo.getContent();
+<a name="290" href="#290">290</a>
+<a name="291" href="#291">291</a> <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i < list.size(); i++) {
+<a name="292" href="#292">292</a> XMLStructure xmlStructure = (XMLStructure) list.get(i);
+<a name="293" href="#293">293</a> <strong class="jxr_keyword">if</strong> (xmlStructure instanceof KeyValue) {
+<a name="294" href="#294">294</a> <strong class="jxr_keyword">return</strong> (KeyValue)xmlStructure;
+<a name="295" href="#295">295</a> }
+<a name="296" href="#296">296</a> }
+<a name="297" href="#297">297</a> <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
+<a name="298" href="#298">298</a> }
+<a name="299" href="#299">299</a>
+<a name="300" href="#300">300</a>
+<a name="301" href="#301">301</a> <em class="jxr_javadoccomment">/**</em>
+<a name="302" href="#302">302</a> <em class="jxr_javadoccomment"> * Verify the WS-Security signature.</em>
+<a name="303" href="#303">303</a> <em class="jxr_javadoccomment"> * </em>
+<a name="304" href="#304">304</a> <em class="jxr_javadoccomment"> * The functions at first checks if then <code>KeyInfo</code> that is</em>
+<a name="305" href="#305">305</a> <em class="jxr_javadoccomment"> * contained in the signature contains standard X509 data. If yes then</em>
+<a name="306" href="#306">306</a> <em class="jxr_javadoccomment"> * get the certificate data via the standard <code>KeyInfo</code> methods.</em>
+<a name="307" href="#307">307</a> <em class="jxr_javadoccomment"> * </em>
+<a name="308" href="#308">308</a> <em class="jxr_javadoccomment"> * Otherwise, if the <code>KeyInfo</code> info does not contain X509 data, check</em>
+<a name="309" href="#309">309</a> <em class="jxr_javadoccomment"> * if we can find a <code>wsse:SecurityTokenReference</code> element. If yes, the next</em>
+<a name="310" href="#310">310</a> <em class="jxr_javadoccomment"> * step is to check how to get the certificate. Two methods are currently supported</em>
+<a name="311" href="#311">311</a> <em class="jxr_javadoccomment"> * here:</em>
+<a name="312" href="#312">312</a> <em class="jxr_javadoccomment"> * <ul></em>
+<a name="313" href="#313">313</a> <em class="jxr_javadoccomment"> * <li> A URI reference to a binary security token contained in the <code>wsse:Security</em>
+<a name="314" href="#314">314</a> <em class="jxr_javadoccomment"> * </code> header. If the dereferenced token is</em>
+<a name="315" href="#315">315</a> <em class="jxr_javadoccomment"> * of the correct type the contained certificate is extracted.</em>
+<a name="316" href="#316">316</a> <em class="jxr_javadoccomment"> * </li></em>
+<a name="317" href="#317">317</a> <em class="jxr_javadoccomment"> * <li> Issuer name an serial number of the certificate. In this case the method</em>
+<a name="318" href="#318">318</a> <em class="jxr_javadoccomment"> * looks up the certificate in the keystore via the <code>crypto</code> parameter.</em>
+<a name="319" href="#319">319</a> <em class="jxr_javadoccomment"> * </li></em>
+<a name="320" href="#320">320</a> <em class="jxr_javadoccomment"> * </ul></em>
+<a name="321" href="#321">321</a> <em class="jxr_javadoccomment"> * </em>
+<a name="322" href="#322">322</a> <em class="jxr_javadoccomment"> * @param elem the XMLSignature DOM Element.</em>
+<a name="323" href="#323">323</a> <em class="jxr_javadoccomment"> * @param crypto the object that implements the access to the keystore and the</em>
+<a name="324" href="#324">324</a> <em class="jxr_javadoccomment"> * handling of certificates.</em>
+<a name="325" href="#325">325</a> <em class="jxr_javadoccomment"> * @param protectedRefs A list of (references) to the signed elements</em>
+<a name="326" href="#326">326</a> <em class="jxr_javadoccomment"> * @param cb CallbackHandler instance to extract key passwords</em>
+<a name="327" href="#327">327</a> <em class="jxr_javadoccomment"> * @return the subject principal of the validated X509 certificate (the</em>
+<a name="328" href="#328">328</a> <em class="jxr_javadoccomment"> * authenticated subject). The calling function may use this</em>
+<a name="329" href="#329">329</a> <em class="jxr_javadoccomment"> * principal for further authentication or authorization.</em>
+<a name="330" href="#330">330</a> <em class="jxr_javadoccomment"> * @throws WSSecurityException</em>
+<a name="331" href="#331">331</a> <em class="jxr_javadoccomment"> */</em>
+<a name="332" href="#332">332</a> <strong class="jxr_keyword">private</strong> XMLSignature verifyXMLSignature(
+<a name="333" href="#333">333</a> Element elem,
+<a name="334" href="#334">334</a> X509Certificate[] certs,
+<a name="335" href="#335">335</a> PublicKey publicKey,
+<a name="336" href="#336">336</a> byte[] secretKey,
+<a name="337" href="#337">337</a> String signatureMethod,
+<a name="338" href="#338">338</a> <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo
+<a name="339" href="#339">339</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="340" href="#340">340</a> <strong class="jxr_keyword">if</strong> (LOG.isDebugEnabled()) {
+<a name="341" href="#341">341</a> LOG.debug(<span class="jxr_string">"Verify XML Signature"</span>);
+<a name="342" href="#342">342</a> }
+<a name="343" href="#343">343</a>
+<a name="344" href="#344">344</a> <em class="jxr_comment">//</em>
+<a name="345" href="#345">345</a> <em class="jxr_comment">// Perform the signature verification and build up a List of elements that the</em>
+<a name="346" href="#346">346</a> <em class="jxr_comment">// signature refers to</em>
+<a name="347" href="#347">347</a> <em class="jxr_comment">//</em>
+<a name="348" href="#348">348</a> Key key = <strong class="jxr_keyword">null</strong>;
+<a name="349" href="#349">349</a> <strong class="jxr_keyword">if</strong> (certs != <strong class="jxr_keyword">null</strong> && certs[0] != <strong class="jxr_keyword">null</strong>) {
+<a name="350" href="#350">350</a> key = certs[0].getPublicKey();
+<a name="351" href="#351">351</a> } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (publicKey != <strong class="jxr_keyword">null</strong>) {
+<a name="352" href="#352">352</a> key = publicKey;
+<a name="353" href="#353">353</a> } <strong class="jxr_keyword">else</strong> {
+<a name="354" href="#354">354</a> key = WSSecurityUtil.prepareSecretKey(signatureMethod, secretKey);
+<a name="355" href="#355">355</a> }
+<a name="356" href="#356">356</a>
+<a name="357" href="#357">357</a> XMLValidateContext context = <strong class="jxr_keyword">new</strong> DOMValidateContext(key, elem);
+<a name="358" href="#358">358</a> context.setProperty(<span class="jxr_string">"javax.xml.crypto.dsig.cacheReference"</span>, Boolean.TRUE);
+<a name="359" href="#359">359</a> context.setProperty(STRTransform.TRANSFORM_WS_DOC_INFO, wsDocInfo);
+<a name="360" href="#360">360</a>
+<a name="361" href="#361">361</a> <strong class="jxr_keyword">try</strong> {
+<a name="362" href="#362">362</a> XMLSignature xmlSignature = signatureFactory.unmarshalXMLSignature(context);
+<a name="363" href="#363">363</a> setElementsOnContext(xmlSignature, (DOMValidateContext)context, wsDocInfo, elem.getOwnerDocument());
+<a name="364" href="#364">364</a> <strong class="jxr_keyword">boolean</strong> signatureOk = xmlSignature.validate(context);
+<a name="365" href="#365">365</a> <strong class="jxr_keyword">if</strong> (signatureOk) {
+<a name="366" href="#366">366</a> <strong class="jxr_keyword">return</strong> xmlSignature;
+<a name="367" href="#367">367</a> }
+<a name="368" href="#368">368</a> <em class="jxr_comment">//</em>
+<a name="369" href="#369">369</a> <em class="jxr_comment">// Log the exact signature error</em>
+<a name="370" href="#370">370</a> <em class="jxr_comment">//</em>
+<a name="371" href="#371">371</a> <strong class="jxr_keyword">if</strong> (LOG.isDebugEnabled()) {
+<a name="372" href="#372">372</a> LOG.debug(<span class="jxr_string">"XML Signature verification has failed"</span>);
+<a name="373" href="#373">373</a> <strong class="jxr_keyword">boolean</strong> signatureValidationCheck =
+<a name="374" href="#374">374</a> xmlSignature.getSignatureValue().validate(context);
+<a name="375" href="#375">375</a> LOG.debug(<span class="jxr_string">"Signature Validation check: "</span> + signatureValidationCheck);
+<a name="376" href="#376">376</a> java.util.Iterator<?> referenceIterator =
+<a name="377" href="#377">377</a> xmlSignature.getSignedInfo().getReferences().iterator();
+<a name="378" href="#378">378</a> <strong class="jxr_keyword">while</strong> (referenceIterator.hasNext()) {
+<a name="379" href="#379">379</a> <a href="../../../../../org/apache/ws/security/message/token/Reference.html">Reference</a> reference = (Reference)referenceIterator.next();
+<a name="380" href="#380">380</a> <strong class="jxr_keyword">boolean</strong> referenceValidationCheck = reference.validate(context);
+<a name="381" href="#381">381</a> String id = reference.getId();
+<a name="382" href="#382">382</a> <strong class="jxr_keyword">if</strong> (id == <strong class="jxr_keyword">null</strong>) {
+<a name="383" href="#383">383</a> id = reference.getURI();
+<a name="384" href="#384">384</a> }
+<a name="385" href="#385">385</a> LOG.debug(<span class="jxr_string">"Reference "</span> + id + <span class="jxr_string">" check: "</span> + referenceValidationCheck);
+<a name="386" href="#386">386</a> }
+<a name="387" href="#387">387</a> }
+<a name="388" href="#388">388</a> } <strong class="jxr_keyword">catch</strong> (Exception ex) {
+<a name="389" href="#389">389</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="390" href="#390">390</a> WSSecurityException.FAILED_CHECK, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">null</strong>, ex
+<a name="391" href="#391">391</a> );
+<a name="392" href="#392">392</a> }
+<a name="393" href="#393">393</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILED_CHECK);
+<a name="394" href="#394">394</a> }
+<a name="395" href="#395">395</a>
+<a name="396" href="#396">396</a> <em class="jxr_javadoccomment">/**</em>
+<a name="397" href="#397">397</a> <em class="jxr_javadoccomment"> * Retrieve the Reference elements and set them on the ValidateContext</em>
+<a name="398" href="#398">398</a> <em class="jxr_javadoccomment"> * @param xmlSignature the XMLSignature object to get the references from</em>
+<a name="399" href="#399">399</a> <em class="jxr_javadoccomment"> * @param context the ValidateContext</em>
+<a name="400" href="#400">400</a> <em class="jxr_javadoccomment"> * @param wsDocInfo the WSDocInfo object where tokens are stored</em>
+<a name="401" href="#401">401</a> <em class="jxr_javadoccomment"> * @param doc the owner document from which to find elements</em>
+<a name="402" href="#402">402</a> <em class="jxr_javadoccomment"> * @throws WSSecurityException</em>
+<a name="403" href="#403">403</a> <em class="jxr_javadoccomment"> */</em>
+<a name="404" href="#404">404</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> setElementsOnContext(
+<a name="405" href="#405">405</a> XMLSignature xmlSignature,
+<a name="406" href="#406">406</a> DOMValidateContext context,
+<a name="407" href="#407">407</a> <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo,
+<a name="408" href="#408">408</a> Document doc
+<a name="409" href="#409">409</a> ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="410" href="#410">410</a> java.util.Iterator<?> referenceIterator =
+<a name="411" href="#411">411</a> xmlSignature.getSignedInfo().getReferences().iterator();
+<a name="412" href="#412">412</a> <a href="../../../../../org/apache/ws/security/message/CallbackLookup.html">CallbackLookup</a> callbackLookup = wsDocInfo.getCallbackLookup();
+<a name="413" href="#413">413</a> <strong class="jxr_keyword">if</strong> (callbackLookup == <strong class="jxr_keyword">null</strong>) {
+<a name="414" href="#414">414</a> callbackLookup = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/message/DOMCallbackLookup.html">DOMCallbackLookup</a>(doc);
+<a name="415" href="#415">415</a> }
+<a name="416" href="#416">416</a> <strong class="jxr_keyword">while</strong> (referenceIterator.hasNext()) {
[... 162 lines stripped ...]