{"id":1513,"date":"2009-12-01T17:49:16","date_gmt":"2009-12-01T15:49:16","guid":{"rendered":"http:\/\/firefang.net\/blog\/?p=1513"},"modified":"2009-12-01T17:49:16","modified_gmt":"2009-12-01T15:49:16","slug":"java-with-authenticated-urls","status":"publish","type":"post","link":"https:\/\/firefang.net\/blog\/1513","title":{"rendered":"Java with authenticated urls"},"content":{"rendered":"<p>\u05d4\u05ea\u05e7\u05df \u05e9\u05dc HTTP \u05db\u05d5\u05dc\u05dc \u05e7\u05d1\u05d9\u05e2\u05d4 \u05e9\u05dc \u05e9\u05dd \u05de\u05e9\u05ea\u05de\u05e9 \u05d5\u05e1\u05d9\u05e1\u05de\u05d0 \u05d9\u05e9\u05d9\u05e8\u05d5\u05ea \u05d1URL, \u05dc\u05de\u05e9\u05dc:<br \/>\n[code]<br \/>\nhttp:\/\/user:password@site.com\/file.txt<br \/>\n[\/code]<\/p>\n<p>\u05de\u05e1\u05d9\u05d1\u05d4 \u05dc\u05d0 \u05d1\u05e8\u05d5\u05e8\u05d4, \u05d2'\u05d0\u05d5\u05d5\u05d4 \u05dc\u05d0 \u05de\u05e1\u05ea\u05d3\u05e8 \u05e2\u05dd URL\u05d9\u05dd \u05db\u05d0\u05dc\u05d5 \u05d5\u05e0\u05e8\u05d0\u05d4 \u05e9\u05d4\u05d5\u05d0 \u05dc\u05d0 \u05de\u05e2\u05d1\u05d9\u05e8 \u05d0\u05ea \u05e9\u05dd \u05d4\u05de\u05e9\u05ea\u05de\u05e9 \u05d5\u05d4\u05e1\u05d9\u05e1\u05de\u05d0 \u05dc\u05d0\u05ea\u05e8.<br \/>\n\u05d4\u05e0\u05d4 \u05e4\u05ea\u05e8\u05d5\u05df \u05dc\u05e2\u05e0\u05d9\u05d9\u05df (\u05e2\u05e7\u05d5\u05dd \u05d0\u05da \u05d2\u05e0\u05e8\u05d9) :<br \/>\n[code lang=&quot;java&quot;]<br \/>\nAuthenticator.setDefault(new Authenticator()<br \/>\n{<br \/>\n    @Override<br \/>\n    protected PasswordAuthentication getPasswordAuthentication()<br \/>\n    {<br \/>\n        URL url = getRequestingURL();<br \/>\n        String userInfo = url.getUserInfo();<br \/>\n        String user;<br \/>\n        String password;<br \/>\n        int i = userInfo.indexOf(':');<br \/>\n        if (i == -1)<br \/>\n        {<br \/>\n            user = userInfo.substring(0);<br \/>\n            password = &quot;&quot;;<br \/>\n        }<br \/>\n        else<br \/>\n        {<br \/>\n            user = userInfo.substring(0, i);<br \/>\n            password = userInfo.substring(i+1);<br \/>\n        }<br \/>\n        PasswordAuthentication ps = new PasswordAuthentication(user, password.toCharArray());<br \/>\n        return ps;<br \/>\n    }<br \/>\n});<br \/>\n[\/code]<\/p>\n<p>\u05e2\u05d5\u05d2\u05d9\u05d4 \u05dc\u05de\u05d9 \u05e9\u05e1\u05d1\u05d9\u05e8 \u05dc\u05de\u05d4 \u05d4\u05de\u05d9\u05de\u05d5\u05e9 \u05d4\u05e1\u05d8\u05e0\u05d3\u05e8\u05d8\u05d9 \u05e9\u05dc \u05d2'\u05d0\u05d5\u05d5\u05d4 \u05dc\u05d0 \u05ea\u05d5\u05de\u05da \u05d1\u05d3\u05d1\u05e8 \u05d4\u05d8\u05e8\u05d9\u05d5\u05d9\u05d0\u05dc\u05d9 \u05d4\u05d6\u05d4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u05d4\u05ea\u05e7\u05df \u05e9\u05dc HTTP \u05db\u05d5\u05dc\u05dc \u05e7\u05d1\u05d9\u05e2\u05d4 \u05e9\u05dc \u05e9\u05dd \u05de\u05e9\u05ea\u05de\u05e9 \u05d5\u05e1\u05d9\u05e1\u05de\u05d0 \u05d9\u05e9\u05d9\u05e8\u05d5\u05ea \u05d1URL, \u05dc\u05de\u05e9\u05dc: [code] http:\/\/user:password@site.com\/file.txt [\/code] \u05de\u05e1\u05d9\u05d1\u05d4 \u05dc\u05d0 \u05d1\u05e8\u05d5\u05e8\u05d4, \u05d2'\u05d0\u05d5\u05d5\u05d4 \u05dc\u05d0 \u05de\u05e1\u05ea\u05d3\u05e8 \u05e2\u05dd URL\u05d9\u05dd \u05db\u05d0\u05dc\u05d5 \u05d5\u05e0\u05e8\u05d0\u05d4 \u05e9\u05d4\u05d5\u05d0 \u05dc\u05d0 \u05de\u05e2\u05d1\u05d9\u05e8 \u05d0\u05ea \u05e9\u05dd \u05d4\u05de\u05e9\u05ea\u05de\u05e9 \u05d5\u05d4\u05e1\u05d9\u05e1\u05de\u05d0 \u05dc\u05d0\u05ea\u05e8. \u05d4\u05e0\u05d4 \u05e4\u05ea\u05e8\u05d5\u05df \u05dc\u05e2\u05e0\u05d9\u05d9\u05df (\u05e2\u05e7\u05d5\u05dd \u05d0\u05da \u05d2\u05e0\u05e8\u05d9) : [code lang=&quot;java&quot;] Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { URL url = getRequestingURL(); String &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/firefang.net\/blog\/1513\" class=\"more-link\">\u05dc\u05d4\u05de\u05e9\u05d9\u05da \u05dc\u05e7\u05e8\u05d5\u05d0<span class=\"screen-reader-text\"> Java with authenticated urls<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1513","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/firefang.net\/blog\/wp-json\/wp\/v2\/posts\/1513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/firefang.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/firefang.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/firefang.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/firefang.net\/blog\/wp-json\/wp\/v2\/comments?post=1513"}],"version-history":[{"count":2,"href":"https:\/\/firefang.net\/blog\/wp-json\/wp\/v2\/posts\/1513\/revisions"}],"predecessor-version":[{"id":1515,"href":"https:\/\/firefang.net\/blog\/wp-json\/wp\/v2\/posts\/1513\/revisions\/1515"}],"wp:attachment":[{"href":"https:\/\/firefang.net\/blog\/wp-json\/wp\/v2\/media?parent=1513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/firefang.net\/blog\/wp-json\/wp\/v2\/categories?post=1513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/firefang.net\/blog\/wp-json\/wp\/v2\/tags?post=1513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}