2016-05-17 203 views
0

實際上,我有一個使用WSO2身份驗證服務器(它重定向到WSO2IS登錄頁面)使用SimpleSAML進行身份驗證的CakePHP應用程序。我需要在應用程序中創建一個頁面,並將這些信息發送到WSO2IS以對用戶進行身份驗證。我該怎麼做?我沒有找到任何關於它的示例/文檔。 我跟着這個tutorial與WOS2身份服務器的PHP身份驗證集成

文件中simplesaml: 配置/ authsources.php

<?php 
$config = array(
    'wso2-sp' => array(
     'saml:SP', 
     'entityID' => 'IntranetSP', // I supposed that it is the ID of my Service Provider 
     'idp' => 'https://soa.rw1.local:9443/samlsso' 
    ) 
); 

?> 

元/ saml20-IDP-remote.php

<?php 

$metadata['https://soa.rw1.local:9443/samlsso'] = array(

    'name' => array(

     'en' => 'WSO2 IS', 

     'no' => 'WSO2 IS', 

    ), 

    'description' => 'Login with WSO2 IS SAML2 IdP.', 

    'SingleSignOnService' => 'https://soa.rw1.local:9443/samlsso', 

    'SingleLogoutService' => 'https://soa.rw1.local:9443/samlsso', 

    'certFingerprint'  => '6bf8e136eb36d4a56ea05c7ae4b9a45b63bf975d' 



); 

?> 

在我WSO2的是:

Service provider Configuration: 

Service Provider Name: IntranetSP 
Local & Outbound Authentication Configuration/Request Path Authentication Configuration: basic-auth 
+0

您可以按照[1]設置sso Identity Server,使用簡單的示例php [1] https://docs.wso2.com/display/IS500/SAML2+IdP+with+SimpleSAMLphp+Service+Provider –

+0

大多數身份驗證器做同樣的工作,所以你可以參考其他自定義身份驗證器[1] [1] https://docs.wso2.com/display/ISCONNECTORS/Identity+Server+Authenticators+and+Connectors –

+0

@IsuraDilharaKarunaratne是的,我用這個例子它的工作..我的問題是,我需要創建一個PHP登錄頁面(這很容易),併發送到WSO2的信息進行身份驗證..實際上,登錄頁面是在WSO2,所以,我的PHP應用程序重定向用戶一個WSO2登錄頁面來完成完整的身份驗證。 –

回答

0

在您的服務提供商配置,在本地和出站身份驗證配置下,爲您配置SP請求路徑身份驗證。有關執行此操作的更多信息,請按照this

以下是您可以從客戶端發送請求的Java代碼。

@Test(alwaysRun = true, description = "Test login success") 
public void testLoginSuccess() throws Exception { 
    HttpPost request = new HttpPost(TRAVELOCITY_SAMPLE_APP_URL + "/samlsso?SAML2.HTTPBinding=HTTP-POST"); 
    List<NameValuePair> urlParameters = new ArrayList<>(); 
    urlParameters.add(new BasicNameValuePair("username", adminUsername)); 
    urlParameters.add(new BasicNameValuePair("password", adminPassword)); 
    request.setEntity(new UrlEncodedFormEntity(urlParameters)); 
    HttpResponse response = client.execute(request); 
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 
    String line; 
    String samlRequest = ""; 
    String secToken = ""; 

    while ((line = rd.readLine()) != null) { 
     if (line.contains("name='SAMLRequest'")) { 
      String[] tokens = line.split("'"); 
      samlRequest = tokens[5]; 
     } 
     if (line.contains("name='sectoken'")) { 
      String[] tokens = line.split("'"); 
      secToken = tokens[5]; 
     } 
    } 
    EntityUtils.consume(response.getEntity()); 
    request = new HttpPost(isURL + "samlsso"); 
    urlParameters = new ArrayList<>(); 
    urlParameters.add(new BasicNameValuePair("sectoken", secToken)); 
    urlParameters.add(new BasicNameValuePair("SAMLRequest", samlRequest)); 
    request.setEntity(new UrlEncodedFormEntity(urlParameters)); 
    response = client.execute(request); 
    String samlResponse = ""; 
    rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 
    while ((line = rd.readLine()) != null) { 
     if (line.contains("name='SAMLResponse'")) { 
      String[] tokens = line.split("'"); 
      samlResponse = tokens[5]; 
     } 
    } 
    Base64 base64Decoder = new Base64(); 
    samlResponse = new String(base64Decoder.decode(samlResponse)) 
    EntityUtils.consume(response.getEntity()); 
} 

你應該能夠通過發送相同的請求在PHP中實現這一點。

但是,如果您的要求是更改登錄頁面,您可以自定義wso2 IS登錄頁面,如here所述,而無需使用您自己的頁面。如果你的要求是這樣,我建議你這樣做,因爲這會讓你的生活變得更輕鬆。

+0

但是我怎樣才能在我的PHP應用程序中應用這個?我已經在使用已配置的SP(我正在使用WSO2IS 5.0.0) –

+0

您是否無法更新SP,您需要在SP中啓用請求路徑身份驗證,否則用戶將不得不在IS中輸入憑證sso登錄頁面。 –

+0

我參考了鏈接,但沒有解釋如何在php中配置simplesaml,只有如何在IS中進行配置。我在IS中添加了一個服務提供者,就像在教程中一樣(在Request Path Auth Conf - Local&Out中添加了basic-auth ...),但現在我不知道如何配置我的simplesaml。我將編輯我的問題,把我的conf文件 –