ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1040461 [27/28] - in /webservices/wss4j/site: ./ apidocs/ apidocs/org/apache/ws/axis/security/ apidocs/org/apache/ws/axis/security/class-use/ apidocs/org/apache/ws/axis/security/handler/ apidocs/org/apache/ws/axis/security/handler/class-us...
Date Tue, 30 Nov 2010 11:10:41 GMT
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=1040461&r1=1040460&r2=1040461&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 Nov 30 11:10:26 2010
@@ -90,597 +90,613 @@
 <a name="80" href="#80">80</a>      
 <a name="81" href="#81">81</a>      <strong class="jxr_keyword">private</strong> String signatureId;
 <a name="82" href="#82">82</a>      
-<a name="83" href="#83">83</a>      <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> secretKeyLength = WSConstants.WSE_DERIVED_KEY_LEN;
+<a name="83" href="#83">83</a>      <strong class="jxr_keyword">private</strong> X509Certificate[] certificates;
 <a name="84" href="#84">84</a>      
-<a name="85" href="#85">85</a>      <strong class="jxr_keyword">private</strong> String signatureMethod;
+<a name="85" href="#85">85</a>      <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> secretKeyLength = WSConstants.WSE_DERIVED_KEY_LEN;
 <a name="86" href="#86">86</a>      
-<a name="87" href="#87">87</a>      <strong class="jxr_keyword">private</strong> String c14nMethod;
-<a name="88" href="#88">88</a>  
-<a name="89" href="#89">89</a>      <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> handleToken(
-<a name="90" href="#90">90</a>          Element elem, 
-<a name="91" href="#91">91</a>          <a href="../../../../../org/apache/ws/security/components/crypto/Crypto.html">Crypto</a> crypto, 
-<a name="92" href="#92">92</a>          <a href="../../../../../org/apache/ws/security/components/crypto/Crypto.html">Crypto</a> decCrypto, 
-<a name="93" href="#93">93</a>          CallbackHandler cb, 
-<a name="94" href="#94">94</a>          <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo, 
-<a name="95" href="#95">95</a>          Vector returnResults, 
-<a name="96" href="#96">96</a>          <a href="../../../../../org/apache/ws/security/WSSConfig.html">WSSConfig</a> wsc
-<a name="97" href="#97">97</a>      ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="98" href="#98">98</a>          <strong class="jxr_keyword">if</strong> (log.isDebugEnabled()) {
-<a name="99" href="#99">99</a>              log.debug(<span class="jxr_string">"Found signature element"</span>);
-<a name="100" href="#100">100</a>         }
-<a name="101" href="#101">101</a>         <strong class="jxr_keyword">boolean</strong> remove = WSDocInfoStore.store(wsDocInfo);
-<a name="102" href="#102">102</a>         X509Certificate[] returnCert = <strong class="jxr_keyword">new</strong> X509Certificate[1];
-<a name="103" href="#103">103</a>         Set returnElements = <strong class="jxr_keyword">new</strong> HashSet();
-<a name="104" href="#104">104</a>         List protectedElements = <strong class="jxr_keyword">new</strong> java.util.ArrayList();
-<a name="105" href="#105">105</a>         byte[][] signatureValue = <strong class="jxr_keyword">new</strong> byte[1][];
-<a name="106" href="#106">106</a>         Principal lastPrincipalFound = <strong class="jxr_keyword">null</strong>;
-<a name="107" href="#107">107</a>         secretKeyLength = wsc.getSecretKeyLength();
-<a name="108" href="#108">108</a>         signatureMethod = c14nMethod = <strong class="jxr_keyword">null</strong>;
-<a name="109" href="#109">109</a>         
-<a name="110" href="#110">110</a>         <strong class="jxr_keyword">try</strong> {
-<a name="111" href="#111">111</a>             lastPrincipalFound = 
-<a name="112" href="#112">112</a>                 verifyXMLSignature(
-<a name="113" href="#113">113</a>                     elem, crypto, returnCert, returnElements,
-<a name="114" href="#114">114</a>                     protectedElements, signatureValue, cb,
-<a name="115" href="#115">115</a>                     wsDocInfo
-<a name="116" href="#116">116</a>                 );
-<a name="117" href="#117">117</a>         } <strong class="jxr_keyword">catch</strong> (WSSecurityException ex) {
-<a name="118" href="#118">118</a>             <strong class="jxr_keyword">throw</strong> ex;
-<a name="119" href="#119">119</a>         } <strong class="jxr_keyword">finally</strong> {
-<a name="120" href="#120">120</a>             <strong class="jxr_keyword">if</strong> (remove) {
-<a name="121" href="#121">121</a>                 WSDocInfoStore.delete(wsDocInfo);
-<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> (lastPrincipalFound instanceof WSUsernameTokenPrincipal) {
-<a name="125" href="#125">125</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="126" href="#126">126</a>                     WSConstants.UT_SIGN, lastPrincipalFound, <strong class="jxr_keyword">null</strong>,
-<a name="127" href="#127">127</a>                     returnElements, protectedElements, signatureValue[0]);
-<a name="128" href="#128">128</a>             result.put(WSSecurityEngineResult.TAG_SIGNATURE_METHOD, signatureMethod);
-<a name="129" href="#129">129</a>             result.put(WSSecurityEngineResult.TAG_CANONICALIZATION_METHOD, c14nMethod);
-<a name="130" href="#130">130</a>             returnResults.add(
-<a name="131" href="#131">131</a>                 0, 
-<a name="132" href="#132">132</a>                 result
-<a name="133" href="#133">133</a>             );
-<a name="134" href="#134">134</a>         } <strong class="jxr_keyword">else</strong> {
-<a name="135" href="#135">135</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="136" href="#136">136</a>                     WSConstants.SIGN, lastPrincipalFound, returnCert[0], 
-<a name="137" href="#137">137</a>                     returnElements, protectedElements, signatureValue[0]);
-<a name="138" href="#138">138</a>             result.put(WSSecurityEngineResult.TAG_SIGNATURE_METHOD, signatureMethod);
-<a name="139" href="#139">139</a>             result.put(WSSecurityEngineResult.TAG_CANONICALIZATION_METHOD, c14nMethod);
-<a name="140" href="#140">140</a>             returnResults.add(
-<a name="141" href="#141">141</a>                 0, 
-<a name="142" href="#142">142</a>                 result
-<a name="143" href="#143">143</a>             );
-<a name="144" href="#144">144</a>         }
-<a name="145" href="#145">145</a>         signatureId = elem.getAttributeNS(<strong class="jxr_keyword">null</strong>, <span class="jxr_string">"Id"</span>);
-<a name="146" href="#146">146</a>     }
-<a name="147" href="#147">147</a> 
-<a name="148" href="#148">148</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="149" href="#149">149</a> <em class="jxr_javadoccomment">     * Verify the WS-Security signature.</em>
-<a name="150" href="#150">150</a> <em class="jxr_javadoccomment">     * </em>
-<a name="151" href="#151">151</a> <em class="jxr_javadoccomment">     * The functions at first checks if then &lt;code&gt;KeyInfo&lt;/code&gt; that is</em>
-<a name="152" href="#152">152</a> <em class="jxr_javadoccomment">     * contained in the signature contains standard X509 data. If yes then</em>
-<a name="153" href="#153">153</a> <em class="jxr_javadoccomment">     * get the certificate data via the standard &lt;code&gt;KeyInfo&lt;/code&gt; methods.</em>
+<a name="87" href="#87">87</a>      <strong class="jxr_keyword">private</strong> String signatureMethod;
+<a name="88" href="#88">88</a>      
+<a name="89" href="#89">89</a>      <strong class="jxr_keyword">private</strong> String c14nMethod;
+<a name="90" href="#90">90</a>  
+<a name="91" href="#91">91</a>      <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> handleToken(
+<a name="92" href="#92">92</a>          Element elem, 
+<a name="93" href="#93">93</a>          <a href="../../../../../org/apache/ws/security/components/crypto/Crypto.html">Crypto</a> crypto, 
+<a name="94" href="#94">94</a>          <a href="../../../../../org/apache/ws/security/components/crypto/Crypto.html">Crypto</a> decCrypto, 
+<a name="95" href="#95">95</a>          CallbackHandler cb, 
+<a name="96" href="#96">96</a>          <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo, 
+<a name="97" href="#97">97</a>          Vector returnResults, 
+<a name="98" href="#98">98</a>          <a href="../../../../../org/apache/ws/security/WSSConfig.html">WSSConfig</a> wsc
+<a name="99" href="#99">99</a>      ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="100" href="#100">100</a>         <strong class="jxr_keyword">if</strong> (log.isDebugEnabled()) {
+<a name="101" href="#101">101</a>             log.debug(<span class="jxr_string">"Found signature element"</span>);
+<a name="102" href="#102">102</a>         }
+<a name="103" href="#103">103</a>         <strong class="jxr_keyword">boolean</strong> remove = WSDocInfoStore.store(wsDocInfo);
+<a name="104" href="#104">104</a>         X509Certificate[] returnCert = <strong class="jxr_keyword">new</strong> X509Certificate[1];
+<a name="105" href="#105">105</a>         Set returnElements = <strong class="jxr_keyword">new</strong> HashSet();
+<a name="106" href="#106">106</a>         List protectedElements = <strong class="jxr_keyword">new</strong> java.util.ArrayList();
+<a name="107" href="#107">107</a>         byte[][] signatureValue = <strong class="jxr_keyword">new</strong> byte[1][];
+<a name="108" href="#108">108</a>         Principal lastPrincipalFound = <strong class="jxr_keyword">null</strong>;
+<a name="109" href="#109">109</a>         secretKeyLength = wsc.getSecretKeyLength();
+<a name="110" href="#110">110</a>         signatureMethod = c14nMethod = <strong class="jxr_keyword">null</strong>;
+<a name="111" href="#111">111</a>         certificates = <strong class="jxr_keyword">null</strong>;
+<a name="112" href="#112">112</a>         
+<a name="113" href="#113">113</a>         <strong class="jxr_keyword">try</strong> {
+<a name="114" href="#114">114</a>             lastPrincipalFound = 
+<a name="115" href="#115">115</a>                 verifyXMLSignature(
+<a name="116" href="#116">116</a>                     elem, crypto, returnCert, returnElements,
+<a name="117" href="#117">117</a>                     protectedElements, signatureValue, cb,
+<a name="118" href="#118">118</a>                     wsDocInfo
+<a name="119" href="#119">119</a>                 );
+<a name="120" href="#120">120</a>         } <strong class="jxr_keyword">catch</strong> (WSSecurityException ex) {
+<a name="121" href="#121">121</a>             <strong class="jxr_keyword">throw</strong> ex;
+<a name="122" href="#122">122</a>         } <strong class="jxr_keyword">finally</strong> {
+<a name="123" href="#123">123</a>             <strong class="jxr_keyword">if</strong> (remove) {
+<a name="124" href="#124">124</a>                 WSDocInfoStore.delete(wsDocInfo);
+<a name="125" href="#125">125</a>             }
+<a name="126" href="#126">126</a>         }
+<a name="127" href="#127">127</a>         <strong class="jxr_keyword">if</strong> (lastPrincipalFound instanceof WSUsernameTokenPrincipal) {
+<a name="128" href="#128">128</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="129" href="#129">129</a>                     WSConstants.UT_SIGN, lastPrincipalFound, <strong class="jxr_keyword">null</strong>,
+<a name="130" href="#130">130</a>                     returnElements, protectedElements, signatureValue[0]);
+<a name="131" href="#131">131</a>             result.put(WSSecurityEngineResult.TAG_SIGNATURE_METHOD, signatureMethod);
+<a name="132" href="#132">132</a>             result.put(WSSecurityEngineResult.TAG_CANONICALIZATION_METHOD, c14nMethod);
+<a name="133" href="#133">133</a>             returnResults.add(
+<a name="134" href="#134">134</a>                 0, 
+<a name="135" href="#135">135</a>                 result
+<a name="136" href="#136">136</a>             );
+<a name="137" href="#137">137</a>         } <strong class="jxr_keyword">else</strong> {
+<a name="138" href="#138">138</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="139" href="#139">139</a>                     WSConstants.SIGN, lastPrincipalFound, returnCert[0], 
+<a name="140" href="#140">140</a>                     returnElements, protectedElements, signatureValue[0]);
+<a name="141" href="#141">141</a>             result.put(WSSecurityEngineResult.TAG_SIGNATURE_METHOD, signatureMethod);
+<a name="142" href="#142">142</a>             result.put(WSSecurityEngineResult.TAG_CANONICALIZATION_METHOD, c14nMethod);
+<a name="143" href="#143">143</a>             result.put(WSSecurityEngineResult.TAG_X509_CERTIFICATES, certificates);
+<a name="144" href="#144">144</a>             returnResults.add(
+<a name="145" href="#145">145</a>                 0, 
+<a name="146" href="#146">146</a>                 result
+<a name="147" href="#147">147</a>             );
+<a name="148" href="#148">148</a>         }
+<a name="149" href="#149">149</a>         signatureId = elem.getAttributeNS(<strong class="jxr_keyword">null</strong>, <span class="jxr_string">"Id"</span>);
+<a name="150" href="#150">150</a>     }
+<a name="151" href="#151">151</a> 
+<a name="152" href="#152">152</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="153" href="#153">153</a> <em class="jxr_javadoccomment">     * Verify the WS-Security signature.</em>
 <a name="154" href="#154">154</a> <em class="jxr_javadoccomment">     * </em>
