簡體   English   中英

cakephp應用程序中的SAML SSO

[英]SAML SSO in cakephp application

我有一個cakephp應用程序,需要用戶通過SAML登錄登錄進行身份驗證。 為此,我點擊了鏈接“ https://github.com/zl4bv/CakePHP-simpleSAMLphp-Plugin ”。

根據其文檔,我已經下載了cakephp和simpleSAMLphp的新副本。 現在,我的工作區中有一個cakephp文件夾和simpleSAMLphp文件夾。 我已按照鏈接“ https://simplesamlphp.org/docs/stable/ ”中所述安裝了simpleSAMLphp。 我按照以下步驟操作:(1)我在apache配置中配置了simpleSAML,如下所示:

<VirtualHost *>
        ServerName service.local-saml.com
        DocumentRoot /var/www/simplesamlphp/www/

       <Directory "/var/www/simplesamlphp/www/">
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost> 

(2)現在,在simplesamlphp應用程序文件夾中,我更改了/config/config.php文件中'auth.adminpassword','secretsalt','technicalcontact_name','technicalcontact_email'的值。

(3)我使用了SAML:sp模塊,默認啟用。

(4)首先,我開始使用SAML作為身份提供者。

(5)我在/config/config.php文件中啟用了'enable.saml20-idp'=> true。

(6)使用終端上的命令創建ssl自簽名證書

sudo openssl req -new -x509 -days 3652 -nodes -out /etc/ssl/certs/simplesamlphp.crt -keyout /etc/ssl/certs/simplesamlphp.pem

(7)將上述證書移至simplesamlphp / cert (8)為config / authsources.php添加了私鑰和證書

'default-sp' => array(
        'saml:SP',
            'privatekey' => 'simplesamlphp.pem',
            'certificate' => 'simplesamlphp.crt',

    ) 

(9)還向“ metadata / saml20-idp-hosted.php ”文件添加了私鑰和證書。

(10)更改了“ metadata / saml20-sp-remote.php ”中的元數據

$metadata['http://service.local-saml.com'] = array(
        'AssertionConsumerService' => 'http://service.local-saml.com/simplesaml/module.php/saml/sp/saml2-acs.php/default-sp',
        'SingleLogoutService' => 'http://service.local-saml.com/simplesaml/module.php/saml/sp/saml2-logout.php/default-sp',
    );

(11)我在鏈接“ https://openidp.feide.no/simplesaml/module.php/core/loginuserpass.php?AuthState=_36266db92ac88d2d66ae8ede39dd1264a39243f08e%3Ahttps%3A%2F%2Fopenidp.feide.no%2Fsimplesaml%上添加了元數據2Fmodule.php%2Fcore%2Fas_login.php%3FAuthId%3Dopenidp-ldap%26ReturnTo%3Dhttps%253A%252F%252Fopenidp.feide.no%252Fsimplesaml%252Fmodule.php%252Fmetaedit%252Findex.php “。

(12)我在瀏覽器上輸入了網址“ http://service.local-saml.com/simplesaml ”,它運行正常。 我嘗試使用default-sp選項登錄,但它運行正常。

現在,我想在我的cakephp應用程序中使用這個simplesamlphp。 (13)為此,如“ https://github.com/zl4bv/CakePHP-simpleSAMLphp-Plugin ”中所述,我將saml文件夾放在Cakephp的/ app / plugin文件夾中

(14)我在core.php和bootstrap.php文件中添加了行。

(15)我創建了一個usersController,並且與鏈接的示例文件中給出的相同。

(16)我添加了以下內容

'sp1' => array(
            'saml:SP',
            'privatekey' => 'simplesamlphp.pem',
            'certificate' => 'simplesamlphp.crt',
            'entityID' => 'http://localhost/cakephp1',
    ),

在simplesamlphp的config / authsources.php中。

(17)我在metadata / saml20-sp-remote.php中添加了元數據

$metadata['http://localhost/cakephp'] = array(
        'AssertionConsumerService' => 'http://localhost/cakephp',
        'SingleLogoutService' => 'http://localhost/cakephp',
);

當我在瀏覽器上鍵入localhost / cakephp時,重定向到“ https://openidp.feide.no/simplesaml/module.php/core/loginuserpass.php ”的鏈接,用戶輸入了他的用戶名和密碼,但“ 狀態信息丟失 “錯誤顯示在” http://service.local-saml.com/simplesaml/module.php/saml/sp/saml2-acs.php/sp1 “,用戶不會返回” localhost / cakephp “。 當用戶輸入登錄憑據時,我希望用戶返回到cakephp url。

請幫助我,我錯了,我錯過了什么?

似乎cakephp和simpleSAMLphp有會話沖突。 一個可行的解決方案是安裝memcache並使用memcache具有simpleSAMLphp的會話處理程序。 https://simplesamlphp.org/docs/stable/simplesamlphp-maintenance#section_2_1

但還有更多方法,請查看: https//simplesamlphp.org/docs/development/simplesamlphp-nostate

你還在php.ini中設置了cookie域嗎?

session.cookie_domain = ".feide.no"

NB! 如果使用PHP會話,則還必須確保應用程序在設置cookie時使用相同的域。 閱讀此來源以獲取更多信息。 祝好運。

有一個簡單的方法可以在沒有這個插件的cakephp中包含simplesamlphp

1-在app / Lib文件夾2中添加已配置和正常工作的simplesamlphp - 在你的控制器中根據我的情況制作你的自定義方法我做了auth()

    function auth()
{
    $this->layout='ajax';
    $this->autoRender=false;
         require_once(APP . 'Lib/simplesamlphp/www/_include.php');

SimpleSAML_Logger::info('SAML2.0 - IdP.SSOService: Accessing SAML 2.0 IdP endpoint SSOService');

$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
$idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
$idp = SimpleSAML_IdP::getById('saml2:' . $idpEntityId);
sspmod_saml_IdP_SAML2::receiveAuthnRequest($idp);
assert('FALSE');

    }

而不是像這樣點擊simplesamlphp的網址http://yoursimplesamlphpurl.com/saml2/idp/SSOService.php?spentityid=spname

使用你的cakephp應用程序的這個URL http://your-cakeappurl.com/CakeControllername/auth?spentityid=spname

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM