2013-07-16 90 views
0

我有一個問題,我需要從登錄Web服務獲取SSO令牌,但我似乎無法得到它。當我做一個ajax後,它會返回登錄網頁的html代碼。我試圖搜索stackoverflow和谷歌提示,但我什麼也沒有得到。這裏是帶有web服務的java函數文件,可以使用url調用,因爲安全原因我不能在這裏發佈。 可能有人給我一個更好的提示,但一個例子很熱這樣做?如何從登錄Web服務獲取sso令牌

package lv.rtu.itd.mobile.api.v1.service; 



    public interface SecurityService { 

    /** 
    * Try to login and aquire SSO token. 
    * 
    * @param username - attribute identifying person. This might me UID, email, short UID, or other supported 
    *   attribues. 
    * @param password - password of the user. 
    * @return SSO token identifying user's session or <code>null</code> in case of invalid credentials. 
    */ 
    String login(String username, String password); 

    /** 
    * Checks if there's a SSO session that can be identified by provided token. 
    * 
    * @param token - token of SSO session returned by {@link #login(String, String)}; 
    * @return <code>true</code> if SSO session is valid, <code>false</code> otherwise. 
    */ 
    boolean isTokenValid(String token); 

    /** 
    * Tries to log out the user's SSO session with given token. 
    * 
    * @param token - token identifying user's SSO session. 
    */ 
    void logout(String token); 
} 

回答

0

您的問題包含太少的細節。首先,可以給出示例AJAX代碼。

假設JSON-RPC被選擇的協議,以下應工作:

POST https://your.domain.com/api/SecurityServiceURL 
Content-Type: application/json 
{"jsonrpc": "2.0", "method": "login", "params": {"username":"yourusername","password":"yourpassword"}, "id": 1} 

在JQuery的AJAX,應該像(未測試):

$.ajax({ 
    url: 'https://your.domain.com/api/SecurityServiceURL', 
     data: JSON.stringify ({"jsonrpc": "2.0", "method": "login", "params": {"username":"yourusername","password":"yourpassword"}, "id": 1}), 
     type:"POST", 
     contentType:"application/json", 
     success: function (data) { 
      alert("ok"); 
     }, 
     error: function (err) { 
      alert("err"); 
     } 
    });