2016-05-17 145 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文件 –