ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1040461 [23/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/message/token/UsernameToken.html
URL: http://svn.apache.org/viewvc/webservices/wss4j/site/xref/org/apache/ws/security/message/token/UsernameToken.html?rev=1040461&r1=1040460&r2=1040461&view=diff
==============================================================================
--- webservices/wss4j/site/xref/org/apache/ws/security/message/token/UsernameToken.html (original)
+++ webservices/wss4j/site/xref/org/apache/ws/security/message/token/UsernameToken.html Tue Nov 30 11:10:26 2010
@@ -83,736 +83,793 @@
 <a name="73" href="#73">73</a>      <strong class="jxr_keyword">protected</strong> String passwordType = <strong class="jxr_keyword">null</strong>;
 <a name="74" href="#74">74</a>      <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">boolean</strong> hashed = <strong class="jxr_keyword">true</strong>;
 <a name="75" href="#75">75</a>      <strong class="jxr_keyword">private</strong> String rawPassword;        <em class="jxr_comment">// enhancement by Alberto Coletti</em>
-<a name="76" href="#76">76</a>      
-<a name="77" href="#77">77</a>      <strong class="jxr_keyword">static</strong> {
-<a name="78" href="#78">78</a>          <strong class="jxr_keyword">try</strong> {
-<a name="79" href="#79">79</a>              random = WSSecurityUtil.resolveSecureRandom();
-<a name="80" href="#80">80</a>          } <strong class="jxr_keyword">catch</strong> (NoSuchAlgorithmException e) {
-<a name="81" href="#81">81</a>              <strong class="jxr_keyword">if</strong> (DO_DEBUG) {
-<a name="82" href="#82">82</a>                  LOG.debug(e.getMessage(), e);
-<a name="83" href="#83">83</a>              }
-<a name="84" href="#84">84</a>          }
-<a name="85" href="#85">85</a>      }
-<a name="86" href="#86">86</a>      
-<a name="87" href="#87">87</a>      <em class="jxr_javadoccomment">/**</em>
-<a name="88" href="#88">88</a>  <em class="jxr_javadoccomment">     * Constructs a &lt;code&gt;UsernameToken&lt;/code&gt; object and parses the</em>
-<a name="89" href="#89">89</a>  <em class="jxr_javadoccomment">     * &lt;code&gt;wsse:UsernameToken&lt;/code&gt; element to initialize it.</em>
-<a name="90" href="#90">90</a>  <em class="jxr_javadoccomment">     * </em>
-<a name="91" href="#91">91</a>  <em class="jxr_javadoccomment">     * @param elem the &lt;code&gt;wsse:UsernameToken&lt;/code&gt; element that contains</em>
-<a name="92" href="#92">92</a>  <em class="jxr_javadoccomment">     *             the UsernameToken data</em>
-<a name="93" href="#93">93</a>  <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="94" href="#94">94</a>  <em class="jxr_javadoccomment">     */</em>
-<a name="95" href="#95">95</a>      <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/ws/security/message/token/UsernameToken.html">UsernameToken</a>(Element elem) <strong class="jxr_keyword">throws</strong> WSSecurityException {
-<a name="96" href="#96">96</a>          <strong class="jxr_keyword">this</strong> (elem, false);
-<a name="97" href="#97">97</a>      }
-<a name="98" href="#98">98</a>  
-<a name="99" href="#99">99</a>      <em class="jxr_javadoccomment">/**</em>
-<a name="100" href="#100">100</a> <em class="jxr_javadoccomment">     * Constructs a &lt;code&gt;UsernameToken&lt;/code&gt; object and parses the</em>
-<a name="101" href="#101">101</a> <em class="jxr_javadoccomment">     * &lt;code&gt;wsse:UsernameToken&lt;/code&gt; element to initialize it.</em>
-<a name="102" href="#102">102</a> <em class="jxr_javadoccomment">     * </em>
-<a name="103" href="#103">103</a> <em class="jxr_javadoccomment">     * @param elem the &lt;code&gt;wsse:UsernameToken&lt;/code&gt; element that contains</em>
-<a name="104" href="#104">104</a> <em class="jxr_javadoccomment">     *             the UsernameToken data</em>
-<a name="105" href="#105">105</a> <em class="jxr_javadoccomment">     * @param allowNamespaceQualifiedPasswordTypes whether to allow (wsse)</em>
-<a name="106" href="#106">106</a> <em class="jxr_javadoccomment">     *        namespace qualified password types or not (for interop with WCF)</em>
-<a name="107" href="#107">107</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="108" href="#108">108</a> <em class="jxr_javadoccomment">     */</em>
-<a name="109" href="#109">109</a>     <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/ws/security/message/token/UsernameToken.html">UsernameToken</a>(
-<a name="110" href="#110">110</a>         Element elem, 
-<a name="111" href="#111">111</a>         <strong class="jxr_keyword">boolean</strong> allowNamespaceQualifiedPasswordTypes
-<a name="112" href="#112">112</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="113" href="#113">113</a>         element = elem;
-<a name="114" href="#114">114</a>         QName el = <strong class="jxr_keyword">new</strong> QName(element.getNamespaceURI(), element.getLocalName());
-<a name="115" href="#115">115</a>         <strong class="jxr_keyword">if</strong> (!el.equals(TOKEN)) {
-<a name="116" href="#116">116</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="117" href="#117">117</a>                 WSSecurityException.INVALID_SECURITY_TOKEN,
-<a name="118" href="#118">118</a>                 <span class="jxr_string">"badTokenType00"</span>, 
-<a name="119" href="#119">119</a>                 <strong class="jxr_keyword">new</strong> Object[] {el}
-<a name="120" href="#120">120</a>             );
-<a name="121" href="#121">121</a>         }
-<a name="122" href="#122">122</a>         elementUsername = 
-<a name="123" href="#123">123</a>             (Element) WSSecurityUtil.getDirectChild(
-<a name="124" href="#124">124</a>                 element, WSConstants.USERNAME_LN, WSConstants.WSSE_NS
-<a name="125" href="#125">125</a>             );
-<a name="126" href="#126">126</a>         elementPassword = 
-<a name="127" href="#127">127</a>             (Element) WSSecurityUtil.getDirectChild(
-<a name="128" href="#128">128</a>                 element, WSConstants.PASSWORD_LN, WSConstants.WSSE_NS
-<a name="129" href="#129">129</a>             );
-<a name="130" href="#130">130</a>         elementNonce = 
-<a name="131" href="#131">131</a>             (Element) WSSecurityUtil.getDirectChild(
-<a name="132" href="#132">132</a>                 element, WSConstants.NONCE_LN, WSConstants.WSSE_NS
-<a name="133" href="#133">133</a>             );
-<a name="134" href="#134">134</a>         elementCreated = 
-<a name="135" href="#135">135</a>             (Element) WSSecurityUtil.getDirectChild(
-<a name="136" href="#136">136</a>                 element, WSConstants.CREATED_LN, WSConstants.WSU_NS
-<a name="137" href="#137">137</a>             );
-<a name="138" href="#138">138</a>         elementSalt = 
-<a name="139" href="#139">139</a>             (Element) WSSecurityUtil.getDirectChild(
-<a name="140" href="#140">140</a>                 element, WSConstants.SALT_LN, WSConstants.WSSE11_NS
-<a name="141" href="#141">141</a>             );
-<a name="142" href="#142">142</a>         elementIteration = 
-<a name="143" href="#143">143</a>             (Element) WSSecurityUtil.getDirectChild(
-<a name="144" href="#144">144</a>                 element, WSConstants.ITERATION_LN, WSConstants.WSSE11_NS
-<a name="145" href="#145">145</a>             );
-<a name="146" href="#146">146</a>         <strong class="jxr_keyword">if</strong> (elementUsername == <strong class="jxr_keyword">null</strong>) {
-<a name="147" href="#147">147</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="148" href="#148">148</a>                 WSSecurityException.INVALID_SECURITY_TOKEN,
-<a name="149" href="#149">149</a>                 <span class="jxr_string">"badTokenType01"</span>, 
-<a name="150" href="#150">150</a>                 <strong class="jxr_keyword">new</strong> Object[] {el}
-<a name="151" href="#151">151</a>             );
-<a name="152" href="#152">152</a>         }
-<a name="153" href="#153">153</a>         hashed = false;
-<a name="154" href="#154">154</a>         <strong class="jxr_keyword">if</strong> (elementSalt != <strong class="jxr_keyword">null</strong>) {
-<a name="155" href="#155">155</a>             <em class="jxr_comment">//</em>
-<a name="156" href="#156">156</a>             <em class="jxr_comment">// If the UsernameToken is to be used for key derivation, the (1.1)</em>
-<a name="157" href="#157">157</a>             <em class="jxr_comment">// spec says that it cannot contain a password, and it must contain</em>
-<a name="158" href="#158">158</a>             <em class="jxr_comment">// an Iteration element</em>
-<a name="159" href="#159">159</a>             <em class="jxr_comment">//</em>
-<a name="160" href="#160">160</a>             <strong class="jxr_keyword">if</strong> (elementPassword != <strong class="jxr_keyword">null</strong> || elementIteration == <strong class="jxr_keyword">null</strong>) {
-<a name="161" href="#161">161</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="162" href="#162">162</a>                     WSSecurityException.INVALID_SECURITY_TOKEN,
-<a name="163" href="#163">163</a>                     <span class="jxr_string">"badTokenType01"</span>, 
-<a name="164" href="#164">164</a>                     <strong class="jxr_keyword">new</strong> Object[] {el}
-<a name="165" href="#165">165</a>                 );
-<a name="166" href="#166">166</a>             }
-<a name="167" href="#167">167</a>             <strong class="jxr_keyword">return</strong>;
-<a name="168" href="#168">168</a>         }
-<a name="169" href="#169">169</a>         <strong class="jxr_keyword">if</strong> (elementPassword != <strong class="jxr_keyword">null</strong>) {
-<a name="170" href="#170">170</a>             <strong class="jxr_keyword">if</strong> (elementPassword.hasAttribute(WSConstants.PASSWORD_TYPE_ATTR)) {
-<a name="171" href="#171">171</a>                 passwordType = elementPassword.getAttribute(WSConstants.PASSWORD_TYPE_ATTR);
-<a name="172" href="#172">172</a>             } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (elementPassword.hasAttributeNS(
-<a name="173" href="#173">173</a>                 WSConstants.WSSE_NS, WSConstants.PASSWORD_TYPE_ATTR)
-<a name="174" href="#174">174</a>             ) {
-<a name="175" href="#175">175</a>                 <strong class="jxr_keyword">if</strong> (allowNamespaceQualifiedPasswordTypes) {
-<a name="176" href="#176">176</a>                     passwordType = 
-<a name="177" href="#177">177</a>                         elementPassword.getAttributeNS(
-<a name="178" href="#178">178</a>                             WSConstants.WSSE_NS, WSConstants.PASSWORD_TYPE_ATTR
-<a name="179" href="#179">179</a>                         );
-<a name="180" href="#180">180</a>                 } <strong class="jxr_keyword">else</strong> {
-<a name="181" href="#181">181</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="182" href="#182">182</a>                         WSSecurityException.INVALID_SECURITY_TOKEN,
-<a name="183" href="#183">183</a>                         <span class="jxr_string">"badTokenType01"</span>, 
-<a name="184" href="#184">184</a>                         <strong class="jxr_keyword">new</strong> Object[] {el}
-<a name="185" href="#185">185</a>                     );
-<a name="186" href="#186">186</a>                 }
-<a name="187" href="#187">187</a>             }
-<a name="188" href="#188">188</a>             
-<a name="189" href="#189">189</a>         }
-<a name="190" href="#190">190</a>         <strong class="jxr_keyword">if</strong> (passwordType != <strong class="jxr_keyword">null</strong>
-<a name="191" href="#191">191</a>             &amp;&amp; passwordType.equals(WSConstants.PASSWORD_DIGEST)) {
-<a name="192" href="#192">192</a>             hashed = <strong class="jxr_keyword">true</strong>;
-<a name="193" href="#193">193</a>             <strong class="jxr_keyword">if</strong> (elementNonce == <strong class="jxr_keyword">null</strong> || elementCreated == <strong class="jxr_keyword">null</strong>) {
-<a name="194" href="#194">194</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="195" href="#195">195</a>                     WSSecurityException.INVALID_SECURITY_TOKEN,
-<a name="196" href="#196">196</a>                     <span class="jxr_string">"badTokenType01"</span>, 
-<a name="197" href="#197">197</a>                     <strong class="jxr_keyword">new</strong> Object[] {el}
-<a name="198" href="#198">198</a>                 );
-<a name="199" href="#199">199</a>             }
-<a name="200" href="#200">200</a>         }
-<a name="201" href="#201">201</a>     }
-<a name="202" href="#202">202</a> 
-<a name="203" href="#203">203</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="204" href="#204">204</a> <em class="jxr_javadoccomment">     * Constructs a &lt;code&gt;UsernameToken&lt;/code&gt; object according to the defined</em>
-<a name="205" href="#205">205</a> <em class="jxr_javadoccomment">     * parameters. &lt;p/&gt; This constructs set the password encoding to</em>
-<a name="206" href="#206">206</a> <em class="jxr_javadoccomment">     * {@link WSConstants#PASSWORD_DIGEST}</em>
-<a name="207" href="#207">207</a> <em class="jxr_javadoccomment">     * </em>
-<a name="208" href="#208">208</a> <em class="jxr_javadoccomment">     * @param doc the SOAP envelope as &lt;code&gt;Document&lt;/code&gt;</em>
-<a name="209" href="#209">209</a> <em class="jxr_javadoccomment">     */</em>
-<a name="210" href="#210">210</a>     <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/ws/security/message/token/UsernameToken.html">UsernameToken</a>(<strong class="jxr_keyword">boolean</strong> milliseconds, Document doc) {
-<a name="211" href="#211">211</a>         <strong class="jxr_keyword">this</strong>(milliseconds, doc, WSConstants.PASSWORD_DIGEST);
-<a name="212" href="#212">212</a>     }
-<a name="213" href="#213">213</a> 
-<a name="214" href="#214">214</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="215" href="#215">215</a> <em class="jxr_javadoccomment">     * Constructs a &lt;code&gt;UsernameToken&lt;/code&gt; object according to the defined</em>
-<a name="216" href="#216">216</a> <em class="jxr_javadoccomment">     * parameters.</em>
-<a name="217" href="#217">217</a> <em class="jxr_javadoccomment">     * </em>
-<a name="218" href="#218">218</a> <em class="jxr_javadoccomment">     * @param doc the SOAP envelope as &lt;code&gt;Document&lt;/code&gt;</em>
-<a name="219" href="#219">219</a> <em class="jxr_javadoccomment">     * @param pwType the required password encoding, either</em>
-<a name="220" href="#220">220</a> <em class="jxr_javadoccomment">     *               {@link WSConstants#PASSWORD_DIGEST} or</em>
-<a name="221" href="#221">221</a> <em class="jxr_javadoccomment">     *               {@link WSConstants#PASSWORD_TEXT} or </em>
-<a name="222" href="#222">222</a> <em class="jxr_javadoccomment">     *               {@link WSConstants#PW_NONE} &lt;code&gt;null&lt;/code&gt; if no</em>
-<a name="223" href="#223">223</a> <em class="jxr_javadoccomment">     *               password required</em>
-<a name="224" href="#224">224</a> <em class="jxr_javadoccomment">     */</em>
-<a name="225" href="#225">225</a>     <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/ws/security/message/token/UsernameToken.html">UsernameToken</a>(<strong class="jxr_keyword">boolean</strong> milliseconds, Document doc, String pwType) {
-<a name="226" href="#226">226</a>         element = 
-<a name="227" href="#227">227</a>             doc.createElementNS(WSConstants.WSSE_NS, <span class="jxr_string">"wsse:"</span> + WSConstants.USERNAME_TOKEN_LN);
-<a name="228" href="#228">228</a>         WSSecurityUtil.setNamespace(element, WSConstants.WSSE_NS, WSConstants.WSSE_PREFIX);
-<a name="229" href="#229">229</a> 
-<a name="230" href="#230">230</a>         elementUsername = 
-<a name="231" href="#231">231</a>             doc.createElementNS(WSConstants.WSSE_NS, <span class="jxr_string">"wsse:"</span> + WSConstants.USERNAME_LN);
-<a name="232" href="#232">232</a>         elementUsername.appendChild(doc.createTextNode(<span class="jxr_string">""</span>));
-<a name="233" href="#233">233</a>         element.appendChild(elementUsername);
-<a name="234" href="#234">234</a> 
-<a name="235" href="#235">235</a>         <strong class="jxr_keyword">if</strong> (pwType != <strong class="jxr_keyword">null</strong>) {
-<a name="236" href="#236">236</a>             elementPassword = 
-<a name="237" href="#237">237</a>                 doc.createElementNS(WSConstants.WSSE_NS, <span class="jxr_string">"wsse:"</span> + WSConstants.PASSWORD_LN);
-<a name="238" href="#238">238</a>             elementPassword.appendChild(doc.createTextNode(<span class="jxr_string">""</span>));
-<a name="239" href="#239">239</a>             element.appendChild(elementPassword);
-<a name="240" href="#240">240</a> 
-<a name="241" href="#241">241</a>             hashed = false;
-<a name="242" href="#242">242</a>             passwordType = pwType;
-<a name="243" href="#243">243</a>             <strong class="jxr_keyword">if</strong> (passwordType.equals(WSConstants.PASSWORD_DIGEST)) {
-<a name="244" href="#244">244</a>                 hashed = <strong class="jxr_keyword">true</strong>;
-<a name="245" href="#245">245</a>                 addNonce(doc);
-<a name="246" href="#246">246</a>                 addCreated(milliseconds, doc);
-<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>     <em class="jxr_javadoccomment">/**</em>
-<a name="252" href="#252">252</a> <em class="jxr_javadoccomment">     * Creates and adds a Nonce element to this UsernameToken</em>
-<a name="253" href="#253">253</a> <em class="jxr_javadoccomment">     */</em>
-<a name="254" href="#254">254</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> addNonce(Document doc) {
-<a name="255" href="#255">255</a>         <strong class="jxr_keyword">if</strong> (elementNonce != <strong class="jxr_keyword">null</strong>) {
-<a name="256" href="#256">256</a>             <strong class="jxr_keyword">return</strong>;
-<a name="257" href="#257">257</a>         }
-<a name="258" href="#258">258</a>         byte[] nonceValue = <strong class="jxr_keyword">new</strong> byte[16];
-<a name="259" href="#259">259</a>         random.nextBytes(nonceValue);
-<a name="260" href="#260">260</a>         elementNonce = doc.createElementNS(WSConstants.WSSE_NS, <span class="jxr_string">"wsse:"</span> + WSConstants.NONCE_LN);
-<a name="261" href="#261">261</a>         elementNonce.appendChild(doc.createTextNode(Base64.encode(nonceValue)));
-<a name="262" href="#262">262</a>         elementNonce.setAttributeNS(<strong class="jxr_keyword">null</strong>, <span class="jxr_string">"EncodingType"</span>, BASE64_ENCODING);
-<a name="263" href="#263">263</a>         element.appendChild(elementNonce);
-<a name="264" href="#264">264</a>     }
-<a name="265" href="#265">265</a> 
-<a name="266" href="#266">266</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="267" href="#267">267</a> <em class="jxr_javadoccomment">     * Creates and adds a Created element to this UsernameToken</em>
-<a name="268" href="#268">268</a> <em class="jxr_javadoccomment">     */</em>
-<a name="269" href="#269">269</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> addCreated(<strong class="jxr_keyword">boolean</strong> milliseconds, Document doc) {
-<a name="270" href="#270">270</a>         <strong class="jxr_keyword">if</strong> (elementCreated != <strong class="jxr_keyword">null</strong>) {
-<a name="271" href="#271">271</a>             <strong class="jxr_keyword">return</strong>;
-<a name="272" href="#272">272</a>         }
-<a name="273" href="#273">273</a>         DateFormat zulu = <strong class="jxr_keyword">null</strong>;
-<a name="274" href="#274">274</a>         <strong class="jxr_keyword">if</strong> (milliseconds) {
-<a name="275" href="#275">275</a>             zulu = <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/util/XmlSchemaDateFormat.html">XmlSchemaDateFormat</a>();
-<a name="276" href="#276">276</a>         } <strong class="jxr_keyword">else</strong> {
-<a name="277" href="#277">277</a>             zulu = <strong class="jxr_keyword">new</strong> SimpleDateFormat(<span class="jxr_string">"yyyy-MM-dd'T'HH:mm:ss'Z'"</span>);
-<a name="278" href="#278">278</a>             zulu.setTimeZone(TimeZone.getTimeZone(<span class="jxr_string">"UTC"</span>));
-<a name="279" href="#279">279</a>         }
-<a name="280" href="#280">280</a>         Calendar rightNow = Calendar.getInstance();
-<a name="281" href="#281">281</a>         elementCreated = 
-<a name="282" href="#282">282</a>             doc.createElementNS(
-<a name="283" href="#283">283</a>                 WSConstants.WSU_NS,WSConstants.WSU_PREFIX + <span class="jxr_string">":"</span> + WSConstants.CREATED_LN
-<a name="284" href="#284">284</a>             );
-<a name="285" href="#285">285</a>         WSSecurityUtil.setNamespace(element, WSConstants.WSU_NS, WSConstants.WSU_PREFIX);
-<a name="286" href="#286">286</a>         elementCreated.appendChild(doc.createTextNode(zulu.format(rightNow.getTime())));
-<a name="287" href="#287">287</a>         element.appendChild(elementCreated);
-<a name="288" href="#288">288</a>     }
-<a name="289" href="#289">289</a> 
-<a name="290" href="#290">290</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="291" href="#291">291</a> <em class="jxr_javadoccomment">     * Adds and optionally creates a Salt element to this UsernameToken.</em>
-<a name="292" href="#292">292</a> <em class="jxr_javadoccomment">     * </em>
-<a name="293" href="#293">293</a> <em class="jxr_javadoccomment">     * If the &lt;code&gt;saltValue&lt;/code&gt; is &lt;code&gt;null&lt;/code&gt; the the method</em>
-<a name="294" href="#294">294</a> <em class="jxr_javadoccomment">     * generates a new salt. Otherwise it uses the the given value.</em>
-<a name="295" href="#295">295</a> <em class="jxr_javadoccomment">     * </em>
-<a name="296" href="#296">296</a> <em class="jxr_javadoccomment">     * @param doc The Document for the UsernameToken</em>
-<a name="297" href="#297">297</a> <em class="jxr_javadoccomment">     * @param saltValue The salt to add, if null generate a new salt value</em>
-<a name="298" href="#298">298</a> <em class="jxr_javadoccomment">     * @param mac If &lt;code&gt;true&lt;/code&gt; then an optionally generated value is</em>
-<a name="299" href="#299">299</a> <em class="jxr_javadoccomment">     *            usable for a MAC</em>
-<a name="300" href="#300">300</a> <em class="jxr_javadoccomment">     * @return Returns the added salt</em>
-<a name="301" href="#301">301</a> <em class="jxr_javadoccomment">     */</em>
-<a name="302" href="#302">302</a>     <strong class="jxr_keyword">public</strong> byte[] addSalt(Document doc, byte[] saltValue, <strong class="jxr_keyword">boolean</strong> mac) {
-<a name="303" href="#303">303</a>         <strong class="jxr_keyword">if</strong> (saltValue == <strong class="jxr_keyword">null</strong>) {
-<a name="304" href="#304">304</a>             saltValue = generateSalt(mac);
-<a name="305" href="#305">305</a>         }
-<a name="306" href="#306">306</a>         elementSalt = 
-<a name="307" href="#307">307</a>             doc.createElementNS(
-<a name="308" href="#308">308</a>                 WSConstants.WSSE11_NS, WSConstants.WSSE11_PREFIX + <span class="jxr_string">":"</span> + WSConstants.SALT_LN
-<a name="309" href="#309">309</a>             );
-<a name="310" href="#310">310</a>         WSSecurityUtil.setNamespace(<strong class="jxr_keyword">this</strong>.element, WSConstants.WSSE11_NS, WSConstants.WSSE11_PREFIX);
-<a name="311" href="#311">311</a>         elementSalt.appendChild(doc.createTextNode(Base64.encode(saltValue)));
-<a name="312" href="#312">312</a>         element.appendChild(elementSalt);
-<a name="313" href="#313">313</a>         <strong class="jxr_keyword">return</strong> saltValue;
-<a name="314" href="#314">314</a>     }
-<a name="315" href="#315">315</a> 
-<a name="316" href="#316">316</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="317" href="#317">317</a> <em class="jxr_javadoccomment">     * Creates and adds a Iteration element to this UsernameToken</em>
-<a name="318" href="#318">318</a> <em class="jxr_javadoccomment">     */</em>
-<a name="319" href="#319">319</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> addIteration(Document doc, <strong class="jxr_keyword">int</strong> iteration) {
-<a name="320" href="#320">320</a>         String text = <span class="jxr_string">""</span> + iteration;
-<a name="321" href="#321">321</a>         elementIteration = 
-<a name="322" href="#322">322</a>             doc.createElementNS(
-<a name="323" href="#323">323</a>                 WSConstants.WSSE11_NS, WSConstants.WSSE11_PREFIX + <span class="jxr_string">":"</span> + WSConstants.ITERATION_LN
-<a name="324" href="#324">324</a>             );
-<a name="325" href="#325">325</a>         WSSecurityUtil.setNamespace(element, WSConstants.WSSE11_NS, WSConstants.WSSE11_PREFIX);
-<a name="326" href="#326">326</a>         <strong class="jxr_keyword">this</strong>.elementIteration.appendChild(doc.createTextNode(text));
-<a name="327" href="#327">327</a>         element.appendChild(elementIteration);
-<a name="328" href="#328">328</a>     }
-<a name="329" href="#329">329</a> 
-<a name="330" href="#330">330</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="331" href="#331">331</a> <em class="jxr_javadoccomment">     * Get the user name.</em>
-<a name="332" href="#332">332</a> <em class="jxr_javadoccomment">     * </em>
-<a name="333" href="#333">333</a> <em class="jxr_javadoccomment">     * @return the data from the user name element.</em>
-<a name="334" href="#334">334</a> <em class="jxr_javadoccomment">     */</em>
-<a name="335" href="#335">335</a>     <strong class="jxr_keyword">public</strong> String getName() {
-<a name="336" href="#336">336</a>         <strong class="jxr_keyword">return</strong> nodeString(elementUsername);
-<a name="337" href="#337">337</a>     }
-<a name="338" href="#338">338</a> 
-<a name="339" href="#339">339</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="340" href="#340">340</a> <em class="jxr_javadoccomment">     * Set the user name.</em>
-<a name="341" href="#341">341</a> <em class="jxr_javadoccomment">     * </em>
-<a name="342" href="#342">342</a> <em class="jxr_javadoccomment">     * @param name sets a text node containing the use name into the user name</em>
-<a name="343" href="#343">343</a> <em class="jxr_javadoccomment">     *             element.</em>
-<a name="344" href="#344">344</a> <em class="jxr_javadoccomment">     */</em>
-<a name="345" href="#345">345</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setName(String name) {
-<a name="346" href="#346">346</a>         Text node = getFirstNode(elementUsername);
-<a name="347" href="#347">347</a>         node.setData(name);
-<a name="348" href="#348">348</a>     }
-<a name="349" href="#349">349</a> 
-<a name="350" href="#350">350</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="351" href="#351">351</a> <em class="jxr_javadoccomment">     * Get the nonce.</em>
-<a name="352" href="#352">352</a> <em class="jxr_javadoccomment">     * </em>
-<a name="353" href="#353">353</a> <em class="jxr_javadoccomment">     * @return the data from the nonce element.</em>
-<a name="354" href="#354">354</a> <em class="jxr_javadoccomment">     */</em>
-<a name="355" href="#355">355</a>     <strong class="jxr_keyword">public</strong> String getNonce() {
-<a name="356" href="#356">356</a>         <strong class="jxr_keyword">return</strong> nodeString(elementNonce);
-<a name="357" href="#357">357</a>     }
-<a name="358" href="#358">358</a> 
-<a name="359" href="#359">359</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="360" href="#360">360</a> <em class="jxr_javadoccomment">     * Get the created timestamp.</em>
-<a name="361" href="#361">361</a> <em class="jxr_javadoccomment">     * </em>
-<a name="362" href="#362">362</a> <em class="jxr_javadoccomment">     * @return the data from the created time element.</em>
-<a name="363" href="#363">363</a> <em class="jxr_javadoccomment">     */</em>
-<a name="364" href="#364">364</a>     <strong class="jxr_keyword">public</strong> String getCreated() {
-<a name="365" href="#365">365</a>         <strong class="jxr_keyword">return</strong> nodeString(elementCreated);
-<a name="366" href="#366">366</a>     }
-<a name="367" href="#367">367</a> 
-<a name="368" href="#368">368</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="369" href="#369">369</a> <em class="jxr_javadoccomment">     * Gets the password string. This is the password as it is in the password</em>
-<a name="370" href="#370">370</a> <em class="jxr_javadoccomment">     * element of a username token. Thus it can be either plain text or the</em>
-<a name="371" href="#371">371</a> <em class="jxr_javadoccomment">     * password digest value.</em>
-<a name="372" href="#372">372</a> <em class="jxr_javadoccomment">     * </em>
-<a name="373" href="#373">373</a> <em class="jxr_javadoccomment">     * @return the password string or &lt;code&gt;null&lt;/code&gt; if no such node exists.</em>
-<a name="374" href="#374">374</a> <em class="jxr_javadoccomment">     */</em>
-<a name="375" href="#375">375</a>     <strong class="jxr_keyword">public</strong> String getPassword() {
-<a name="376" href="#376">376</a>         String password = nodeString(elementPassword);
-<a name="377" href="#377">377</a>         <em class="jxr_comment">// See WSS-219</em>
-<a name="378" href="#378">378</a>         <strong class="jxr_keyword">if</strong> (password == <strong class="jxr_keyword">null</strong> &amp;&amp; elementPassword != <strong class="jxr_keyword">null</strong>) {
-<a name="379" href="#379">379</a>             <strong class="jxr_keyword">return</strong> <span class="jxr_string">""</span>;
-<a name="380" href="#380">380</a>         }
-<a name="381" href="#381">381</a>         <strong class="jxr_keyword">return</strong> password;
-<a name="382" href="#382">382</a>     }
-<a name="383" href="#383">383</a> 
-<a name="384" href="#384">384</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="385" href="#385">385</a> <em class="jxr_javadoccomment">     * Get the Salt value of this UsernameToken.</em>
-<a name="386" href="#386">386</a> <em class="jxr_javadoccomment">     * </em>
-<a name="387" href="#387">387</a> <em class="jxr_javadoccomment">     * @return Returns the binary Salt value or &lt;code&gt;null&lt;/code&gt; if no Salt</em>
-<a name="388" href="#388">388</a> <em class="jxr_javadoccomment">     *         value is available in the username token.</em>
-<a name="389" href="#389">389</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="390" href="#390">390</a> <em class="jxr_javadoccomment">     */</em>
-<a name="391" href="#391">391</a>     <strong class="jxr_keyword">public</strong> byte[] getSalt() <strong class="jxr_keyword">throws</strong> WSSecurityException {
-<a name="392" href="#392">392</a>         String salt = nodeString(elementSalt);
-<a name="393" href="#393">393</a>         <strong class="jxr_keyword">if</strong> (salt != <strong class="jxr_keyword">null</strong>) {
-<a name="394" href="#394">394</a>             <strong class="jxr_keyword">return</strong> Base64.decode(nodeString(elementSalt));
-<a name="395" href="#395">395</a>         }
-<a name="396" href="#396">396</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
-<a name="397" href="#397">397</a>     }
-<a name="398" href="#398">398</a> 
-<a name="399" href="#399">399</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="400" href="#400">400</a> <em class="jxr_javadoccomment">     * Get the Iteration value of this UsernameToken.</em>
-<a name="401" href="#401">401</a> <em class="jxr_javadoccomment">     * </em>
-<a name="402" href="#402">402</a> <em class="jxr_javadoccomment">     * @return Returns the Iteration value. If no Iteration was specified in the</em>
-<a name="403" href="#403">403</a> <em class="jxr_javadoccomment">     *         username token the default value according to the specification</em>
-<a name="404" href="#404">404</a> <em class="jxr_javadoccomment">     *         is returned.</em>
-<a name="405" href="#405">405</a> <em class="jxr_javadoccomment">     */</em>
-<a name="406" href="#406">406</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">int</strong> getIteration() {
-<a name="407" href="#407">407</a>         String iter = nodeString(elementIteration);
-<a name="408" href="#408">408</a>         <strong class="jxr_keyword">if</strong> (iter != <strong class="jxr_keyword">null</strong>) {
-<a name="409" href="#409">409</a>             <strong class="jxr_keyword">return</strong> Integer.parseInt(iter);
-<a name="410" href="#410">410</a>         }
-<a name="411" href="#411">411</a>         <strong class="jxr_keyword">return</strong> DEFAULT_ITERATION;
-<a name="412" href="#412">412</a>     }
-<a name="413" href="#413">413</a> 
-<a name="414" href="#414">414</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="415" href="#415">415</a> <em class="jxr_javadoccomment">     * Get the hashed indicator. If the indicator is &lt;code&gt;true&gt; the password of the</em>
-<a name="416" href="#416">416</a> <em class="jxr_javadoccomment">     * &lt;code&gt;UsernameToken&lt;/code&gt; was encoded using {@link WSConstants#PASSWORD_DIGEST}</em>
-<a name="417" href="#417">417</a> <em class="jxr_javadoccomment">     *</em>
-<a name="418" href="#418">418</a> <em class="jxr_javadoccomment">     * @return the hashed indicator.</em>
-<a name="419" href="#419">419</a> <em class="jxr_javadoccomment">     */</em>
-<a name="420" href="#420">420</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">boolean</strong> isHashed() {
-<a name="421" href="#421">421</a>         <strong class="jxr_keyword">return</strong> hashed;
-<a name="422" href="#422">422</a>     }
-<a name="423" href="#423">423</a> 
-<a name="424" href="#424">424</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="425" href="#425">425</a> <em class="jxr_javadoccomment">     * @return Returns the passwordType.</em>
-<a name="426" href="#426">426</a> <em class="jxr_javadoccomment">     */</em>
-<a name="427" href="#427">427</a>     <strong class="jxr_keyword">public</strong> String getPasswordType() {
-<a name="428" href="#428">428</a>         <strong class="jxr_keyword">return</strong> passwordType;
-<a name="429" href="#429">429</a>     }
-<a name="430" href="#430">430</a> 
-<a name="431" href="#431">431</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="432" href="#432">432</a> <em class="jxr_javadoccomment">     * Sets the password string. This function sets the password in the</em>
-<a name="433" href="#433">433</a> <em class="jxr_javadoccomment">     * &lt;code&gt;UsernameToken&lt;/code&gt; either as plain text or encodes the password</em>
-<a name="434" href="#434">434</a> <em class="jxr_javadoccomment">     * according to the WS Security specifications, UsernameToken profile, into</em>
-<a name="435" href="#435">435</a> <em class="jxr_javadoccomment">     * a password digest.</em>
-<a name="436" href="#436">436</a> <em class="jxr_javadoccomment">     * </em>
-<a name="437" href="#437">437</a> <em class="jxr_javadoccomment">     * @param pwd the password to use</em>
-<a name="438" href="#438">438</a> <em class="jxr_javadoccomment">     */</em>
-<a name="439" href="#439">439</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setPassword(String pwd) {
-<a name="440" href="#440">440</a>         <strong class="jxr_keyword">if</strong> (pwd == <strong class="jxr_keyword">null</strong>) {
-<a name="441" href="#441">441</a>             <strong class="jxr_keyword">if</strong> (passwordType != <strong class="jxr_keyword">null</strong>) {
-<a name="442" href="#442">442</a>                 <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalArgumentException(<span class="jxr_string">"pwd == null but a password is needed"</span>);
-<a name="443" href="#443">443</a>             } <strong class="jxr_keyword">else</strong> {
-<a name="444" href="#444">444</a>                 <em class="jxr_comment">// Ignore setting the password.</em>
-<a name="445" href="#445">445</a>                 <strong class="jxr_keyword">return</strong>;
-<a name="446" href="#446">446</a>             }
-<a name="447" href="#447">447</a>         }
-<a name="448" href="#448">448</a>         
-<a name="449" href="#449">449</a>         rawPassword = pwd;             <em class="jxr_comment">// enhancement by Alberto coletti</em>
-<a name="450" href="#450">450</a>         Text node = getFirstNode(elementPassword);
-<a name="451" href="#451">451</a>         <strong class="jxr_keyword">try</strong> {
-<a name="452" href="#452">452</a>             <strong class="jxr_keyword">if</strong> (!hashed) {
-<a name="453" href="#453">453</a>                 node.setData(pwd);
-<a name="454" href="#454">454</a>                 elementPassword.setAttributeNS(<strong class="jxr_keyword">null</strong>, <span class="jxr_string">"Type"</span>, WSConstants.PASSWORD_TEXT);
-<a name="455" href="#455">455</a>             } <strong class="jxr_keyword">else</strong> {
-<a name="456" href="#456">456</a>                 node.setData(doPasswordDigest(getNonce(), getCreated(), pwd));
-<a name="457" href="#457">457</a>                 elementPassword.setAttributeNS(<strong class="jxr_keyword">null</strong>, <span class="jxr_string">"Type"</span>, WSConstants.PASSWORD_DIGEST);
-<a name="458" href="#458">458</a>             }
-<a name="459" href="#459">459</a>         } <strong class="jxr_keyword">catch</strong> (Exception e) {
-<a name="460" href="#460">460</a>             <strong class="jxr_keyword">if</strong> (DO_DEBUG) {
-<a name="461" href="#461">461</a>                 LOG.debug(e.getMessage(), e);
-<a name="462" href="#462">462</a>             }
-<a name="463" href="#463">463</a>         }
-<a name="464" href="#464">464</a>     }
-<a name="465" href="#465">465</a> 
-<a name="466" href="#466">466</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="467" href="#467">467</a> <em class="jxr_javadoccomment">     * Set the raw (plain text) password used to compute secret key.</em>
-<a name="468" href="#468">468</a> <em class="jxr_javadoccomment">     * </em>
-<a name="469" href="#469">469</a> <em class="jxr_javadoccomment">     * @param newRawPassword the raw password to set</em>
-<a name="470" href="#470">470</a> <em class="jxr_javadoccomment">     */</em>
-<a name="471" href="#471">471</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setRawPassword(String newRawPassword) {
-<a name="472" href="#472">472</a>         rawPassword = newRawPassword;
-<a name="473" href="#473">473</a>     }
-<a name="474" href="#474">474</a>     
-<a name="475" href="#475">475</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="476" href="#476">476</a> <em class="jxr_javadoccomment">     * Get the raw (plain text) password used to compute secret key.</em>
-<a name="477" href="#477">477</a> <em class="jxr_javadoccomment">     */</em>
-<a name="478" href="#478">478</a>     <strong class="jxr_keyword">public</strong> String getRawPassword() {
-<a name="479" href="#479">479</a>         <strong class="jxr_keyword">return</strong> rawPassword;
-<a name="480" href="#480">480</a>     }
-<a name="481" href="#481">481</a>     
-<a name="482" href="#482">482</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> String doPasswordDigest(String nonce, String created, String password) {
-<a name="483" href="#483">483</a>         String passwdDigest = <strong class="jxr_keyword">null</strong>;
-<a name="484" href="#484">484</a>         <strong class="jxr_keyword">try</strong> {
-<a name="485" href="#485">485</a>             byte[] b1 = nonce != <strong class="jxr_keyword">null</strong> ? Base64.decode(nonce) : <strong class="jxr_keyword">new</strong> byte[0];
-<a name="486" href="#486">486</a>             byte[] b2 = created != <strong class="jxr_keyword">null</strong> ? created.getBytes(<span class="jxr_string">"UTF-8"</span>) : <strong class="jxr_keyword">new</strong> byte[0];
-<a name="487" href="#487">487</a>             byte[] b3 = password.getBytes(<span class="jxr_string">"UTF-8"</span>);
-<a name="488" href="#488">488</a>             byte[] b4 = <strong class="jxr_keyword">new</strong> byte[b1.length + b2.length + b3.length];
-<a name="489" href="#489">489</a>             <strong class="jxr_keyword">int</strong> offset = 0;
-<a name="490" href="#490">490</a>             System.arraycopy(b1, 0, b4, offset, b1.length);
-<a name="491" href="#491">491</a>             offset += b1.length;
-<a name="492" href="#492">492</a>             
-<a name="493" href="#493">493</a>             System.arraycopy(b2, 0, b4, offset, b2.length);
-<a name="494" href="#494">494</a>             offset += b2.length;
-<a name="495" href="#495">495</a> 
-<a name="496" href="#496">496</a>             System.arraycopy(b3, 0, b4, offset, b3.length);
-<a name="497" href="#497">497</a>             
-<a name="498" href="#498">498</a>             MessageDigest sha = MessageDigest.getInstance(<span class="jxr_string">"SHA-1"</span>);
-<a name="499" href="#499">499</a>             sha.reset();
-<a name="500" href="#500">500</a>             sha.update(b4);
-<a name="501" href="#501">501</a>             passwdDigest = Base64.encode(sha.digest());
-<a name="502" href="#502">502</a>         } <strong class="jxr_keyword">catch</strong> (Exception e) {
-<a name="503" href="#503">503</a>             <strong class="jxr_keyword">if</strong> (DO_DEBUG) {
-<a name="504" href="#504">504</a>                 LOG.debug(e.getMessage(), e);
-<a name="505" href="#505">505</a>             }
-<a name="506" href="#506">506</a>         }
-<a name="507" href="#507">507</a>         <strong class="jxr_keyword">return</strong> passwdDigest;
-<a name="508" href="#508">508</a>     }
-<a name="509" href="#509">509</a> 
-<a name="510" href="#510">510</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="511" href="#511">511</a> <em class="jxr_javadoccomment">     * Returns the first text node of an element.</em>
-<a name="512" href="#512">512</a> <em class="jxr_javadoccomment">     * </em>
-<a name="513" href="#513">513</a> <em class="jxr_javadoccomment">     * @param e the element to get the node from</em>
-<a name="514" href="#514">514</a> <em class="jxr_javadoccomment">     * @return the first text node or &lt;code&gt;null&lt;/code&gt; if node is null or is</em>
-<a name="515" href="#515">515</a> <em class="jxr_javadoccomment">     *         not a text node</em>
-<a name="516" href="#516">516</a> <em class="jxr_javadoccomment">     */</em>
-<a name="517" href="#517">517</a>     <strong class="jxr_keyword">private</strong> Text getFirstNode(Element e) {
-<a name="518" href="#518">518</a>         Node node = e.getFirstChild();
-<a name="519" href="#519">519</a>         <strong class="jxr_keyword">return</strong> ((node != <strong class="jxr_keyword">null</strong>) &amp;&amp; node instanceof Text) ? (Text) node : <strong class="jxr_keyword">null</strong>;
-<a name="520" href="#520">520</a>     }
-<a name="521" href="#521">521</a> 
-<a name="522" href="#522">522</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="523" href="#523">523</a> <em class="jxr_javadoccomment">     * Returns the data of an element as String or null if either the the element</em>
-<a name="524" href="#524">524</a> <em class="jxr_javadoccomment">     * does not contain a Text node or the node is empty.</em>
-<a name="525" href="#525">525</a> <em class="jxr_javadoccomment">     * </em>
-<a name="526" href="#526">526</a> <em class="jxr_javadoccomment">     * @param e DOM element</em>
-<a name="527" href="#527">527</a> <em class="jxr_javadoccomment">     * @return Element text node data as String</em>
-<a name="528" href="#528">528</a> <em class="jxr_javadoccomment">     */</em>
-<a name="529" href="#529">529</a>     <strong class="jxr_keyword">private</strong> String nodeString(Element e) {
-<a name="530" href="#530">530</a>         <strong class="jxr_keyword">if</strong> (e != <strong class="jxr_keyword">null</strong>) {
-<a name="531" href="#531">531</a>             Text node = getFirstNode(e);
-<a name="532" href="#532">532</a>             <strong class="jxr_keyword">if</strong> (node != <strong class="jxr_keyword">null</strong>) {
-<a name="533" href="#533">533</a>                 <strong class="jxr_keyword">return</strong> node.getData();
-<a name="534" href="#534">534</a>             }
-<a name="535" href="#535">535</a>         }
-<a name="536" href="#536">536</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
-<a name="537" href="#537">537</a>     }
-<a name="538" href="#538">538</a> 
-<a name="539" href="#539">539</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="540" href="#540">540</a> <em class="jxr_javadoccomment">     * Returns the dom element of this &lt;code&gt;UsernameToken&lt;/code&gt; object.</em>
-<a name="541" href="#541">541</a> <em class="jxr_javadoccomment">     * </em>
-<a name="542" href="#542">542</a> <em class="jxr_javadoccomment">     * @return the &lt;code&gt;wsse:UsernameToken&lt;/code&gt; element</em>
-<a name="543" href="#543">543</a> <em class="jxr_javadoccomment">     */</em>
-<a name="544" href="#544">544</a>     <strong class="jxr_keyword">public</strong> Element getElement() {
-<a name="545" href="#545">545</a>         <strong class="jxr_keyword">return</strong> element;
-<a name="546" href="#546">546</a>     }
-<a name="547" href="#547">547</a> 
-<a name="548" href="#548">548</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="549" href="#549">549</a> <em class="jxr_javadoccomment">     * Returns the string representation of the token.</em>
-<a name="550" href="#550">550</a> <em class="jxr_javadoccomment">     * </em>
-<a name="551" href="#551">551</a> <em class="jxr_javadoccomment">     * @return a XML string representation</em>
-<a name="552" href="#552">552</a> <em class="jxr_javadoccomment">     */</em>
-<a name="553" href="#553">553</a>     <strong class="jxr_keyword">public</strong> String toString() {
-<a name="554" href="#554">554</a>         <strong class="jxr_keyword">return</strong> DOM2Writer.nodeToString((Node) <strong class="jxr_keyword">this</strong>.element);
-<a name="555" href="#555">555</a>     }
-<a name="556" href="#556">556</a> 
-<a name="557" href="#557">557</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="558" href="#558">558</a> <em class="jxr_javadoccomment">     * Gets the id.</em>
-<a name="559" href="#559">559</a> <em class="jxr_javadoccomment">     * </em>
-<a name="560" href="#560">560</a> <em class="jxr_javadoccomment">     * @return the value of the &lt;code&gt;wsu:Id&lt;/code&gt; attribute of this username</em>
-<a name="561" href="#561">561</a> <em class="jxr_javadoccomment">     *         token</em>
-<a name="562" href="#562">562</a> <em class="jxr_javadoccomment">     */</em>
-<a name="563" href="#563">563</a>     <strong class="jxr_keyword">public</strong> String getID() {
-<a name="564" href="#564">564</a>         <strong class="jxr_keyword">return</strong> element.getAttributeNS(WSConstants.WSU_NS, <span class="jxr_string">"Id"</span>);
-<a name="565" href="#565">565</a>     }
-<a name="566" href="#566">566</a> 
-<a name="567" href="#567">567</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="568" href="#568">568</a> <em class="jxr_javadoccomment">     * Set the id of this username token.</em>
-<a name="569" href="#569">569</a> <em class="jxr_javadoccomment">     * </em>
-<a name="570" href="#570">570</a> <em class="jxr_javadoccomment">     * @param id</em>
-<a name="571" href="#571">571</a> <em class="jxr_javadoccomment">     *            the value for the &lt;code&gt;wsu:Id&lt;/code&gt; attribute of this</em>
-<a name="572" href="#572">572</a> <em class="jxr_javadoccomment">     *            username token</em>
-<a name="573" href="#573">573</a> <em class="jxr_javadoccomment">     */</em>
-<a name="574" href="#574">574</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setID(String id) {
-<a name="575" href="#575">575</a>         String prefix = 
-<a name="576" href="#576">576</a>             WSSecurityUtil.setNamespace(element, WSConstants.WSU_NS, WSConstants.WSU_PREFIX);
-<a name="577" href="#577">577</a>         element.setAttributeNS(WSConstants.WSU_NS, prefix + <span class="jxr_string">":Id"</span>, id);
-<a name="578" href="#578">578</a>     }
-<a name="579" href="#579">579</a> 
-<a name="580" href="#580">580</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="581" href="#581">581</a> <em class="jxr_javadoccomment">     * Gets the secret key as per WS-Trust spec. This method uses default setting</em>
-<a name="582" href="#582">582</a> <em class="jxr_javadoccomment">     * to generate the secret key. These default values are suitable for .NET</em>
-<a name="583" href="#583">583</a> <em class="jxr_javadoccomment">     * WSE.</em>
-<a name="584" href="#584">584</a> <em class="jxr_javadoccomment">     * </em>
-<a name="585" href="#585">585</a> <em class="jxr_javadoccomment">     * @return a secret key constructed from information contained in this</em>
-<a name="586" href="#586">586</a> <em class="jxr_javadoccomment">     *         username token</em>
-<a name="587" href="#587">587</a> <em class="jxr_javadoccomment">     */</em>
-<a name="588" href="#588">588</a>     <strong class="jxr_keyword">public</strong> byte[] getSecretKey() {
-<a name="589" href="#589">589</a>         <strong class="jxr_keyword">return</strong> getSecretKey(WSConstants.WSE_DERIVED_KEY_LEN, WSConstants.LABEL_FOR_DERIVED_KEY);
-<a name="590" href="#590">590</a>     }
-<a name="591" href="#591">591</a>     
-<a name="592" href="#592">592</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="593" href="#593">593</a> <em class="jxr_javadoccomment">     * Gets the secret key as per WS-Trust spec. This method uses default setting</em>
-<a name="594" href="#594">594</a> <em class="jxr_javadoccomment">     * to generate the secret key. These default values are suitable for .NET</em>
-<a name="595" href="#595">595</a> <em class="jxr_javadoccomment">     * WSE.</em>
-<a name="596" href="#596">596</a> <em class="jxr_javadoccomment">     * </em>
-<a name="597" href="#597">597</a> <em class="jxr_javadoccomment">     * @return a secret key constructed from information contained in this</em>
-<a name="598" href="#598">598</a> <em class="jxr_javadoccomment">     *         username token</em>
-<a name="599" href="#599">599</a> <em class="jxr_javadoccomment">     */</em>
-<a name="600" href="#600">600</a>     <strong class="jxr_keyword">public</strong> byte[] getSecretKey(<strong class="jxr_keyword">int</strong> keylen) {
-<a name="601" href="#601">601</a>         <strong class="jxr_keyword">return</strong> getSecretKey(keylen, WSConstants.LABEL_FOR_DERIVED_KEY);
-<a name="602" href="#602">602</a>     }
-<a name="603" href="#603">603</a> 
-<a name="604" href="#604">604</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="605" href="#605">605</a> <em class="jxr_javadoccomment">     * Gets the secret key as per WS-Trust spec.</em>
-<a name="606" href="#606">606</a> <em class="jxr_javadoccomment">     * </em>
-<a name="607" href="#607">607</a> <em class="jxr_javadoccomment">     * @param keylen How many bytes to generate for the key</em>
-<a name="608" href="#608">608</a> <em class="jxr_javadoccomment">     * @param labelString the label used to generate the seed</em>
-<a name="609" href="#609">609</a> <em class="jxr_javadoccomment">     * @return a secret key constructed from information contained in this</em>
-<a name="610" href="#610">610</a> <em class="jxr_javadoccomment">     *         username token</em>
-<a name="611" href="#611">611</a> <em class="jxr_javadoccomment">     */</em>
-<a name="612" href="#612">612</a>     <strong class="jxr_keyword">public</strong> byte[] getSecretKey(<strong class="jxr_keyword">int</strong> keylen, String labelString) {
-<a name="613" href="#613">613</a>         byte[] key = <strong class="jxr_keyword">null</strong>;
-<a name="614" href="#614">614</a>         <strong class="jxr_keyword">try</strong> {
-<a name="615" href="#615">615</a>             Mac mac = Mac.getInstance(<span class="jxr_string">"HMACSHA1"</span>);
-<a name="616" href="#616">616</a>             byte[] password = rawPassword.getBytes(<span class="jxr_string">"UTF-8"</span>); <em class="jxr_comment">// enhancement by Alberto Coletti</em>
-<a name="617" href="#617">617</a>             byte[] label = labelString.getBytes(<span class="jxr_string">"UTF-8"</span>);
-<a name="618" href="#618">618</a>             byte[] nonce = Base64.decode(getNonce());
-<a name="619" href="#619">619</a>             byte[] created = getCreated().getBytes(<span class="jxr_string">"UTF-8"</span>);
-<a name="620" href="#620">620</a>             byte[] seed = <strong class="jxr_keyword">new</strong> byte[label.length + nonce.length + created.length];
-<a name="621" href="#621">621</a> 
-<a name="622" href="#622">622</a>             <strong class="jxr_keyword">int</strong> offset = 0;
-<a name="623" href="#623">623</a>             System.arraycopy(label, 0, seed, offset, label.length);
-<a name="624" href="#624">624</a>             offset += label.length;
-<a name="625" href="#625">625</a>             
-<a name="626" href="#626">626</a>             System.arraycopy(nonce, 0, seed, offset, nonce.length);
-<a name="627" href="#627">627</a>             offset += nonce.length;
-<a name="628" href="#628">628</a> 
-<a name="629" href="#629">629</a>             System.arraycopy(created, 0, seed, offset, created.length);
-<a name="630" href="#630">630</a>             
-<a name="631" href="#631">631</a>             key = P_hash(password, seed, mac, keylen);
-<a name="632" href="#632">632</a> 
-<a name="633" href="#633">633</a>             <strong class="jxr_keyword">if</strong> (LOG.isDebugEnabled()) {
-<a name="634" href="#634">634</a>                 LOG.debug(<span class="jxr_string">"password   :"</span> + Base64.encode(password));
-<a name="635" href="#635">635</a>                 LOG.debug(<span class="jxr_string">"label      :"</span> + Base64.encode(label));
-<a name="636" href="#636">636</a>                 LOG.debug(<span class="jxr_string">"nonce      :"</span> + Base64.encode(nonce));
-<a name="637" href="#637">637</a>                 LOG.debug(<span class="jxr_string">"created    :"</span> + Base64.encode(created));
-<a name="638" href="#638">638</a>                 LOG.debug(<span class="jxr_string">"seed       :"</span> + Base64.encode(seed));
-<a name="639" href="#639">639</a>                 LOG.debug(<span class="jxr_string">"Key        :"</span> + Base64.encode(key));
-<a name="640" href="#640">640</a>             }
-<a name="641" href="#641">641</a>         } <strong class="jxr_keyword">catch</strong> (Exception e) {
-<a name="642" href="#642">642</a>             <strong class="jxr_keyword">if</strong> (DO_DEBUG) {
-<a name="643" href="#643">643</a>                 LOG.debug(e.getMessage(), e);
-<a name="644" href="#644">644</a>             }
-<a name="645" href="#645">645</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
-<a name="646" href="#646">646</a>         }
-<a name="647" href="#647">647</a>         <strong class="jxr_keyword">return</strong> key;
-<a name="648" href="#648">648</a>     }
-<a name="649" href="#649">649</a>     
-<a name="650" href="#650">650</a>   
-<a name="651" href="#651">651</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="652" href="#652">652</a> <em class="jxr_javadoccomment">     * This static method generates a derived key as defined in WSS Username</em>
-<a name="653" href="#653">653</a> <em class="jxr_javadoccomment">     * Token Profile.</em>
-<a name="654" href="#654">654</a> <em class="jxr_javadoccomment">     * </em>
-<a name="655" href="#655">655</a> <em class="jxr_javadoccomment">     * @param password The password to include in the key generation</em>
-<a name="656" href="#656">656</a> <em class="jxr_javadoccomment">     * @param salt The Salt value</em>
-<a name="657" href="#657">657</a> <em class="jxr_javadoccomment">     * @param iteration The Iteration value. If zero (0) is given the method uses the</em>
-<a name="658" href="#658">658</a> <em class="jxr_javadoccomment">     *                  default value</em>
-<a name="659" href="#659">659</a> <em class="jxr_javadoccomment">     * @return Returns the derived key a byte array</em>
-<a name="660" href="#660">660</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="661" href="#661">661</a> <em class="jxr_javadoccomment">     */</em>
-<a name="662" href="#662">662</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> byte[] generateDerivedKey(
-<a name="663" href="#663">663</a>         String password, 
-<a name="664" href="#664">664</a>         byte[] salt, 
-<a name="665" href="#665">665</a>         <strong class="jxr_keyword">int</strong> iteration
-<a name="666" href="#666">666</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="667" href="#667">667</a>         <strong class="jxr_keyword">if</strong> (iteration == 0) {
-<a name="668" href="#668">668</a>             iteration = DEFAULT_ITERATION;
-<a name="669" href="#669">669</a>         }
-<a name="670" href="#670">670</a>         byte[] pwBytes = <strong class="jxr_keyword">null</strong>;
-<a name="671" href="#671">671</a>         <strong class="jxr_keyword">try</strong> {
-<a name="672" href="#672">672</a>             pwBytes = password.getBytes(<span class="jxr_string">"UTF-8"</span>);
-<a name="673" href="#673">673</a>         } <strong class="jxr_keyword">catch</strong> (<strong class="jxr_keyword">final</strong> java.io.UnsupportedEncodingException e) {
-<a name="674" href="#674">674</a>             <strong class="jxr_keyword">if</strong> (DO_DEBUG) {
-<a name="675" href="#675">675</a>                 LOG.debug(e.getMessage(), e);
+<a name="76" href="#76">76</a>      <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">boolean</strong> passwordsAreEncoded = false;
+<a name="77" href="#77">77</a>      
+<a name="78" href="#78">78</a>      <strong class="jxr_keyword">static</strong> {
+<a name="79" href="#79">79</a>          <strong class="jxr_keyword">try</strong> {
+<a name="80" href="#80">80</a>              random = WSSecurityUtil.resolveSecureRandom();
+<a name="81" href="#81">81</a>          } <strong class="jxr_keyword">catch</strong> (NoSuchAlgorithmException e) {
+<a name="82" href="#82">82</a>              <strong class="jxr_keyword">if</strong> (DO_DEBUG) {
+<a name="83" href="#83">83</a>                  LOG.debug(e.getMessage(), e);
+<a name="84" href="#84">84</a>              }
+<a name="85" href="#85">85</a>          }
+<a name="86" href="#86">86</a>      }
+<a name="87" href="#87">87</a>      
+<a name="88" href="#88">88</a>      <em class="jxr_javadoccomment">/**</em>
+<a name="89" href="#89">89</a>  <em class="jxr_javadoccomment">     * Constructs a &lt;code&gt;UsernameToken&lt;/code&gt; object and parses the</em>
+<a name="90" href="#90">90</a>  <em class="jxr_javadoccomment">     * &lt;code&gt;wsse:UsernameToken&lt;/code&gt; element to initialize it.</em>
+<a name="91" href="#91">91</a>  <em class="jxr_javadoccomment">     * </em>
+<a name="92" href="#92">92</a>  <em class="jxr_javadoccomment">     * @param elem the &lt;code&gt;wsse:UsernameToken&lt;/code&gt; element that contains</em>
+<a name="93" href="#93">93</a>  <em class="jxr_javadoccomment">     *             the UsernameToken data</em>
+<a name="94" href="#94">94</a>  <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
+<a name="95" href="#95">95</a>  <em class="jxr_javadoccomment">     */</em>
+<a name="96" href="#96">96</a>      <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/ws/security/message/token/UsernameToken.html">UsernameToken</a>(Element elem) <strong class="jxr_keyword">throws</strong> WSSecurityException {
+<a name="97" href="#97">97</a>          <strong class="jxr_keyword">this</strong> (elem, false);
+<a name="98" href="#98">98</a>      }
+<a name="99" href="#99">99</a>  
+<a name="100" href="#100">100</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="101" href="#101">101</a> <em class="jxr_javadoccomment">     * Constructs a &lt;code&gt;UsernameToken&lt;/code&gt; object and parses the</em>
+<a name="102" href="#102">102</a> <em class="jxr_javadoccomment">     * &lt;code&gt;wsse:UsernameToken&lt;/code&gt; element to initialize it.</em>
+<a name="103" href="#103">103</a> <em class="jxr_javadoccomment">     * </em>
+<a name="104" href="#104">104</a> <em class="jxr_javadoccomment">     * @param elem the &lt;code&gt;wsse:UsernameToken&lt;/code&gt; element that contains</em>
+<a name="105" href="#105">105</a> <em class="jxr_javadoccomment">     *             the UsernameToken data</em>
+<a name="106" href="#106">106</a> <em class="jxr_javadoccomment">     * @param allowNamespaceQualifiedPasswordTypes whether to allow (wsse)</em>
+<a name="107" href="#107">107</a> <em class="jxr_javadoccomment">     *        namespace qualified password types or not (for interop with WCF)</em>
+<a name="108" href="#108">108</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
+<a name="109" href="#109">109</a> <em class="jxr_javadoccomment">     */</em>
+<a name="110" href="#110">110</a>     <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/ws/security/message/token/UsernameToken.html">UsernameToken</a>(
+<a name="111" href="#111">111</a>         Element elem, 
+<a name="112" href="#112">112</a>         <strong class="jxr_keyword">boolean</strong> allowNamespaceQualifiedPasswordTypes
+<a name="113" href="#113">113</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="114" href="#114">114</a>         element = elem;
+<a name="115" href="#115">115</a>         QName el = <strong class="jxr_keyword">new</strong> QName(element.getNamespaceURI(), element.getLocalName());
+<a name="116" href="#116">116</a>         <strong class="jxr_keyword">if</strong> (!el.equals(TOKEN)) {
+<a name="117" href="#117">117</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="118" href="#118">118</a>                 WSSecurityException.INVALID_SECURITY_TOKEN,
+<a name="119" href="#119">119</a>                 <span class="jxr_string">"badTokenType00"</span>, 
+<a name="120" href="#120">120</a>                 <strong class="jxr_keyword">new</strong> Object[] {el}
+<a name="121" href="#121">121</a>             );
+<a name="122" href="#122">122</a>         }
+<a name="123" href="#123">123</a>         elementUsername = 
+<a name="124" href="#124">124</a>             (Element) WSSecurityUtil.getDirectChild(
+<a name="125" href="#125">125</a>                 element, WSConstants.USERNAME_LN, WSConstants.WSSE_NS
+<a name="126" href="#126">126</a>             );
+<a name="127" href="#127">127</a>         elementPassword = 
+<a name="128" href="#128">128</a>             (Element) WSSecurityUtil.getDirectChild(
+<a name="129" href="#129">129</a>                 element, WSConstants.PASSWORD_LN, WSConstants.WSSE_NS
+<a name="130" href="#130">130</a>             );
+<a name="131" href="#131">131</a>         elementNonce = 
+<a name="132" href="#132">132</a>             (Element) WSSecurityUtil.getDirectChild(
+<a name="133" href="#133">133</a>                 element, WSConstants.NONCE_LN, WSConstants.WSSE_NS
+<a name="134" href="#134">134</a>             );
+<a name="135" href="#135">135</a>         elementCreated = 
+<a name="136" href="#136">136</a>             (Element) WSSecurityUtil.getDirectChild(
+<a name="137" href="#137">137</a>                 element, WSConstants.CREATED_LN, WSConstants.WSU_NS
+<a name="138" href="#138">138</a>             );
+<a name="139" href="#139">139</a>         elementSalt = 
+<a name="140" href="#140">140</a>             (Element) WSSecurityUtil.getDirectChild(
+<a name="141" href="#141">141</a>                 element, WSConstants.SALT_LN, WSConstants.WSSE11_NS
+<a name="142" href="#142">142</a>             );
+<a name="143" href="#143">143</a>         elementIteration = 
+<a name="144" href="#144">144</a>             (Element) WSSecurityUtil.getDirectChild(
+<a name="145" href="#145">145</a>                 element, WSConstants.ITERATION_LN, WSConstants.WSSE11_NS
+<a name="146" href="#146">146</a>             );
+<a name="147" href="#147">147</a>         <strong class="jxr_keyword">if</strong> (elementUsername == <strong class="jxr_keyword">null</strong>) {
+<a name="148" href="#148">148</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="149" href="#149">149</a>                 WSSecurityException.INVALID_SECURITY_TOKEN,
+<a name="150" href="#150">150</a>                 <span class="jxr_string">"badTokenType01"</span>, 
+<a name="151" href="#151">151</a>                 <strong class="jxr_keyword">new</strong> Object[] {el}
+<a name="152" href="#152">152</a>             );
+<a name="153" href="#153">153</a>         }
+<a name="154" href="#154">154</a>         hashed = false;
+<a name="155" href="#155">155</a>         <strong class="jxr_keyword">if</strong> (elementSalt != <strong class="jxr_keyword">null</strong>) {
+<a name="156" href="#156">156</a>             <em class="jxr_comment">//</em>
+<a name="157" href="#157">157</a>             <em class="jxr_comment">// If the UsernameToken is to be used for key derivation, the (1.1)</em>
+<a name="158" href="#158">158</a>             <em class="jxr_comment">// spec says that it cannot contain a password, and it must contain</em>
+<a name="159" href="#159">159</a>             <em class="jxr_comment">// an Iteration element</em>
+<a name="160" href="#160">160</a>             <em class="jxr_comment">//</em>
+<a name="161" href="#161">161</a>             <strong class="jxr_keyword">if</strong> (elementPassword != <strong class="jxr_keyword">null</strong> || elementIteration == <strong class="jxr_keyword">null</strong>) {
+<a name="162" href="#162">162</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="163" href="#163">163</a>                     WSSecurityException.INVALID_SECURITY_TOKEN,
+<a name="164" href="#164">164</a>                     <span class="jxr_string">"badTokenType01"</span>, 
+<a name="165" href="#165">165</a>                     <strong class="jxr_keyword">new</strong> Object[] {el}
+<a name="166" href="#166">166</a>                 );
+<a name="167" href="#167">167</a>             }
+<a name="168" href="#168">168</a>             <strong class="jxr_keyword">return</strong>;
+<a name="169" href="#169">169</a>         }
+<a name="170" href="#170">170</a>         <strong class="jxr_keyword">if</strong> (elementPassword != <strong class="jxr_keyword">null</strong>) {
+<a name="171" href="#171">171</a>             <strong class="jxr_keyword">if</strong> (elementPassword.hasAttribute(WSConstants.PASSWORD_TYPE_ATTR)) {
+<a name="172" href="#172">172</a>                 passwordType = elementPassword.getAttribute(WSConstants.PASSWORD_TYPE_ATTR);
+<a name="173" href="#173">173</a>             } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (elementPassword.hasAttributeNS(
+<a name="174" href="#174">174</a>                 WSConstants.WSSE_NS, WSConstants.PASSWORD_TYPE_ATTR)
+<a name="175" href="#175">175</a>             ) {
+<a name="176" href="#176">176</a>                 <strong class="jxr_keyword">if</strong> (allowNamespaceQualifiedPasswordTypes) {
+<a name="177" href="#177">177</a>                     passwordType = 
+<a name="178" href="#178">178</a>                         elementPassword.getAttributeNS(
+<a name="179" href="#179">179</a>                             WSConstants.WSSE_NS, WSConstants.PASSWORD_TYPE_ATTR
+<a name="180" href="#180">180</a>                         );
+<a name="181" href="#181">181</a>                 } <strong class="jxr_keyword">else</strong> {
+<a name="182" href="#182">182</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="183" href="#183">183</a>                         WSSecurityException.INVALID_SECURITY_TOKEN,
+<a name="184" href="#184">184</a>                         <span class="jxr_string">"badTokenType01"</span>, 
+<a name="185" href="#185">185</a>                         <strong class="jxr_keyword">new</strong> Object[] {el}
+<a name="186" href="#186">186</a>                     );
+<a name="187" href="#187">187</a>                 }
+<a name="188" href="#188">188</a>             }
+<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">if</strong> (passwordType != <strong class="jxr_keyword">null</strong>
+<a name="192" href="#192">192</a>             &amp;&amp; passwordType.equals(WSConstants.PASSWORD_DIGEST)) {
+<a name="193" href="#193">193</a>             hashed = <strong class="jxr_keyword">true</strong>;
+<a name="194" href="#194">194</a>             <strong class="jxr_keyword">if</strong> (elementNonce == <strong class="jxr_keyword">null</strong> || elementCreated == <strong class="jxr_keyword">null</strong>) {
+<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_TOKEN,
+<a name="197" href="#197">197</a>                     <span class="jxr_string">"badTokenType01"</span>, 
+<a name="198" href="#198">198</a>                     <strong class="jxr_keyword">new</strong> Object[] {el}
+<a name="199" href="#199">199</a>                 );
+<a name="200" href="#200">200</a>             }
+<a name="201" href="#201">201</a>         }
+<a name="202" href="#202">202</a>     }
+<a name="203" href="#203">203</a> 
+<a name="204" href="#204">204</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="205" href="#205">205</a> <em class="jxr_javadoccomment">     * Constructs a &lt;code&gt;UsernameToken&lt;/code&gt; object according to the defined</em>
+<a name="206" href="#206">206</a> <em class="jxr_javadoccomment">     * parameters. &lt;p/&gt; This constructs set the password encoding to</em>
+<a name="207" href="#207">207</a> <em class="jxr_javadoccomment">     * {@link WSConstants#PASSWORD_DIGEST}</em>
+<a name="208" href="#208">208</a> <em class="jxr_javadoccomment">     * </em>
+<a name="209" href="#209">209</a> <em class="jxr_javadoccomment">     * @param doc the SOAP envelope as &lt;code&gt;Document&lt;/code&gt;</em>
+<a name="210" href="#210">210</a> <em class="jxr_javadoccomment">     */</em>
+<a name="211" href="#211">211</a>     <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/ws/security/message/token/UsernameToken.html">UsernameToken</a>(<strong class="jxr_keyword">boolean</strong> milliseconds, Document doc) {
+<a name="212" href="#212">212</a>         <strong class="jxr_keyword">this</strong>(milliseconds, doc, WSConstants.PASSWORD_DIGEST);
+<a name="213" href="#213">213</a>     }
+<a name="214" href="#214">214</a> 
+<a name="215" href="#215">215</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="216" href="#216">216</a> <em class="jxr_javadoccomment">     * Constructs a &lt;code&gt;UsernameToken&lt;/code&gt; object according to the defined</em>
+<a name="217" href="#217">217</a> <em class="jxr_javadoccomment">     * parameters.</em>
+<a name="218" href="#218">218</a> <em class="jxr_javadoccomment">     * </em>
+<a name="219" href="#219">219</a> <em class="jxr_javadoccomment">     * @param doc the SOAP envelope as &lt;code&gt;Document&lt;/code&gt;</em>
+<a name="220" href="#220">220</a> <em class="jxr_javadoccomment">     * @param pwType the required password encoding, either</em>
+<a name="221" href="#221">221</a> <em class="jxr_javadoccomment">     *               {@link WSConstants#PASSWORD_DIGEST} or</em>
+<a name="222" href="#222">222</a> <em class="jxr_javadoccomment">     *               {@link WSConstants#PASSWORD_TEXT} or </em>
+<a name="223" href="#223">223</a> <em class="jxr_javadoccomment">     *               {@link WSConstants#PW_NONE} &lt;code&gt;null&lt;/code&gt; if no</em>
+<a name="224" href="#224">224</a> <em class="jxr_javadoccomment">     *               password required</em>
+<a name="225" href="#225">225</a> <em class="jxr_javadoccomment">     */</em>
+<a name="226" href="#226">226</a>     <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/ws/security/message/token/UsernameToken.html">UsernameToken</a>(<strong class="jxr_keyword">boolean</strong> milliseconds, Document doc, String pwType) {
+<a name="227" href="#227">227</a>         element = 
+<a name="228" href="#228">228</a>             doc.createElementNS(WSConstants.WSSE_NS, <span class="jxr_string">"wsse:"</span> + WSConstants.USERNAME_TOKEN_LN);
+<a name="229" href="#229">229</a>         WSSecurityUtil.setNamespace(element, WSConstants.WSSE_NS, WSConstants.WSSE_PREFIX);
+<a name="230" href="#230">230</a> 
+<a name="231" href="#231">231</a>         elementUsername = 
+<a name="232" href="#232">232</a>             doc.createElementNS(WSConstants.WSSE_NS, <span class="jxr_string">"wsse:"</span> + WSConstants.USERNAME_LN);
+<a name="233" href="#233">233</a>         elementUsername.appendChild(doc.createTextNode(<span class="jxr_string">""</span>));
+<a name="234" href="#234">234</a>         element.appendChild(elementUsername);
+<a name="235" href="#235">235</a> 
+<a name="236" href="#236">236</a>         <strong class="jxr_keyword">if</strong> (pwType != <strong class="jxr_keyword">null</strong>) {
+<a name="237" href="#237">237</a>             elementPassword = 
+<a name="238" href="#238">238</a>                 doc.createElementNS(WSConstants.WSSE_NS, <span class="jxr_string">"wsse:"</span> + WSConstants.PASSWORD_LN);
+<a name="239" href="#239">239</a>             elementPassword.appendChild(doc.createTextNode(<span class="jxr_string">""</span>));
+<a name="240" href="#240">240</a>             element.appendChild(elementPassword);
+<a name="241" href="#241">241</a> 
+<a name="242" href="#242">242</a>             hashed = false;
+<a name="243" href="#243">243</a>             passwordType = pwType;
+<a name="244" href="#244">244</a>             <strong class="jxr_keyword">if</strong> (passwordType.equals(WSConstants.PASSWORD_DIGEST)) {
+<a name="245" href="#245">245</a>                 hashed = <strong class="jxr_keyword">true</strong>;
+<a name="246" href="#246">246</a>                 addNonce(doc);
+<a name="247" href="#247">247</a>                 addCreated(milliseconds, doc);
+<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> 
+<a name="252" href="#252">252</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="253" href="#253">253</a> <em class="jxr_javadoccomment">     * Creates and adds a Nonce element to this UsernameToken</em>
+<a name="254" href="#254">254</a> <em class="jxr_javadoccomment">     */</em>
+<a name="255" href="#255">255</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> addNonce(Document doc) {
+<a name="256" href="#256">256</a>         <strong class="jxr_keyword">if</strong> (elementNonce != <strong class="jxr_keyword">null</strong>) {
+<a name="257" href="#257">257</a>             <strong class="jxr_keyword">return</strong>;
+<a name="258" href="#258">258</a>         }
+<a name="259" href="#259">259</a>         byte[] nonceValue = <strong class="jxr_keyword">new</strong> byte[16];
+<a name="260" href="#260">260</a>         random.nextBytes(nonceValue);
+<a name="261" href="#261">261</a>         elementNonce = doc.createElementNS(WSConstants.WSSE_NS, <span class="jxr_string">"wsse:"</span> + WSConstants.NONCE_LN);
+<a name="262" href="#262">262</a>         elementNonce.appendChild(doc.createTextNode(Base64.encode(nonceValue)));
+<a name="263" href="#263">263</a>         elementNonce.setAttributeNS(<strong class="jxr_keyword">null</strong>, <span class="jxr_string">"EncodingType"</span>, BASE64_ENCODING);
+<a name="264" href="#264">264</a>         element.appendChild(elementNonce);
+<a name="265" href="#265">265</a>     }
+<a name="266" href="#266">266</a> 
+<a name="267" href="#267">267</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="268" href="#268">268</a> <em class="jxr_javadoccomment">     * Creates and adds a Created element to this UsernameToken</em>
+<a name="269" href="#269">269</a> <em class="jxr_javadoccomment">     */</em>
+<a name="270" href="#270">270</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> addCreated(<strong class="jxr_keyword">boolean</strong> milliseconds, Document doc) {
+<a name="271" href="#271">271</a>         <strong class="jxr_keyword">if</strong> (elementCreated != <strong class="jxr_keyword">null</strong>) {
+<a name="272" href="#272">272</a>             <strong class="jxr_keyword">return</strong>;
+<a name="273" href="#273">273</a>         }
+<a name="274" href="#274">274</a>         DateFormat zulu = <strong class="jxr_keyword">null</strong>;
+<a name="275" href="#275">275</a>         <strong class="jxr_keyword">if</strong> (milliseconds) {
+<a name="276" href="#276">276</a>             zulu = <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/util/XmlSchemaDateFormat.html">XmlSchemaDateFormat</a>();
+<a name="277" href="#277">277</a>         } <strong class="jxr_keyword">else</strong> {
+<a name="278" href="#278">278</a>             zulu = <strong class="jxr_keyword">new</strong> SimpleDateFormat(<span class="jxr_string">"yyyy-MM-dd'T'HH:mm:ss'Z'"</span>);
+<a name="279" href="#279">279</a>             zulu.setTimeZone(TimeZone.getTimeZone(<span class="jxr_string">"UTC"</span>));
+<a name="280" href="#280">280</a>         }
+<a name="281" href="#281">281</a>         Calendar rightNow = Calendar.getInstance();
+<a name="282" href="#282">282</a>         elementCreated = 
+<a name="283" href="#283">283</a>             doc.createElementNS(
+<a name="284" href="#284">284</a>                 WSConstants.WSU_NS,WSConstants.WSU_PREFIX + <span class="jxr_string">":"</span> + WSConstants.CREATED_LN
+<a name="285" href="#285">285</a>             );
+<a name="286" href="#286">286</a>         WSSecurityUtil.setNamespace(element, WSConstants.WSU_NS, WSConstants.WSU_PREFIX);
+<a name="287" href="#287">287</a>         elementCreated.appendChild(doc.createTextNode(zulu.format(rightNow.getTime())));
+<a name="288" href="#288">288</a>         element.appendChild(elementCreated);
+<a name="289" href="#289">289</a>     }
+<a name="290" href="#290">290</a> 
+<a name="291" href="#291">291</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="292" href="#292">292</a> <em class="jxr_javadoccomment">     * Adds and optionally creates a Salt element to this UsernameToken.</em>
+<a name="293" href="#293">293</a> <em class="jxr_javadoccomment">     * </em>
+<a name="294" href="#294">294</a> <em class="jxr_javadoccomment">     * If the &lt;code&gt;saltValue&lt;/code&gt; is &lt;code&gt;null&lt;/code&gt; the the method</em>
+<a name="295" href="#295">295</a> <em class="jxr_javadoccomment">     * generates a new salt. Otherwise it uses the the given value.</em>
+<a name="296" href="#296">296</a> <em class="jxr_javadoccomment">     * </em>
+<a name="297" href="#297">297</a> <em class="jxr_javadoccomment">     * @param doc The Document for the UsernameToken</em>
+<a name="298" href="#298">298</a> <em class="jxr_javadoccomment">     * @param saltValue The salt to add, if null generate a new salt value</em>
+<a name="299" href="#299">299</a> <em class="jxr_javadoccomment">     * @param mac If &lt;code&gt;true&lt;/code&gt; then an optionally generated value is</em>
+<a name="300" href="#300">300</a> <em class="jxr_javadoccomment">     *            usable for a MAC</em>
+<a name="301" href="#301">301</a> <em class="jxr_javadoccomment">     * @return Returns the added salt</em>
+<a name="302" href="#302">302</a> <em class="jxr_javadoccomment">     */</em>
+<a name="303" href="#303">303</a>     <strong class="jxr_keyword">public</strong> byte[] addSalt(Document doc, byte[] saltValue, <strong class="jxr_keyword">boolean</strong> mac) {
+<a name="304" href="#304">304</a>         <strong class="jxr_keyword">if</strong> (saltValue == <strong class="jxr_keyword">null</strong>) {
+<a name="305" href="#305">305</a>             saltValue = generateSalt(mac);
+<a name="306" href="#306">306</a>         }
+<a name="307" href="#307">307</a>         elementSalt = 
+<a name="308" href="#308">308</a>             doc.createElementNS(
+<a name="309" href="#309">309</a>                 WSConstants.WSSE11_NS, WSConstants.WSSE11_PREFIX + <span class="jxr_string">":"</span> + WSConstants.SALT_LN
+<a name="310" href="#310">310</a>             );
+<a name="311" href="#311">311</a>         WSSecurityUtil.setNamespace(<strong class="jxr_keyword">this</strong>.element, WSConstants.WSSE11_NS, WSConstants.WSSE11_PREFIX);
+<a name="312" href="#312">312</a>         elementSalt.appendChild(doc.createTextNode(Base64.encode(saltValue)));
+<a name="313" href="#313">313</a>         element.appendChild(elementSalt);
+<a name="314" href="#314">314</a>         <strong class="jxr_keyword">return</strong> saltValue;
+<a name="315" href="#315">315</a>     }
+<a name="316" href="#316">316</a> 
+<a name="317" href="#317">317</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="318" href="#318">318</a> <em class="jxr_javadoccomment">     * Creates and adds a Iteration element to this UsernameToken</em>
+<a name="319" href="#319">319</a> <em class="jxr_javadoccomment">     */</em>
+<a name="320" href="#320">320</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> addIteration(Document doc, <strong class="jxr_keyword">int</strong> iteration) {
+<a name="321" href="#321">321</a>         String text = <span class="jxr_string">""</span> + iteration;
+<a name="322" href="#322">322</a>         elementIteration = 
+<a name="323" href="#323">323</a>             doc.createElementNS(
+<a name="324" href="#324">324</a>                 WSConstants.WSSE11_NS, WSConstants.WSSE11_PREFIX + <span class="jxr_string">":"</span> + WSConstants.ITERATION_LN
+<a name="325" href="#325">325</a>             );
+<a name="326" href="#326">326</a>         WSSecurityUtil.setNamespace(element, WSConstants.WSSE11_NS, WSConstants.WSSE11_PREFIX);
+<a name="327" href="#327">327</a>         <strong class="jxr_keyword">this</strong>.elementIteration.appendChild(doc.createTextNode(text));
+<a name="328" href="#328">328</a>         element.appendChild(elementIteration);
+<a name="329" href="#329">329</a>     }
+<a name="330" href="#330">330</a> 
+<a name="331" href="#331">331</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="332" href="#332">332</a> <em class="jxr_javadoccomment">     * Get the user name.</em>
+<a name="333" href="#333">333</a> <em class="jxr_javadoccomment">     * </em>
+<a name="334" href="#334">334</a> <em class="jxr_javadoccomment">     * @return the data from the user name element.</em>
+<a name="335" href="#335">335</a> <em class="jxr_javadoccomment">     */</em>
+<a name="336" href="#336">336</a>     <strong class="jxr_keyword">public</strong> String getName() {
+<a name="337" href="#337">337</a>         <strong class="jxr_keyword">return</strong> nodeString(elementUsername);
+<a name="338" href="#338">338</a>     }
+<a name="339" href="#339">339</a> 
+<a name="340" href="#340">340</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="341" href="#341">341</a> <em class="jxr_javadoccomment">     * Set the user name.</em>
+<a name="342" href="#342">342</a> <em class="jxr_javadoccomment">     * </em>
+<a name="343" href="#343">343</a> <em class="jxr_javadoccomment">     * @param name sets a text node containing the use name into the user name</em>
+<a name="344" href="#344">344</a> <em class="jxr_javadoccomment">     *             element.</em>
+<a name="345" href="#345">345</a> <em class="jxr_javadoccomment">     */</em>
+<a name="346" href="#346">346</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setName(String name) {
+<a name="347" href="#347">347</a>         Text node = getFirstNode(elementUsername);
+<a name="348" href="#348">348</a>         node.setData(name);
+<a name="349" href="#349">349</a>     }
+<a name="350" href="#350">350</a> 
+<a name="351" href="#351">351</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="352" href="#352">352</a> <em class="jxr_javadoccomment">     * Get the nonce.</em>
+<a name="353" href="#353">353</a> <em class="jxr_javadoccomment">     * </em>
+<a name="354" href="#354">354</a> <em class="jxr_javadoccomment">     * @return the data from the nonce element.</em>
+<a name="355" href="#355">355</a> <em class="jxr_javadoccomment">     */</em>
+<a name="356" href="#356">356</a>     <strong class="jxr_keyword">public</strong> String getNonce() {
+<a name="357" href="#357">357</a>         <strong class="jxr_keyword">return</strong> nodeString(elementNonce);
+<a name="358" href="#358">358</a>     }
+<a name="359" href="#359">359</a> 
+<a name="360" href="#360">360</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="361" href="#361">361</a> <em class="jxr_javadoccomment">     * Get the created timestamp.</em>
+<a name="362" href="#362">362</a> <em class="jxr_javadoccomment">     * </em>
+<a name="363" href="#363">363</a> <em class="jxr_javadoccomment">     * @return the data from the created time element.</em>
+<a name="364" href="#364">364</a> <em class="jxr_javadoccomment">     */</em>
+<a name="365" href="#365">365</a>     <strong class="jxr_keyword">public</strong> String getCreated() {
+<a name="366" href="#366">366</a>         <strong class="jxr_keyword">return</strong> nodeString(elementCreated);
+<a name="367" href="#367">367</a>     }
+<a name="368" href="#368">368</a> 
+<a name="369" href="#369">369</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="370" href="#370">370</a> <em class="jxr_javadoccomment">     * Gets the password string. This is the password as it is in the password</em>
+<a name="371" href="#371">371</a> <em class="jxr_javadoccomment">     * element of a username token. Thus it can be either plain text or the</em>
+<a name="372" href="#372">372</a> <em class="jxr_javadoccomment">     * password digest value.</em>
+<a name="373" href="#373">373</a> <em class="jxr_javadoccomment">     * </em>
+<a name="374" href="#374">374</a> <em class="jxr_javadoccomment">     * @return the password string or &lt;code&gt;null&lt;/code&gt; if no such node exists.</em>

[... 617 lines stripped ...]


Mime
View raw message