-<a name="155" href="#155">155</a> <em class="jxr_javadoccomment">     * Otherwise, if the &lt;code&gt;KeyInfo&lt;/code&gt; info does not contain X509 data, check</em>
-<a name="156" href="#156">156</a> <em class="jxr_javadoccomment">     * if we can find a &lt;code&gt;wsse:SecurityTokenReference&lt;/code&gt; element. If yes, the next</em>
-<a name="157" href="#157">157</a> <em class="jxr_javadoccomment">     * step is to check how to get the certificate. Two methods are currently supported</em>
-<a name="158" href="#158">158</a> <em class="jxr_javadoccomment">     * here:</em>
-<a name="159" href="#159">159</a> <em class="jxr_javadoccomment">     * &lt;ul&gt;</em>
-<a name="160" href="#160">160</a> <em class="jxr_javadoccomment">     * &lt;li&gt; A URI reference to a binary security token contained in the &lt;code&gt;wsse:Security</em>
-<a name="161" href="#161">161</a> <em class="jxr_javadoccomment">     * &lt;/code&gt; header.  If the dereferenced token is</em>
-<a name="162" href="#162">162</a> <em class="jxr_javadoccomment">     * of the correct type the contained certificate is extracted.</em>
-<a name="163" href="#163">163</a> <em class="jxr_javadoccomment">     * &lt;/li&gt;</em>
-<a name="164" href="#164">164</a> <em class="jxr_javadoccomment">     * &lt;li&gt; Issuer name an serial number of the certificate. In this case the method</em>
-<a name="165" href="#165">165</a> <em class="jxr_javadoccomment">     * looks up the certificate in the keystore via the &lt;code&gt;crypto&lt;/code&gt; parameter.</em>
-<a name="166" href="#166">166</a> <em class="jxr_javadoccomment">     * &lt;/li&gt;</em>
-<a name="167" href="#167">167</a> <em class="jxr_javadoccomment">     * &lt;/ul&gt;</em>
-<a name="168" href="#168">168</a> <em class="jxr_javadoccomment">     * </em>
-<a name="169" href="#169">169</a> <em class="jxr_javadoccomment">     * The methods checks is the certificate is valid and calls the</em>
-<a name="170" href="#170">170</a> <em class="jxr_javadoccomment">     * {@link org.apache.xml.security.signature.XMLSignature#checkSignatureValue(X509Certificate) </em>
-<a name="171" href="#171">171</a> <em class="jxr_javadoccomment">     * verification} function.</em>
-<a name="172" href="#172">172</a> <em class="jxr_javadoccomment">     *</em>
-<a name="173" href="#173">173</a> <em class="jxr_javadoccomment">     * @param elem        the XMLSignature DOM Element.</em>
-<a name="174" href="#174">174</a> <em class="jxr_javadoccomment">     * @param crypto      the object that implements the access to the keystore and the</em>
-<a name="175" href="#175">175</a> <em class="jxr_javadoccomment">     *                    handling of certificates.</em>
-<a name="176" href="#176">176</a> <em class="jxr_javadoccomment">     * @param returnCert  verifyXMLSignature stores the certificate in the first</em>
-<a name="177" href="#177">177</a> <em class="jxr_javadoccomment">     *                    entry of this array. The caller may then further validate</em>
-<a name="178" href="#178">178</a> <em class="jxr_javadoccomment">     *                    the certificate</em>
-<a name="179" href="#179">179</a> <em class="jxr_javadoccomment">     * @param returnElements verifyXMLSignature adds the wsu:ID attribute values for</em>
-<a name="180" href="#180">180</a> <em class="jxr_javadoccomment">     *               the signed elements to this Set</em>
-<a name="181" href="#181">181</a> <em class="jxr_javadoccomment">     * @param cb CallbackHandler instance to extract key passwords</em>
-<a name="182" href="#182">182</a> <em class="jxr_javadoccomment">     * @return the subject principal of the validated X509 certificate (the</em>
-<a name="183" href="#183">183</a> <em class="jxr_javadoccomment">     *         authenticated subject). The calling function may use this</em>
-<a name="184" href="#184">184</a> <em class="jxr_javadoccomment">     *         principal for further authentication or authorization.</em>
-<a name="185" href="#185">185</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="186" href="#186">186</a> <em class="jxr_javadoccomment">     */</em>
-<a name="187" href="#187">187</a>     <strong class="jxr_keyword">protected</strong> Principal verifyXMLSignature(
-<a name="188" href="#188">188</a>         Element elem,
-<a name="189" href="#189">189</a>         <a href="../../../../../org/apache/ws/security/components/crypto/Crypto.html">Crypto</a> crypto,
-<a name="190" href="#190">190</a>         X509Certificate[] returnCert,
-<a name="191" href="#191">191</a>         Set returnElements,
-<a name="192" href="#192">192</a>         List protectedElements,
-<a name="193" href="#193">193</a>         byte[][] signatureValue,
-<a name="194" href="#194">194</a>         CallbackHandler cb,
-<a name="195" href="#195">195</a>         <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo
-<a name="196" href="#196">196</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="197" href="#197">197</a>         <strong class="jxr_keyword">if</strong> (log.isDebugEnabled()) {
-<a name="198" href="#198">198</a>             log.debug(<span class="jxr_string">"Verify XML Signature"</span>);
-<a name="199" href="#199">199</a>         }
-<a name="200" href="#200">200</a>         <strong class="jxr_keyword">long</strong> t0 = 0, t1 = 0, t2 = 0;
-<a name="201" href="#201">201</a>         <strong class="jxr_keyword">if</strong> (tlog.isDebugEnabled()) {
-<a name="202" href="#202">202</a>             t0 = System.currentTimeMillis();
+<a name="155" href="#155">155</a> <em class="jxr_javadoccomment">     * The functions at first checks if then &lt;code&gt;KeyInfo&lt;/code&gt; that is</em>
+<a name="156" href="#156">156</a> <em class="jxr_javadoccomment">     * contained in the signature contains standard X509 data. If yes then</em>
+<a name="157" href="#157">157</a> <em class="jxr_javadoccomment">     * get the certificate data via the standard &lt;code&gt;KeyInfo&lt;/code&gt; methods.</em>
+<a name="158" href="#158">158</a> <em class="jxr_javadoccomment">     * </em>
+<a name="159" href="#159">159</a> <em class="jxr_javadoccomment">     * Otherwise, if the &lt;code&gt;KeyInfo&lt;/code&gt; info does not contain X509 data, check</em>
+<a name="160" href="#160">160</a> <em class="jxr_javadoccomment">     * if we can find a &lt;code&gt;wsse:SecurityTokenReference&lt;/code&gt; element. If yes, the next</em>
+<a name="161" href="#161">161</a> <em class="jxr_javadoccomment">     * step is to check how to get the certificate. Two methods are currently supported</em>
+<a name="162" href="#162">162</a> <em class="jxr_javadoccomment">     * here:</em>
+<a name="163" href="#163">163</a> <em class="jxr_javadoccomment">     * &lt;ul&gt;</em>
+<a name="164" href="#164">164</a> <em class="jxr_javadoccomment">     * &lt;li&gt; A URI reference to a binary security token contained in the &lt;code&gt;wsse:Security</em>
+<a name="165" href="#165">165</a> <em class="jxr_javadoccomment">     * &lt;/code&gt; header.  If the dereferenced token is</em>
+<a name="166" href="#166">166</a> <em class="jxr_javadoccomment">     * of the correct type the contained certificate is extracted.</em>
+<a name="167" href="#167">167</a> <em class="jxr_javadoccomment">     * &lt;/li&gt;</em>
+<a name="168" href="#168">168</a> <em class="jxr_javadoccomment">     * &lt;li&gt; Issuer name an serial number of the certificate. In this case the method</em>
+<a name="169" href="#169">169</a> <em class="jxr_javadoccomment">     * looks up the certificate in the keystore via the &lt;code&gt;crypto&lt;/code&gt; parameter.</em>
+<a name="170" href="#170">170</a> <em class="jxr_javadoccomment">     * &lt;/li&gt;</em>
+<a name="171" href="#171">171</a> <em class="jxr_javadoccomment">     * &lt;/ul&gt;</em>
+<a name="172" href="#172">172</a> <em class="jxr_javadoccomment">     * </em>
+<a name="173" href="#173">173</a> <em class="jxr_javadoccomment">     * The methods checks is the certificate is valid and calls the</em>
+<a name="174" href="#174">174</a> <em class="jxr_javadoccomment">     * {@link org.apache.xml.security.signature.XMLSignature#checkSignatureValue(X509Certificate) </em>
+<a name="175" href="#175">175</a> <em class="jxr_javadoccomment">     * verification} function.</em>
+<a name="176" href="#176">176</a> <em class="jxr_javadoccomment">     *</em>
+<a name="177" href="#177">177</a> <em class="jxr_javadoccomment">     * @param elem        the XMLSignature DOM Element.</em>
+<a name="178" href="#178">178</a> <em class="jxr_javadoccomment">     * @param crypto      the object that implements the access to the keystore and the</em>
+<a name="179" href="#179">179</a> <em class="jxr_javadoccomment">     *                    handling of certificates.</em>
+<a name="180" href="#180">180</a> <em class="jxr_javadoccomment">     * @param returnCert  verifyXMLSignature stores the certificate in the first</em>
+<a name="181" href="#181">181</a> <em class="jxr_javadoccomment">     *                    entry of this array. The caller may then further validate</em>
+<a name="182" href="#182">182</a> <em class="jxr_javadoccomment">     *                    the certificate</em>
+<a name="183" href="#183">183</a> <em class="jxr_javadoccomment">     * @param returnElements verifyXMLSignature adds the wsu:ID attribute values for</em>
+<a name="184" href="#184">184</a> <em class="jxr_javadoccomment">     *               the signed elements to this Set</em>
+<a name="185" href="#185">185</a> <em class="jxr_javadoccomment">     * @param cb CallbackHandler instance to extract key passwords</em>
+<a name="186" href="#186">186</a> <em class="jxr_javadoccomment">     * @return the subject principal of the validated X509 certificate (the</em>
+<a name="187" href="#187">187</a> <em class="jxr_javadoccomment">     *         authenticated subject). The calling function may use this</em>
+<a name="188" href="#188">188</a> <em class="jxr_javadoccomment">     *         principal for further authentication or authorization.</em>
+<a name="189" href="#189">189</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
+<a name="190" href="#190">190</a> <em class="jxr_javadoccomment">     */</em>
+<a name="191" href="#191">191</a>     <strong class="jxr_keyword">protected</strong> Principal verifyXMLSignature(
+<a name="192" href="#192">192</a>         Element elem,
+<a name="193" href="#193">193</a>         <a href="../../../../../org/apache/ws/security/components/crypto/Crypto.html">Crypto</a> crypto,
+<a name="194" href="#194">194</a>         X509Certificate[] returnCert,
+<a name="195" href="#195">195</a>         Set returnElements,
+<a name="196" href="#196">196</a>         List protectedElements,
+<a name="197" href="#197">197</a>         byte[][] signatureValue,
+<a name="198" href="#198">198</a>         CallbackHandler cb,
+<a name="199" href="#199">199</a>         <a href="../../../../../org/apache/ws/security/WSDocInfo.html">WSDocInfo</a> wsDocInfo
+<a name="200" href="#200">200</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="201" href="#201">201</a>         <strong class="jxr_keyword">if</strong> (log.isDebugEnabled()) {
+<a name="202" href="#202">202</a>             log.debug(<span class="jxr_string">"Verify XML Signature"</span>);
 <a name="203" href="#203">203</a>         }
-<a name="204" href="#204">204</a> 
-<a name="205" href="#205">205</a>         XMLSignature sig = <strong class="jxr_keyword">null</strong>;
-<a name="206" href="#206">206</a>         <strong class="jxr_keyword">try</strong> {
-<a name="207" href="#207">207</a>             sig = <strong class="jxr_keyword">new</strong> XMLSignature(elem, <strong class="jxr_keyword">null</strong>);
-<a name="208" href="#208">208</a>         } <strong class="jxr_keyword">catch</strong> (XMLSecurityException e2) {
-<a name="209" href="#209">209</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="210" href="#210">210</a>                 WSSecurityException.FAILED_CHECK, <span class="jxr_string">"noXMLSig"</span>, <strong class="jxr_keyword">null</strong>, e2
-<a name="211" href="#211">211</a>             );
-<a name="212" href="#212">212</a>         }
-<a name="213" href="#213">213</a> 
-<a name="214" href="#214">214</a>         sig.addResourceResolver(EnvelopeIdResolver.getInstance());
-<a name="215" href="#215">215</a> 
-<a name="216" href="#216">216</a>         X509Certificate[] certs = <strong class="jxr_keyword">null</strong>;
-<a name="217" href="#217">217</a>         KeyInfo info = sig.getKeyInfo();
-<a name="218" href="#218">218</a>         byte[] secretKey = <strong class="jxr_keyword">null</strong>;
-<a name="219" href="#219">219</a>         <a href="../../../../../org/apache/ws/security/message/token/UsernameToken.html">UsernameToken</a> ut = <strong class="jxr_keyword">null</strong>;
-<a name="220" href="#220">220</a>         <a href="../../../../../org/apache/ws/security/message/token/DerivedKeyToken.html">DerivedKeyToken</a> dkt = <strong class="jxr_keyword">null</strong>;
-<a name="221" href="#221">221</a>         <a href="../../../../../org/apache/ws/security/saml/SAMLKeyInfo.html">SAMLKeyInfo</a> samlKi = <strong class="jxr_keyword">null</strong>;
-<a name="222" href="#222">222</a>         String customTokenId = <strong class="jxr_keyword">null</strong>;
-<a name="223" href="#223">223</a>         java.security.PublicKey publicKey = <strong class="jxr_keyword">null</strong>;
-<a name="224" href="#224">224</a>         
-<a name="225" href="#225">225</a>         <strong class="jxr_keyword">if</strong> (info != <strong class="jxr_keyword">null</strong> &amp;&amp; info.containsKeyValue()) {
-<a name="226" href="#226">226</a>             <strong class="jxr_keyword">try</strong> {
-<a name="227" href="#227">227</a>                 publicKey = info.getPublicKey();
-<a name="228" href="#228">228</a>             } <strong class="jxr_keyword">catch</strong> (Exception ex) {
-<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>(ex.getMessage(), ex);
-<a name="230" href="#230">230</a>             }
-<a name="231" href="#231">231</a>         } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (info != <strong class="jxr_keyword">null</strong>) {
-<a name="232" href="#232">232</a>             Node node = 
-<a name="233" href="#233">233</a>                 WSSecurityUtil.getDirectChild(
-<a name="234" href="#234">234</a>                     info.getElement(),
-<a name="235" href="#235">235</a>                     SecurityTokenReference.SECURITY_TOKEN_REFERENCE,
-<a name="236" href="#236">236</a>                     WSConstants.WSSE_NS
-<a name="237" href="#237">237</a>                 );
-<a name="238" href="#238">238</a>             <strong class="jxr_keyword">if</strong> (node == <strong class="jxr_keyword">null</strong>) {
-<a name="239" href="#239">239</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="240" href="#240">240</a>                     WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"unsupportedKeyInfo"</span>
-<a name="241" href="#241">241</a>                 );
-<a name="242" href="#242">242</a>             }
-<a name="243" href="#243">243</a>             <a href="../../../../../org/apache/ws/security/message/token/SecurityTokenReference.html">SecurityTokenReference</a> secRef = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/message/token/SecurityTokenReference.html">SecurityTokenReference</a>((Element) node);
-<a name="244" href="#244">244</a>             <em class="jxr_comment">//</em>
-<a name="245" href="#245">245</a>             <em class="jxr_comment">// Here we get some information about the document that is being</em>
-<a name="246" href="#246">246</a>             <em class="jxr_comment">// processed, in particular the crypto implementation, and already</em>
-<a name="247" href="#247">247</a>             <em class="jxr_comment">// detected BST that may be used later during dereferencing.</em>
-<a name="248" href="#248">248</a>             <em class="jxr_comment">//</em>
-<a name="249" href="#249">249</a>             <strong class="jxr_keyword">if</strong> (secRef.containsReference()) {
-<a name="250" href="#250">250</a>                 org.apache.ws.security.message.token.Reference ref = secRef.getReference();
-<a name="251" href="#251">251</a>                 
-<a name="252" href="#252">252</a>                 String uri = ref.getURI();
-<a name="253" href="#253">253</a>                 <strong class="jxr_keyword">if</strong> (uri.charAt(0) == '#') {
-<a name="254" href="#254">254</a>                     uri = uri.substring(1);
-<a name="255" href="#255">255</a>                 }
-<a name="256" href="#256">256</a>                 <a href="../../../../../org/apache/ws/security/processor/Processor.html">Processor</a> processor = wsDocInfo.getProcessor(uri);
-<a name="257" href="#257">257</a>                 <strong class="jxr_keyword">if</strong> (processor == <strong class="jxr_keyword">null</strong>) {
-<a name="258" href="#258">258</a>                     Element token = secRef.getTokenElement(elem.getOwnerDocument(), wsDocInfo, cb);
-<a name="259" href="#259">259</a>                     <em class="jxr_comment">//</em>
-<a name="260" href="#260">260</a>                     <em class="jxr_comment">// at this point check token type: Binary, SAML, EncryptedKey, Custom</em>
-<a name="261" href="#261">261</a>                     <em class="jxr_comment">//</em>
-<a name="262" href="#262">262</a>                     QName el = <strong class="jxr_keyword">new</strong> QName(token.getNamespaceURI(), token.getLocalName());
-<a name="263" href="#263">263</a>                     <strong class="jxr_keyword">if</strong> (el.equals(WSSecurityEngine.binaryToken)) {
-<a name="264" href="#264">264</a>                         certs = getCertificatesTokenReference(token, crypto);
-<a name="265" href="#265">265</a>                     } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (el.equals(WSSecurityEngine.SAML_TOKEN)) {
-<a name="266" href="#266">266</a>                         <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</strong>) {
-<a name="267" href="#267">267</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="268" href="#268">268</a>                                     WSSecurityException.FAILURE, <span class="jxr_string">"noSigCryptoFile"</span>
-<a name="269" href="#269">269</a>                             );
-<a name="270" href="#270">270</a>                         }
-<a name="271" href="#271">271</a>                         samlKi = SAMLUtil.getSAMLKeyInfo(token, crypto, cb);
-<a name="272" href="#272">272</a>                         certs = samlKi.getCerts();
-<a name="273" href="#273">273</a>                         secretKey = samlKi.getSecret();
-<a name="274" href="#274">274</a> 
-<a name="275" href="#275">275</a>                     } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (el.equals(WSSecurityEngine.ENCRYPTED_KEY)){
-<a name="276" href="#276">276</a>                         <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</strong>) {
-<a name="277" href="#277">277</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="278" href="#278">278</a>                                 WSSecurityException.FAILURE, <span class="jxr_string">"noSigCryptoFile"</span>
-<a name="279" href="#279">279</a>                             );
-<a name="280" href="#280">280</a>                         }
-<a name="281" href="#281">281</a>                         <a href="../../../../../org/apache/ws/security/processor/EncryptedKeyProcessor.html">EncryptedKeyProcessor</a> encryptKeyProcessor = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/processor/EncryptedKeyProcessor.html">EncryptedKeyProcessor</a>();
-<a name="282" href="#282">282</a>                         encryptKeyProcessor.handleEncryptedKey(token, cb, crypto);
-<a name="283" href="#283">283</a>                         secretKey = encryptKeyProcessor.getDecryptedBytes();
-<a name="284" href="#284">284</a>                     } <strong class="jxr_keyword">else</strong> {
-<a name="285" href="#285">285</a>                         <em class="jxr_comment">// Try custom token through callback handler</em>
-<a name="286" href="#286">286</a>                         <em class="jxr_comment">// try to find a custom token</em>
-<a name="287" href="#287">287</a>                         String id = secRef.getReference().getURI();
-<a name="288" href="#288">288</a>                         <strong class="jxr_keyword">if</strong> (id.charAt(0) == '#') {
-<a name="289" href="#289">289</a>                             id = id.substring(1);
-<a name="290" href="#290">290</a>                         }
-<a name="291" href="#291">291</a>                         <a href="../../../../../org/apache/ws/security/WSPasswordCallback.html">WSPasswordCallback</a> pwcb = 
-<a name="292" href="#292">292</a>                             <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSPasswordCallback.html">WSPasswordCallback</a>(id, WSPasswordCallback.CUSTOM_TOKEN);
-<a name="293" href="#293">293</a>                         <strong class="jxr_keyword">try</strong> {
-<a name="294" href="#294">294</a>                             Callback[] callbacks = <strong class="jxr_keyword">new</strong> Callback[]{pwcb};
-<a name="295" href="#295">295</a>                             cb.handle(callbacks);
-<a name="296" href="#296">296</a>                         } <strong class="jxr_keyword">catch</strong> (Exception e) {
-<a name="297" href="#297">297</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="298" href="#298">298</a>                                     WSSecurityException.FAILURE,
-<a name="299" href="#299">299</a>                                     <span class="jxr_string">"noPassword"</span>, 
-<a name="300" href="#300">300</a>                                     <strong class="jxr_keyword">new</strong> Object[] {id}, 
-<a name="301" href="#301">301</a>                                     e
-<a name="302" href="#302">302</a>                             );
-<a name="303" href="#303">303</a>                         }
-<a name="304" href="#304">304</a> 
-<a name="305" href="#305">305</a>                         secretKey = pwcb.getKey();
-<a name="306" href="#306">306</a>                         customTokenId = id;
-<a name="307" href="#307">307</a>                         <strong class="jxr_keyword">if</strong> (secretKey == <strong class="jxr_keyword">null</strong>) {
-<a name="308" href="#308">308</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="309" href="#309">309</a>                                     WSSecurityException.INVALID_SECURITY,
-<a name="310" href="#310">310</a>                                     <span class="jxr_string">"unsupportedKeyInfo"</span>, 
-<a name="311" href="#311">311</a>                                     <strong class="jxr_keyword">new</strong> Object[]{el.toString()}
-<a name="312" href="#312">312</a>                             );
-<a name="313" href="#313">313</a>                         }
-<a name="314" href="#314">314</a>                     }
-<a name="315" href="#315">315</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof UsernameTokenProcessor) {
-<a name="316" href="#316">316</a>                     ut = ((UsernameTokenProcessor)processor).getUt();
-<a name="317" href="#317">317</a>                     <strong class="jxr_keyword">if</strong> (ut.isDerivedKey()) {
-<a name="318" href="#318">318</a>                         secretKey = ut.getDerivedKey();
-<a name="319" href="#319">319</a>                     } <strong class="jxr_keyword">else</strong> {
-<a name="320" href="#320">320</a>                         secretKey = ut.getSecretKey(secretKeyLength);
-<a name="321" href="#321">321</a>                     }
-<a name="322" href="#322">322</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof BinarySecurityTokenProcessor) {
-<a name="323" href="#323">323</a>                     certs = ((BinarySecurityTokenProcessor)processor).getCertificates();
-<a name="324" href="#324">324</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof EncryptedKeyProcessor) {
-<a name="325" href="#325">325</a>                     <a href="../../../../../org/apache/ws/security/processor/EncryptedKeyProcessor.html">EncryptedKeyProcessor</a> ekProcessor = (EncryptedKeyProcessor)processor;
-<a name="326" href="#326">326</a>                     secretKey = ekProcessor.getDecryptedBytes();
-<a name="327" href="#327">327</a>                     customTokenId = ekProcessor.getId();
-<a name="328" href="#328">328</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof SecurityContextTokenProcessor) {
-<a name="329" href="#329">329</a>                     <a href="../../../../../org/apache/ws/security/processor/SecurityContextTokenProcessor.html">SecurityContextTokenProcessor</a> sctProcessor = 
-<a name="330" href="#330">330</a>                         (<a href="../../../../../org/apache/ws/security/processor/SecurityContextTokenProcessor.html">SecurityContextTokenProcessor</a>)processor;
-<a name="331" href="#331">331</a>                     secretKey = sctProcessor.getSecret();
-<a name="332" href="#332">332</a>                     customTokenId = sctProcessor.getIdentifier();
-<a name="333" href="#333">333</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof DerivedKeyTokenProcessor) {
-<a name="334" href="#334">334</a>                     <a href="../../../../../org/apache/ws/security/processor/DerivedKeyTokenProcessor.html">DerivedKeyTokenProcessor</a> dktProcessor = 
-<a name="335" href="#335">335</a>                         (<a href="../../../../../org/apache/ws/security/processor/DerivedKeyTokenProcessor.html">DerivedKeyTokenProcessor</a>) processor;
-<a name="336" href="#336">336</a>                     String signatureMethodURI = sig.getSignedInfo().getSignatureMethodURI();
-<a name="337" href="#337">337</a>                     dkt = dktProcessor.getDerivedKeyToken();
-<a name="338" href="#338">338</a>                     <strong class="jxr_keyword">int</strong> keyLength = (dkt.getLength() &gt; 0) ? dkt.getLength() : 
-<a name="339" href="#339">339</a>                         WSSecurityUtil.getKeyLength(signatureMethodURI);
-<a name="340" href="#340">340</a>                     
-<a name="341" href="#341">341</a>                     secretKey = dktProcessor.getKeyBytes(keyLength);
-<a name="342" href="#342">342</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof SAMLTokenProcessor) {
-<a name="343" href="#343">343</a>                     <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</strong>) {
-<a name="344" href="#344">344</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="345" href="#345">345</a>                             WSSecurityException.FAILURE, <span class="jxr_string">"noSigCryptoFile"</span>
-<a name="346" href="#346">346</a>                         );
-<a name="347" href="#347">347</a>                     }
-<a name="348" href="#348">348</a>                     <a href="../../../../../org/apache/ws/security/processor/SAMLTokenProcessor.html">SAMLTokenProcessor</a> samlp = (SAMLTokenProcessor) processor;
-<a name="349" href="#349">349</a>                     samlKi = SAMLUtil.getSAMLKeyInfo(samlp.getSamlTokenElement(), crypto, cb);
-<a name="350" href="#350">350</a>                     certs = samlKi.getCerts();
-<a name="351" href="#351">351</a>                     secretKey = samlKi.getSecret();
-<a name="352" href="#352">352</a>                     publicKey = samlKi.getPublicKey();
-<a name="353" href="#353">353</a>                 }
-<a name="354" href="#354">354</a>             } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (secRef.containsX509Data() || secRef.containsX509IssuerSerial()) {
-<a name="355" href="#355">355</a>                 certs = secRef.getX509IssuerSerial(crypto);
-<a name="356" href="#356">356</a>             } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (secRef.containsKeyIdentifier()) {
-<a name="357" href="#357">357</a>                 <strong class="jxr_keyword">if</strong> (secRef.getKeyIdentifierValueType().equals(SecurityTokenReference.ENC_KEY_SHA1_URI)) {
-<a name="358" href="#358">358</a>                     String id = secRef.getKeyIdentifierValue();
-<a name="359" href="#359">359</a>                     <a href="../../../../../org/apache/ws/security/WSPasswordCallback.html">WSPasswordCallback</a> pwcb = 
-<a name="360" href="#360">360</a>                         <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSPasswordCallback.html">WSPasswordCallback</a>(
-<a name="361" href="#361">361</a>                             id,
-<a name="362" href="#362">362</a>                             <strong class="jxr_keyword">null</strong>,
-<a name="363" href="#363">363</a>                             SecurityTokenReference.ENC_KEY_SHA1_URI,
-<a name="364" href="#364">364</a>                             WSPasswordCallback.ENCRYPTED_KEY_TOKEN
-<a name="365" href="#365">365</a>                         );
-<a name="366" href="#366">366</a>                     <strong class="jxr_keyword">try</strong> {
-<a name="367" href="#367">367</a>                         Callback[] callbacks = <strong class="jxr_keyword">new</strong> Callback[]{pwcb};
-<a name="368" href="#368">368</a>                         cb.handle(callbacks);
-<a name="369" href="#369">369</a>                     } <strong class="jxr_keyword">catch</strong> (Exception e) {
-<a name="370" href="#370">370</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="371" href="#371">371</a>                             WSSecurityException.FAILURE,
-<a name="372" href="#372">372</a>                             <span class="jxr_string">"noPassword"</span>, 
-<a name="373" href="#373">373</a>                             <strong class="jxr_keyword">new</strong> Object[] {id}, 
-<a name="374" href="#374">374</a>                             e
-<a name="375" href="#375">375</a>                         );
-<a name="376" href="#376">376</a>                     }
-<a name="377" href="#377">377</a>                     secretKey = pwcb.getKey();
-<a name="378" href="#378">378</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (WSConstants.WSS_SAML_KI_VALUE_TYPE.equals(secRef.getKeyIdentifierValueType())) { 
-<a name="379" href="#379">379</a>                     Element token = 
-<a name="380" href="#380">380</a>                         secRef.getKeyIdentifierTokenElement(elem.getOwnerDocument(), wsDocInfo, cb);
-<a name="381" href="#381">381</a>                     
-<a name="382" href="#382">382</a>                     <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</strong>) {
-<a name="383" href="#383">383</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="384" href="#384">384</a>                             WSSecurityException.FAILURE, <span class="jxr_string">"noSigCryptoFile"</span>
-<a name="385" href="#385">385</a>                         );
-<a name="386" href="#386">386</a>                     }
-<a name="387" href="#387">387</a>                     samlKi = SAMLUtil.getSAMLKeyInfo(token, crypto, cb);
-<a name="388" href="#388">388</a>                     certs = samlKi.getCerts();
-<a name="389" href="#389">389</a>                     secretKey = samlKi.getSecret();
-<a name="390" href="#390">390</a>                     publicKey = samlKi.getPublicKey();
-<a name="391" href="#391">391</a>                 } <strong class="jxr_keyword">else</strong> {
-<a name="392" href="#392">392</a>                     certs = secRef.getKeyIdentifier(crypto);
-<a name="393" href="#393">393</a>                 }
-<a name="394" href="#394">394</a>             } <strong class="jxr_keyword">else</strong> {
-<a name="395" href="#395">395</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="396" href="#396">396</a>                     WSSecurityException.INVALID_SECURITY,
-<a name="397" href="#397">397</a>                     <span class="jxr_string">"unsupportedKeyInfo"</span>, 
-<a name="398" href="#398">398</a>                     <strong class="jxr_keyword">new</strong> Object[]{node.toString()}
-<a name="399" href="#399">399</a>                 );
-<a name="400" href="#400">400</a>             }
-<a name="401" href="#401">401</a>         } <strong class="jxr_keyword">else</strong> {
-<a name="402" href="#402">402</a>             <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</strong>) {
-<a name="403" href="#403">403</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="404" href="#404">404</a>             }
-<a name="405" href="#405">405</a>             <strong class="jxr_keyword">if</strong> (crypto.getDefaultX509Alias() != <strong class="jxr_keyword">null</strong>) {
-<a name="406" href="#406">406</a>                 certs = crypto.getCertificates(crypto.getDefaultX509Alias());
-<a name="407" href="#407">407</a>             } <strong class="jxr_keyword">else</strong> {
-<a name="408" href="#408">408</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="409" href="#409">409</a>                     WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"unsupportedKeyInfo"</span>
+<a name="204" href="#204">204</a>         <strong class="jxr_keyword">long</strong> t0 = 0, t1 = 0, t2 = 0;
+<a name="205" href="#205">205</a>         <strong class="jxr_keyword">if</strong> (tlog.isDebugEnabled()) {
+<a name="206" href="#206">206</a>             t0 = System.currentTimeMillis();
+<a name="207" href="#207">207</a>         }
+<a name="208" href="#208">208</a> 
+<a name="209" href="#209">209</a>         XMLSignature sig = <strong class="jxr_keyword">null</strong>;
+<a name="210" href="#210">210</a>         <strong class="jxr_keyword">try</strong> {
+<a name="211" href="#211">211</a>             sig = <strong class="jxr_keyword">new</strong> XMLSignature(elem, <strong class="jxr_keyword">null</strong>);
+<a name="212" href="#212">212</a>         } <strong class="jxr_keyword">catch</strong> (XMLSecurityException e2) {
+<a name="213" href="#213">213</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="214" href="#214">214</a>                 WSSecurityException.FAILED_CHECK, <span class="jxr_string">"noXMLSig"</span>, <strong class="jxr_keyword">null</strong>, e2
+<a name="215" href="#215">215</a>             );
+<a name="216" href="#216">216</a>         }
+<a name="217" href="#217">217</a> 
+<a name="218" href="#218">218</a>         sig.addResourceResolver(EnvelopeIdResolver.getInstance());
+<a name="219" href="#219">219</a> 
+<a name="220" href="#220">220</a>         KeyInfo info = sig.getKeyInfo();
+<a name="221" href="#221">221</a>         byte[] secretKey = <strong class="jxr_keyword">null</strong>;
+<a name="222" href="#222">222</a>         <a href="../../../../../org/apache/ws/security/message/token/UsernameToken.html">UsernameToken</a> ut = <strong class="jxr_keyword">null</strong>;
+<a name="223" href="#223">223</a>         <a href="../../../../../org/apache/ws/security/message/token/DerivedKeyToken.html">DerivedKeyToken</a> dkt = <strong class="jxr_keyword">null</strong>;
+<a name="224" href="#224">224</a>         <a href="../../../../../org/apache/ws/security/saml/SAMLKeyInfo.html">SAMLKeyInfo</a> samlKi = <strong class="jxr_keyword">null</strong>;
+<a name="225" href="#225">225</a>         String customTokenId = <strong class="jxr_keyword">null</strong>;
+<a name="226" href="#226">226</a>         java.security.PublicKey publicKey = <strong class="jxr_keyword">null</strong>;
+<a name="227" href="#227">227</a>         X509Certificate[] certs = <strong class="jxr_keyword">null</strong>;
+<a name="228" href="#228">228</a>         <strong class="jxr_keyword">boolean</strong> validateCertificateChain = false;
+<a name="229" href="#229">229</a>         
+<a name="230" href="#230">230</a>         <strong class="jxr_keyword">if</strong> (info != <strong class="jxr_keyword">null</strong> &amp;&amp; info.containsKeyValue()) {
+<a name="231" href="#231">231</a>             <strong class="jxr_keyword">try</strong> {
+<a name="232" href="#232">232</a>                 publicKey = info.getPublicKey();
+<a name="233" href="#233">233</a>             } <strong class="jxr_keyword">catch</strong> (Exception ex) {
+<a name="234" href="#234">234</a>                 <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(ex.getMessage(), ex);
+<a name="235" href="#235">235</a>             }
+<a name="236" href="#236">236</a>         } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (info != <strong class="jxr_keyword">null</strong>) {
+<a name="237" href="#237">237</a>             Node node = 
+<a name="238" href="#238">238</a>                 WSSecurityUtil.getDirectChild(
+<a name="239" href="#239">239</a>                     info.getElement(),
+<a name="240" href="#240">240</a>                     SecurityTokenReference.SECURITY_TOKEN_REFERENCE,
+<a name="241" href="#241">241</a>                     WSConstants.WSSE_NS
+<a name="242" href="#242">242</a>                 );
+<a name="243" href="#243">243</a>             <strong class="jxr_keyword">if</strong> (node == <strong class="jxr_keyword">null</strong>) {
+<a name="244" href="#244">244</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="245" href="#245">245</a>                     WSSecurityException.INVALID_SECURITY, <span class="jxr_string">"unsupportedKeyInfo"</span>
+<a name="246" href="#246">246</a>                 );
+<a name="247" href="#247">247</a>             }
+<a name="248" href="#248">248</a>             <a href="../../../../../org/apache/ws/security/message/token/SecurityTokenReference.html">SecurityTokenReference</a> secRef = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/message/token/SecurityTokenReference.html">SecurityTokenReference</a>((Element) node);
+<a name="249" href="#249">249</a>             <em class="jxr_comment">//</em>
+<a name="250" href="#250">250</a>             <em class="jxr_comment">// Here we get some information about the document that is being</em>
+<a name="251" href="#251">251</a>             <em class="jxr_comment">// processed, in particular the crypto implementation, and already</em>
+<a name="252" href="#252">252</a>             <em class="jxr_comment">// detected BST that may be used later during dereferencing.</em>
+<a name="253" href="#253">253</a>             <em class="jxr_comment">//</em>
+<a name="254" href="#254">254</a>             <strong class="jxr_keyword">if</strong> (secRef.containsReference()) {
+<a name="255" href="#255">255</a>                 org.apache.ws.security.message.token.Reference ref = secRef.getReference();
+<a name="256" href="#256">256</a>                 
+<a name="257" href="#257">257</a>                 String uri = ref.getURI();
+<a name="258" href="#258">258</a>                 <strong class="jxr_keyword">if</strong> (uri.charAt(0) == '#') {
+<a name="259" href="#259">259</a>                     uri = uri.substring(1);
+<a name="260" href="#260">260</a>                 }
+<a name="261" href="#261">261</a>                 <a href="../../../../../org/apache/ws/security/processor/Processor.html">Processor</a> processor = wsDocInfo.getProcessor(uri);
+<a name="262" href="#262">262</a>                 <strong class="jxr_keyword">if</strong> (processor == <strong class="jxr_keyword">null</strong>) {
+<a name="263" href="#263">263</a>                     Element token = secRef.getTokenElement(elem.getOwnerDocument(), wsDocInfo, cb);
+<a name="264" href="#264">264</a>                     <em class="jxr_comment">//</em>
+<a name="265" href="#265">265</a>                     <em class="jxr_comment">// at this point check token type: Binary, SAML, EncryptedKey, Custom</em>
+<a name="266" href="#266">266</a>                     <em class="jxr_comment">//</em>
+<a name="267" href="#267">267</a>                     QName el = <strong class="jxr_keyword">new</strong> QName(token.getNamespaceURI(), token.getLocalName());
+<a name="268" href="#268">268</a>                     <strong class="jxr_keyword">if</strong> (el.equals(WSSecurityEngine.binaryToken)) {
+<a name="269" href="#269">269</a>                         certs = getCertificatesTokenReference(token, crypto);
+<a name="270" href="#270">270</a>                         <strong class="jxr_keyword">if</strong> (certs != <strong class="jxr_keyword">null</strong> &amp;&amp; certs.length &gt; 1) {
+<a name="271" href="#271">271</a>                             validateCertificateChain = <strong class="jxr_keyword">true</strong>;
+<a name="272" href="#272">272</a>                         }
+<a name="273" href="#273">273</a>                     } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (el.equals(WSSecurityEngine.SAML_TOKEN)) {
+<a name="274" href="#274">274</a>                         <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</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.FAILURE, <span class="jxr_string">"noSigCryptoFile"</span>
+<a name="277" href="#277">277</a>                             );
+<a name="278" href="#278">278</a>                         }
+<a name="279" href="#279">279</a>                         samlKi = SAMLUtil.getSAMLKeyInfo(token, crypto, cb);
+<a name="280" href="#280">280</a>                         certs = samlKi.getCerts();
+<a name="281" href="#281">281</a>                         secretKey = samlKi.getSecret();
+<a name="282" href="#282">282</a> 
+<a name="283" href="#283">283</a>                     } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (el.equals(WSSecurityEngine.ENCRYPTED_KEY)){
+<a name="284" href="#284">284</a>                         <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</strong>) {
+<a name="285" href="#285">285</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="286" href="#286">286</a>                                 WSSecurityException.FAILURE, <span class="jxr_string">"noSigCryptoFile"</span>
+<a name="287" href="#287">287</a>                             );
+<a name="288" href="#288">288</a>                         }
+<a name="289" href="#289">289</a>                         <a href="../../../../../org/apache/ws/security/processor/EncryptedKeyProcessor.html">EncryptedKeyProcessor</a> encryptKeyProcessor = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/processor/EncryptedKeyProcessor.html">EncryptedKeyProcessor</a>();
+<a name="290" href="#290">290</a>                         encryptKeyProcessor.handleEncryptedKey(token, cb, crypto);
+<a name="291" href="#291">291</a>                         secretKey = encryptKeyProcessor.getDecryptedBytes();
+<a name="292" href="#292">292</a>                     } <strong class="jxr_keyword">else</strong> {
+<a name="293" href="#293">293</a>                         <em class="jxr_comment">// Try custom token through callback handler</em>
+<a name="294" href="#294">294</a>                         <em class="jxr_comment">// try to find a custom token</em>
+<a name="295" href="#295">295</a>                         String id = secRef.getReference().getURI();
+<a name="296" href="#296">296</a>                         <strong class="jxr_keyword">if</strong> (id.charAt(0) == '#') {
+<a name="297" href="#297">297</a>                             id = id.substring(1);
+<a name="298" href="#298">298</a>                         }
+<a name="299" href="#299">299</a>                         <a href="../../../../../org/apache/ws/security/WSPasswordCallback.html">WSPasswordCallback</a> pwcb = 
+<a name="300" href="#300">300</a>                             <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSPasswordCallback.html">WSPasswordCallback</a>(id, WSPasswordCallback.CUSTOM_TOKEN);
+<a name="301" href="#301">301</a>                         <strong class="jxr_keyword">try</strong> {
+<a name="302" href="#302">302</a>                             Callback[] callbacks = <strong class="jxr_keyword">new</strong> Callback[]{pwcb};
+<a name="303" href="#303">303</a>                             cb.handle(callbacks);
+<a name="304" href="#304">304</a>                         } <strong class="jxr_keyword">catch</strong> (Exception e) {
+<a name="305" href="#305">305</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="306" href="#306">306</a>                                     WSSecurityException.FAILURE,
+<a name="307" href="#307">307</a>                                     <span class="jxr_string">"noPassword"</span>, 
+<a name="308" href="#308">308</a>                                     <strong class="jxr_keyword">new</strong> Object[] {id}, 
+<a name="309" href="#309">309</a>                                     e
+<a name="310" href="#310">310</a>                             );
+<a name="311" href="#311">311</a>                         }
+<a name="312" href="#312">312</a> 
+<a name="313" href="#313">313</a>                         secretKey = pwcb.getKey();
+<a name="314" href="#314">314</a>                         customTokenId = id;
+<a name="315" href="#315">315</a>                         <strong class="jxr_keyword">if</strong> (secretKey == <strong class="jxr_keyword">null</strong>) {
+<a name="316" href="#316">316</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="317" href="#317">317</a>                                     WSSecurityException.INVALID_SECURITY,
+<a name="318" href="#318">318</a>                                     <span class="jxr_string">"unsupportedKeyInfo"</span>, 
+<a name="319" href="#319">319</a>                                     <strong class="jxr_keyword">new</strong> Object[]{el.toString()}
+<a name="320" href="#320">320</a>                             );
+<a name="321" href="#321">321</a>                         }
+<a name="322" href="#322">322</a>                     }
+<a name="323" href="#323">323</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof UsernameTokenProcessor) {
+<a name="324" href="#324">324</a>                     ut = ((UsernameTokenProcessor)processor).getUt();
+<a name="325" href="#325">325</a>                     <strong class="jxr_keyword">if</strong> (ut.isDerivedKey()) {
+<a name="326" href="#326">326</a>                         secretKey = ut.getDerivedKey();
+<a name="327" href="#327">327</a>                     } <strong class="jxr_keyword">else</strong> {
+<a name="328" href="#328">328</a>                         secretKey = ut.getSecretKey(secretKeyLength);
+<a name="329" href="#329">329</a>                     }
+<a name="330" href="#330">330</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof BinarySecurityTokenProcessor) {
+<a name="331" href="#331">331</a>                     certs = ((BinarySecurityTokenProcessor)processor).getCertificates();
+<a name="332" href="#332">332</a>                     <strong class="jxr_keyword">if</strong> (certs != <strong class="jxr_keyword">null</strong> &amp;&amp; certs.length &gt; 1) {
+<a name="333" href="#333">333</a>                         validateCertificateChain = <strong class="jxr_keyword">true</strong>;
+<a name="334" href="#334">334</a>                     }
+<a name="335" href="#335">335</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof EncryptedKeyProcessor) {
+<a name="336" href="#336">336</a>                     <a href="../../../../../org/apache/ws/security/processor/EncryptedKeyProcessor.html">EncryptedKeyProcessor</a> ekProcessor = (EncryptedKeyProcessor)processor;
+<a name="337" href="#337">337</a>                     secretKey = ekProcessor.getDecryptedBytes();
+<a name="338" href="#338">338</a>                     customTokenId = ekProcessor.getId();
+<a name="339" href="#339">339</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof SecurityContextTokenProcessor) {
+<a name="340" href="#340">340</a>                     <a href="../../../../../org/apache/ws/security/processor/SecurityContextTokenProcessor.html">SecurityContextTokenProcessor</a> sctProcessor = 
+<a name="341" href="#341">341</a>                         (<a href="../../../../../org/apache/ws/security/processor/SecurityContextTokenProcessor.html">SecurityContextTokenProcessor</a>)processor;
+<a name="342" href="#342">342</a>                     secretKey = sctProcessor.getSecret();
+<a name="343" href="#343">343</a>                     customTokenId = sctProcessor.getIdentifier();
+<a name="344" href="#344">344</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof DerivedKeyTokenProcessor) {
+<a name="345" href="#345">345</a>                     <a href="../../../../../org/apache/ws/security/processor/DerivedKeyTokenProcessor.html">DerivedKeyTokenProcessor</a> dktProcessor = 
+<a name="346" href="#346">346</a>                         (<a href="../../../../../org/apache/ws/security/processor/DerivedKeyTokenProcessor.html">DerivedKeyTokenProcessor</a>) processor;
+<a name="347" href="#347">347</a>                     String signatureMethodURI = sig.getSignedInfo().getSignatureMethodURI();
+<a name="348" href="#348">348</a>                     dkt = dktProcessor.getDerivedKeyToken();
+<a name="349" href="#349">349</a>                     <strong class="jxr_keyword">int</strong> keyLength = (dkt.getLength() &gt; 0) ? dkt.getLength() : 
+<a name="350" href="#350">350</a>                         WSSecurityUtil.getKeyLength(signatureMethodURI);
+<a name="351" href="#351">351</a>                     
+<a name="352" href="#352">352</a>                     secretKey = dktProcessor.getKeyBytes(keyLength);
+<a name="353" href="#353">353</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (processor instanceof SAMLTokenProcessor) {
+<a name="354" href="#354">354</a>                     <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</strong>) {
+<a name="355" href="#355">355</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="356" href="#356">356</a>                             WSSecurityException.FAILURE, <span class="jxr_string">"noSigCryptoFile"</span>
+<a name="357" href="#357">357</a>                         );
+<a name="358" href="#358">358</a>                     }
+<a name="359" href="#359">359</a>                     <a href="../../../../../org/apache/ws/security/processor/SAMLTokenProcessor.html">SAMLTokenProcessor</a> samlp = (SAMLTokenProcessor) processor;
+<a name="360" href="#360">360</a>                     samlKi = SAMLUtil.getSAMLKeyInfo(samlp.getSamlTokenElement(), crypto, cb);
+<a name="361" href="#361">361</a>                     certs = samlKi.getCerts();
+<a name="362" href="#362">362</a>                     secretKey = samlKi.getSecret();
+<a name="363" href="#363">363</a>                     publicKey = samlKi.getPublicKey();
+<a name="364" href="#364">364</a>                 }
+<a name="365" href="#365">365</a>             } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (secRef.containsX509Data() || secRef.containsX509IssuerSerial()) {
+<a name="366" href="#366">366</a>                 certs = secRef.getX509IssuerSerial(crypto);
+<a name="367" href="#367">367</a>             } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (secRef.containsKeyIdentifier()) {
+<a name="368" href="#368">368</a>                 <strong class="jxr_keyword">if</strong> (secRef.getKeyIdentifierValueType().equals(SecurityTokenReference.ENC_KEY_SHA1_URI)) {
+<a name="369" href="#369">369</a>                     String id = secRef.getKeyIdentifierValue();
+<a name="370" href="#370">370</a>                     <a href="../../../../../org/apache/ws/security/WSPasswordCallback.html">WSPasswordCallback</a> pwcb = 
+<a name="371" href="#371">371</a>                         <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/WSPasswordCallback.html">WSPasswordCallback</a>(
+<a name="372" href="#372">372</a>                             id,
+<a name="373" href="#373">373</a>                             <strong class="jxr_keyword">null</strong>,
+<a name="374" href="#374">374</a>                             SecurityTokenReference.ENC_KEY_SHA1_URI,
+<a name="375" href="#375">375</a>                             WSPasswordCallback.ENCRYPTED_KEY_TOKEN
+<a name="376" href="#376">376</a>                         );
+<a name="377" href="#377">377</a>                     <strong class="jxr_keyword">try</strong> {
+<a name="378" href="#378">378</a>                         Callback[] callbacks = <strong class="jxr_keyword">new</strong> Callback[]{pwcb};
+<a name="379" href="#379">379</a>                         cb.handle(callbacks);
+<a name="380" href="#380">380</a>                     } <strong class="jxr_keyword">catch</strong> (Exception e) {
+<a name="381" href="#381">381</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="382" href="#382">382</a>                             WSSecurityException.FAILURE,
+<a name="383" href="#383">383</a>                             <span class="jxr_string">"noPassword"</span>, 
+<a name="384" href="#384">384</a>                             <strong class="jxr_keyword">new</strong> Object[] {id}, 
+<a name="385" href="#385">385</a>                             e
+<a name="386" href="#386">386</a>                         );
+<a name="387" href="#387">387</a>                     }
+<a name="388" href="#388">388</a>                     secretKey = pwcb.getKey();
+<a name="389" href="#389">389</a>                 } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (WSConstants.WSS_SAML_KI_VALUE_TYPE.equals(secRef.getKeyIdentifierValueType())) { 
+<a name="390" href="#390">390</a>                     Element token = 
+<a name="391" href="#391">391</a>                         secRef.getKeyIdentifierTokenElement(elem.getOwnerDocument(), wsDocInfo, cb);
+<a name="392" href="#392">392</a>                     
+<a name="393" href="#393">393</a>                     <strong class="jxr_keyword">if</strong> (crypto == <strong class="jxr_keyword">null</strong>) {
+<a name="394" href="#394">394</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="395" href="#395">395</a>                             WSSecurityException.FAILURE, <span class="jxr_string">"noSigCryptoFile"</span>
+<a name="396" href="#396">396</a>                         );
+<a name="397" href="#397">397</a>                     }
+<a name="398" href="#398">398</a>                     samlKi = SAMLUtil.getSAMLKeyInfo(token, crypto, cb);
+<a name="399" href="#399">399</a>                     certs = samlKi.getCerts();
+<a name="400" href="#400">400</a>                     secretKey = samlKi.getSecret();
+<a name="401" href="#401">401</a>                     publicKey = samlKi.getPublicKey();
+<a name="402" href="#402">402</a>                 } <strong class="jxr_keyword">else</strong> {
+<a name="403" href="#403">403</a>                     certs = secRef.getKeyIdentifier(crypto);
+<a name="404" href="#404">404</a>                 }
+<a name="405" href="#405">405</a>             } <strong class="jxr_keyword">else</strong> {
+<a name="406" href="#406">406</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="407" href="#407">407</a>                     WSSecurityException.INVALID_SECURITY,
+<a name="408" href="#408">408</a>                     <span class="jxr_string">"unsupportedKeyInfo"</span>, 
+<a name="409" href="#409">409</a>                     <strong class="jxr_keyword">new</strong> Object[]{node.toString()}
 <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>         <strong class="jxr_keyword">if</strong> (tlog.isDebugEnabled()) {
-<a name="414" href="#414">414</a>             t1 = System.currentTimeMillis();
-<a name="415" href="#415">415</a>         }
-<a name="416" href="#416">416</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="417" href="#417">417</a>             &amp;&amp; secretKey == <strong class="jxr_keyword">null</strong>
-<a name="418" href="#418">418</a>             &amp;&amp; publicKey == <strong class="jxr_keyword">null</strong>) {
-<a name="419" href="#419">419</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="420" href="#420">420</a>         }
-<a name="421" href="#421">421</a>         <strong class="jxr_keyword">if</strong> (certs != <strong class="jxr_keyword">null</strong>) {
-<a name="422" href="#422">422</a>             <strong class="jxr_keyword">try</strong> {
-<a name="423" href="#423">423</a>                 certs[0].checkValidity();
-<a name="424" href="#424">424</a>             } <strong class="jxr_keyword">catch</strong> (CertificateExpiredException e) {
-<a name="425" href="#425">425</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="426" href="#426">426</a>                     WSSecurityException.FAILED_CHECK, <span class="jxr_string">"invalidCert"</span>, <strong class="jxr_keyword">null</strong>, e
-<a name="427" href="#427">427</a>                 );
-<a name="428" href="#428">428</a>             } <strong class="jxr_keyword">catch</strong> (CertificateNotYetValidException e) {
-<a name="429" href="#429">429</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="430" href="#430">430</a>                     WSSecurityException.FAILED_CHECK, <span class="jxr_string">"invalidCert"</span>, <strong class="jxr_keyword">null</strong>, e
-<a name="431" href="#431">431</a>                 );
-<a name="432" href="#432">432</a>             }
-<a name="433" href="#433">433</a>         }
-<a name="434" href="#434">434</a>         <em class="jxr_comment">//</em>
-<a name="435" href="#435">435</a>         <em class="jxr_comment">// Delegate verification of a public key to a Callback Handler</em>
-<a name="436" href="#436">436</a>         <em class="jxr_comment">//</em>
-<a name="437" href="#437">437</a>         <strong class="jxr_keyword">if</strong> (publicKey != <strong class="jxr_keyword">null</strong>) {
-<a name="438" href="#438">438</a>             <a href="../../../../../org/apache/ws/security/PublicKeyCallback.html">PublicKeyCallback</a> pwcb = 
-<a name="439" href="#439">439</a>                 <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/PublicKeyCallback.html">PublicKeyCallback</a>(publicKey);
-<a name="440" href="#440">440</a>             <strong class="jxr_keyword">try</strong> {
-<a name="441" href="#441">441</a>                 Callback[] callbacks = <strong class="jxr_keyword">new</strong> Callback[]{pwcb};
-<a name="442" href="#442">442</a>                 cb.handle(callbacks);
-<a name="443" href="#443">443</a>                 <strong class="jxr_keyword">if</strong> (!pwcb.isVerified()) {
-<a name="444" href="#444">444</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="445" href="#445">445</a>                         WSSecurityException.FAILED_AUTHENTICATION, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">null</strong>
-<a name="446" href="#446">446</a>                     );
-<a name="447" href="#447">447</a>                 }
-<a name="448" href="#448">448</a>             } <strong class="jxr_keyword">catch</strong> (Exception e) {
-<a name="449" href="#449">449</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="450" href="#450">450</a>                     WSSecurityException.FAILED_AUTHENTICATION, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">null</strong>, e
-<a name="451" href="#451">451</a>                 );
-<a name="452" href="#452">452</a>             }
-<a name="453" href="#453">453</a>         }
-<a name="454" href="#454">454</a>         <strong class="jxr_keyword">try</strong> {
-<a name="455" href="#455">455</a>             <strong class="jxr_keyword">boolean</strong> signatureOk = false;
-<a name="456" href="#456">456</a>             <strong class="jxr_keyword">if</strong> (certs != <strong class="jxr_keyword">null</strong>) {
-<a name="457" href="#457">457</a>                 signatureOk = sig.checkSignatureValue(certs[0]);
-<a name="458" href="#458">458</a>             } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (publicKey != <strong class="jxr_keyword">null</strong>) {
-<a name="459" href="#459">459</a>                 signatureOk = sig.checkSignatureValue(publicKey);
-<a name="460" href="#460">460</a>             } <strong class="jxr_keyword">else</strong> {
-<a name="461" href="#461">461</a>                 signatureOk = sig.checkSignatureValue(sig.createSecretKey(secretKey));
-<a name="462" href="#462">462</a>             }
-<a name="463" href="#463">463</a>             <strong class="jxr_keyword">if</strong> (signatureOk) {
-<a name="464" href="#464">464</a>                 <strong class="jxr_keyword">if</strong> (tlog.isDebugEnabled()) {
-<a name="465" href="#465">465</a>                     t2 = System.currentTimeMillis();
-<a name="466" href="#466">466</a>                     tlog.debug(
-<a name="467" href="#467">467</a>                         <span class="jxr_string">"Verify: total= "</span> + (t2 - t0) + <span class="jxr_string">", prepare-cert= "</span> + (t1 - t0) 
-<a name="468" href="#468">468</a>                         + <span class="jxr_string">", verify= "</span> + (t2 - t1)
-<a name="469" href="#469">469</a>                     );
-<a name="470" href="#470">470</a>                 }
-<a name="471" href="#471">471</a>                 signatureValue[0] = sig.getSignatureValue();
-<a name="472" href="#472">472</a>                 <em class="jxr_comment">//</em>
-<a name="473" href="#473">473</a>                 <em class="jxr_comment">// Now dig into the Signature element to get the elements that</em>
-<a name="474" href="#474">474</a>                 <em class="jxr_comment">// this Signature covers. Build the QName of these Elements and</em>
-<a name="475" href="#475">475</a>                 <em class="jxr_comment">// return them to caller</em>
-<a name="476" href="#476">476</a>                 <em class="jxr_comment">//</em>
-<a name="477" href="#477">477</a>                 SignedInfo si = sig.getSignedInfo();
-<a name="478" href="#478">478</a>                 <strong class="jxr_keyword">int</strong> numReferences = si.getLength();
-<a name="479" href="#479">479</a>                 <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; numReferences; i++) {
-<a name="480" href="#480">480</a>                     <a href="../../../../../org/apache/ws/security/message/token/Reference.html">Reference</a> siRef;
-<a name="481" href="#481">481</a>                     <strong class="jxr_keyword">try</strong> {
-<a name="482" href="#482">482</a>                         siRef = si.item(i);
-<a name="483" href="#483">483</a>                     } <strong class="jxr_keyword">catch</strong> (XMLSecurityException e3) {
-<a name="484" href="#484">484</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="485" href="#485">485</a>                             WSSecurityException.FAILED_CHECK, <strong class="jxr_keyword">null</strong>, <strong class="jxr_keyword">null</strong>, e3
-<a name="486" href="#486">486</a>                         );
-<a name="487" href="#487">487</a>                     }
-<a name="488" href="#488">488</a>                     String uri = siRef.getURI();
-<a name="489" href="#489">489</a>                     <strong class="jxr_keyword">if</strong> (uri != <strong class="jxr_keyword">null</strong> &amp;&amp; !<span class="jxr_string">""</span>.equals(uri)) {
-<a name="490" href="#490">490</a>                         
-<a name="491" href="#491">491</a>                         Element se = <strong class="jxr_keyword">null</strong>;
-<a name="492" href="#492">492</a>                         <strong class="jxr_keyword">try</strong> {
-<a name="493" href="#493">493</a>                             Transforms transforms = siRef.getTransforms();
-<a name="494" href="#494">494</a>                             <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> j = 0; j &lt; transforms.getLength(); j++) {
-<a name="495" href="#495">495</a>                                 Transform transform = transforms.item(j);
-<a name="496" href="#496">496</a>                                 <em class="jxr_comment">// We have some transforming to do before we can </em>
-<a name="497" href="#497">497</a>                                 <em class="jxr_comment">// determine the protected element.</em>
-<a name="498" href="#498">498</a>                                 <strong class="jxr_keyword">if</strong> (STRTransform.implementedTransformURI
-<a name="499" href="#499">499</a>                                         .equals(transform.getURI())) {
-<a name="500" href="#500">500</a>                                     
-<a name="501" href="#501">501</a>                                     XMLSignatureInput signatureInput = 
-<a name="502" href="#502">502</a>                                         siRef.getContentsBeforeTransformation();
-<a name="503" href="#503">503</a>                                     
-<a name="504" href="#504">504</a>                                     <strong class="jxr_keyword">if</strong> (signatureInput.isElement()) {
-<a name="505" href="#505">505</a>                                         <em class="jxr_comment">// The signature was already validated,</em>
-<a name="506" href="#506">506</a>                                         <em class="jxr_comment">// meaning that this element was already</em>
-<a name="507" href="#507">507</a>                                         <em class="jxr_comment">// parsed.  We can therefore be pretty</em>
-<a name="508" href="#508">508</a>                                         <em class="jxr_comment">// confident that this constructor will work.</em>
-<a name="509" href="#509">509</a>                                         <a href="../../../../../org/apache/ws/security/message/token/SecurityTokenReference.html">SecurityTokenReference</a> secTokenRef = 
-<a name="510" href="#510">510</a>                                             <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/ws/security/message/token/SecurityTokenReference.html">SecurityTokenReference</a>(
-<a name="511" href="#511">511</a>                                                     (Element) signatureInput.getSubNode());
-<a name="512" href="#512">512</a>                                         
-<a name="513" href="#513">513</a>                                         <em class="jxr_comment">// Use the utility to extract the element (or</em>
-<a name="514" href="#514">514</a>                                         <em class="jxr_comment">// generate a new one in some cases) from the</em>
-<a name="515" href="#515">515</a>                                         <em class="jxr_comment">// message.</em>
-<a name="516" href="#516">516</a>                                         se = STRTransformUtil.dereferenceSTR(
-<a name="517" href="#517">517</a>                                                 transform.getDocument(),
-<a name="518" href="#518">518</a>                                                 secTokenRef, wsDocInfo);
-<a name="519" href="#519">519</a>                                     } <strong class="jxr_keyword">else</strong> {
-<a name="520" href="#520">520</a>                                         <em class="jxr_comment">// The internal impl of Reference changed.</em>
-<a name="521" href="#521">521</a>                                         <em class="jxr_comment">// We expect it to return the signature input</em>
-<a name="522" href="#522">522</a>                                         <em class="jxr_comment">// based on a node/element.</em>

[... 432 lines stripped ...]


Mime
View raw message