⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preconditionenforcer.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<a name="376" href="#376">376</a> <em>    * Consider credential preconditions.</em><a name="377" href="#377">377</a> <em>    *</em><a name="378" href="#378">378</a> <em>    * Looks to see if any credential preconditions (e.g. html form login</em><a name="379" href="#379">379</a> <em>    * credentials) for this &lt;code>CrawlServer&lt;/code>. If there are, have they</em><a name="380" href="#380">380</a> <em>    * been run already? If not, make the running of these logins a precondition</em><a name="381" href="#381">381</a> <em>    * of accessing any other url on this &lt;code>CrawlServer&lt;/code>.</em><a name="382" href="#382">382</a> <em>    *</em><a name="383" href="#383">383</a> <em>    * &lt;p></em><a name="384" href="#384">384</a> <em>    * One day, do optimization and avoid running the bulk of the code below.</em><a name="385" href="#385">385</a> <em>    * Argument for running the code everytime is that overrides and refinements</em><a name="386" href="#386">386</a> <em>    * may change what comes back from credential store.</em><a name="387" href="#387">387</a> <em>    *</em><a name="388" href="#388">388</a> <em>    * @param curi CrawlURI we're checking for any required preconditions.</em><a name="389" href="#389">389</a> <em>    * @return True, if this &lt;code>curi&lt;/code> has a precondition that needs to</em><a name="390" href="#390">390</a> <em>    *         be met before we can proceed. False if we can precede to process</em><a name="391" href="#391">391</a> <em>    *         this url.</em><a name="392" href="#392">392</a> <em>    */</em><a name="393" href="#393">393</a>     <strong>private</strong> <strong>boolean</strong> credentialPrecondition(<strong>final</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="394" href="#394">394</a> <a name="395" href="#395">395</a>         <strong>boolean</strong> result = false;<a name="396" href="#396">396</a> <a name="397" href="#397">397</a>         <a href="../../../../org/archive/crawler/datamodel/CredentialStore.html">CredentialStore</a> cs =<a name="398" href="#398">398</a>             CredentialStore.getCredentialStore(getSettingsHandler());<a name="399" href="#399">399</a>         <strong>if</strong> (cs == <strong>null</strong>) {<a name="400" href="#400">400</a>             logger.severe(<span class="string">"No credential store for "</span> + curi);<a name="401" href="#401">401</a>             <strong>return</strong> result;<a name="402" href="#402">402</a>         }<a name="403" href="#403">403</a> <a name="404" href="#404">404</a>         Iterator i = cs.iterator(curi);<a name="405" href="#405">405</a>         <strong>if</strong> (i == <strong>null</strong>) {<a name="406" href="#406">406</a>             <strong>return</strong> result;<a name="407" href="#407">407</a>         }<a name="408" href="#408">408</a> <a name="409" href="#409">409</a>         <strong>while</strong> (i.hasNext()) {<a name="410" href="#410">410</a>             <a href="../../../../org/archive/crawler/datamodel/credential/Credential.html">Credential</a> c = (Credential)i.next();<a name="411" href="#411">411</a> <a name="412" href="#412">412</a>             <strong>if</strong> (c.isPrerequisite(curi)) {<a name="413" href="#413">413</a>                 <em class="comment">// This credential has a prereq. and this curi is it.  Let it</em><a name="414" href="#414">414</a>                 <em class="comment">// through.  Add its avatar to the curi as a mark.  Also, does</em><a name="415" href="#415">415</a>                 <em class="comment">// this curi need to be posted?  Note, we do this test for</em><a name="416" href="#416">416</a>                 <em class="comment">// is it a prereq BEFORE we do the check that curi is of the</em><a name="417" href="#417">417</a>                 <em class="comment">// credential domain because such as yahoo have you go to</em><a name="418" href="#418">418</a>                 <em class="comment">// another domain altogether to login.</em><a name="419" href="#419">419</a>                 c.attach(curi);<a name="420" href="#420">420</a>                 curi.setPost(c.isPost(curi));<a name="421" href="#421">421</a>                 <strong>break</strong>;<a name="422" href="#422">422</a>             }<a name="423" href="#423">423</a> <a name="424" href="#424">424</a>             <strong>if</strong> (!c.rootUriMatch(getController(), curi)) {<a name="425" href="#425">425</a>                 <strong>continue</strong>;<a name="426" href="#426">426</a>             }<a name="427" href="#427">427</a> <a name="428" href="#428">428</a>             <strong>if</strong> (!c.hasPrerequisite(curi)) {<a name="429" href="#429">429</a>                 <strong>continue</strong>;<a name="430" href="#430">430</a>             }<a name="431" href="#431">431</a> <a name="432" href="#432">432</a>             <strong>if</strong> (!authenticated(c, curi)) {<a name="433" href="#433">433</a>                 <em class="comment">// Han't been authenticated.  Queue it and move on (Assumption</em><a name="434" href="#434">434</a>                 <em class="comment">// is that we can do one authentication at a time -- usually one</em><a name="435" href="#435">435</a>                 <em class="comment">// html form).</em><a name="436" href="#436">436</a>                 String prereq = c.getPrerequisite(curi);<a name="437" href="#437">437</a>                 <strong>if</strong> (prereq == <strong>null</strong> || prereq.length() &lt;= 0) {<a name="438" href="#438">438</a>                     <a href="../../../../org/archive/crawler/datamodel/CrawlServer.html">CrawlServer</a> server =<a name="439" href="#439">439</a>                         getController().getServerCache().getServerFor(curi);<a name="440" href="#440">440</a>                     logger.severe(server.getName() + <span class="string">" has "</span><a name="441" href="#441">441</a>                         + <span class="string">" credential(s) of type "</span> + c + <span class="string">" but prereq"</span><a name="442" href="#442">442</a>                         + <span class="string">" is null."</span>);<a name="443" href="#443">443</a>                 } <strong>else</strong> {<a name="444" href="#444">444</a>                     <strong>try</strong> {<a name="445" href="#445">445</a>                         curi.markPrerequisite(prereq,<a name="446" href="#446">446</a>                             getController().getPostprocessorChain());<a name="447" href="#447">447</a>                     } <strong>catch</strong> (URIException e) {<a name="448" href="#448">448</a>                         logger.severe(<span class="string">"unable to set credentials prerequisite "</span>+prereq);<a name="449" href="#449">449</a>                         getController().logUriError(e,curi.getUURI(),prereq);<a name="450" href="#450">450</a>                         <strong>return</strong> false; <a name="451" href="#451">451</a>                     }<a name="452" href="#452">452</a>                     result = <strong>true</strong>;<a name="453" href="#453">453</a>                     <strong>if</strong> (logger.isLoggable(Level.FINE)) {<a name="454" href="#454">454</a>                         logger.fine(<span class="string">"Queueing prereq "</span> + prereq + <span class="string">" of type "</span> +<a name="455" href="#455">455</a>                             c + <span class="string">" for "</span> + curi);<a name="456" href="#456">456</a>                     }<a name="457" href="#457">457</a>                     <strong>break</strong>;<a name="458" href="#458">458</a>                 }<a name="459" href="#459">459</a>             }<a name="460" href="#460">460</a>         }<a name="461" href="#461">461</a>         <strong>return</strong> result;<a name="462" href="#462">462</a>     }<a name="463" href="#463">463</a> <a name="464" href="#464">464</a>     <em>/**<em>*</em></em><a name="465" href="#465">465</a> <em>     * Has passed credential already been authenticated.</em><a name="466" href="#466">466</a> <em>     *</em><a name="467" href="#467">467</a> <em>     * @param credential Credential to test.</em><a name="468" href="#468">468</a> <em>     * @param curi CrawlURI.</em><a name="469" href="#469">469</a> <em>     * @return True if already run.</em><a name="470" href="#470">470</a> <em>     */</em><a name="471" href="#471">471</a>     <strong>private</strong> <strong>boolean</strong> authenticated(<strong>final</strong> <a href="../../../../org/archive/crawler/datamodel/credential/Credential.html">Credential</a> credential,<a name="472" href="#472">472</a>             <strong>final</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="473" href="#473">473</a>         <strong>boolean</strong> result = false;<a name="474" href="#474">474</a>         <a href="../../../../org/archive/crawler/datamodel/CrawlServer.html">CrawlServer</a> server =<a name="475" href="#475">475</a>             getController().getServerCache().getServerFor(curi);<a name="476" href="#476">476</a>         <strong>if</strong> (!server.hasCredentialAvatars()) {<a name="477" href="#477">477</a>             <strong>return</strong> result;<a name="478" href="#478">478</a>         }<a name="479" href="#479">479</a>         Set avatars = server.getCredentialAvatars();<a name="480" href="#480">480</a>         <strong>for</strong> (Iterator i = avatars.iterator(); i.hasNext();) {<a name="481" href="#481">481</a>             <a href="../../../../org/archive/crawler/datamodel/credential/CredentialAvatar.html">CredentialAvatar</a> ca = (CredentialAvatar)i.next();<a name="482" href="#482">482</a>             String key = <strong>null</strong>;<a name="483" href="#483">483</a>             <strong>try</strong> {<a name="484" href="#484">484</a>                 key = credential.getKey(curi);<a name="485" href="#485">485</a>             } <strong>catch</strong> (AttributeNotFoundException e) {<a name="486" href="#486">486</a>                 logger.severe(<span class="string">"Failed getting key for "</span> + credential +<a name="487" href="#487">487</a>                     <span class="string">" for "</span> + curi);<a name="488" href="#488">488</a>                 <strong>continue</strong>;<a name="489" href="#489">489</a>             }<a name="490" href="#490">490</a>             <strong>if</strong> (ca.match(credential.getClass(), key)) {<a name="491" href="#491">491</a>                 result = <strong>true</strong>;<a name="492" href="#492">492</a>             }<a name="493" href="#493">493</a>         }<a name="494" href="#494">494</a>         <strong>return</strong> result;<a name="495" href="#495">495</a>     }<a name="496" href="#496">496</a> }</pre><hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -