我正在開發一個Android項目,該項目必須與SSO Shibboleth身份驗證受保護網站進行強烈交互。因此,我必須創建一個Java類來創建有效的SAML斷言並登錄到網站。如何登錄有效的SAML 2.0斷言?
我GOOGLE了很多,我覺得這一段代碼:http://blog.keksrolle.de/2010/07/27/how-to-create-a-valid-saml-2-0-assertion-with-opensaml-for-java.html 其實我發現並不需要它,因爲我是能夠獲得通過一些HttpConnection的請求,SAML響應。
我寫的代碼能夠執行步驟這個名單的1-5:http://en.wikipedia.org/wiki/Security_Assertion_Markup_Language#The_SAML_Use_Case 它確實是越來越SAMLResponse參數,這是一個元素的Base64編碼的值的最後一件事。然後它向斷言消費者服務發出POST請求。 這裏僞代碼:
/* discover the IdP */
connect to the link (/idp/login/) which redirects to the form page (/Authn/UserPassword)
get cookies from the link in order to gain access to the form page
/* end */
/* get SAML response climbing the redirects */
set goTo var to the link of the form page
do {
send POST data (+ cookies) to the goTo page
get cookies of the new page and saves them with the others
set goTo to connection.getHeaderField("Location");
} while (!(responseCode==200));
read the source of the last redirect
get the specific SAMLResponse
/* end */
send it to website.com/Shibboleth.sso/SAML2/POST
get cookies, session data
但後來服務器的響應是一個500錯誤代碼,或在頁面錯誤代碼(「出事了重試。」)。 事實上,即使我有一個有效的SAML斷言(我向服務器發送(編碼)),我也無法獲得會話的訪問權限。 這是會話的問題嗎?一旦我發佈POST請求,我認爲服務器通過cookie(JSESSIONID)和querystring(/home.do;jsessionid=XXXFAEC60AXXX7A7B9XXXAA9EXXXE71X.jvm2c)重新整理了我,但我認爲這可能是完全錯誤的。
如何通過Java登錄SAML認證網站?
另一個(邊際)問題:我執行了所有沒有加密的請求(https)。從安全的角度來看,這可能是一個問題(數據包嗅探等)?
您是否解決了您的問題?如果我可以問,你是怎麼做到的? – 2013-05-13 01:56:48
請參閱:http://stackoverflow.com/a/15731858/1557941 – Gianluca 2013-05-13 18:13:32
謝謝你的迴應,我很高興它爲你工作。我只是想問,你碰巧使用任何外部Java庫,並解決涉及比你上面描述的一個不同的方法,並沒有手動創建自己的主張? – 2013-05-17 16:29:59