mirror of
https://github.com/salesagility/SuiteCRM.git
synced 2025-03-13 04:53:21 +00:00
Add a SAML2 metadata endpoint (named "SAML2Metadata")
This adds a new endpoint which returns the XML metadata for the saml integration. The output can be used to register the service with the identity provider. The endpoint can be reached through "index.php?entryPoint=SAML2Metadata" Based on the php-saml example: https://github.com/onelogin/php-saml/blob/master/demo1/metadata.php
This commit is contained in:
parent
7f2783b4bd
commit
cf230157a6
4 changed files with 143 additions and 0 deletions
include/MVC/Controller
modules/Users/authentication/SAML2Authenticate
tests/unit/phpunit/modules/Users
|
@ -73,6 +73,7 @@ $entry_point_registry = array(
|
|||
'getYUIComboFile' => array('file' => 'include/javascript/getYUIComboFile.php', 'auth' => false),
|
||||
'UploadFileCheck' => array('file' => 'modules/Configurator/UploadFileCheck.php', 'auth' => true),
|
||||
'SAML'=> array('file' => 'modules/Users/authentication/SAMLAuthenticate/index.php', 'auth' => false),
|
||||
'SAML2Metadata'=> array('file' => 'modules/Users/authentication/SAML2Authenticate/SAML2Metadata.php', 'auth' => false),
|
||||
'jslang'=> array('file' => 'include/language/getJSLanguage.php', 'auth' => true),
|
||||
'deleteAttachment' => array('file' => 'include/SugarFields/Fields/Image/deleteAttachment.php', 'auth' => false),
|
||||
'responseEntryPoint' => array('file' => 'modules/FP_events/responseEntryPoint.php', 'auth' => false),
|
||||
|
|
|
@ -44,6 +44,27 @@ if (!defined('sugarEntry') || !sugarEntry) {
|
|||
|
||||
require_once('modules/Users/authentication/SugarAuthenticate/SugarAuthenticate.php');
|
||||
|
||||
/**
|
||||
* Returns the XML metadata which can be used to register the SP with the IDP
|
||||
*
|
||||
* @param array $settingsInfo a SAML2 settings array structure
|
||||
* @return string the xml metadata
|
||||
* @throws OneLogin_Saml2_Error In case the settings/metadata are invalid
|
||||
*/
|
||||
function getSAML2Metadata($settingsInfo) {
|
||||
$auth = new OneLogin_Saml2_Auth($settingsInfo);
|
||||
$settings = $auth->getSettings();
|
||||
$metadata = $settings->getSPMetadata();
|
||||
$errors = $settings->validateMetadata($metadata);
|
||||
if (!empty($errors)) {
|
||||
throw new OneLogin_Saml2_Error(
|
||||
'Invalid SP metadata: '.implode(', ', $errors),
|
||||
OneLogin_Saml2_Error::METADATA_SP_INVALID
|
||||
);
|
||||
}
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class SAML2Authenticate for SAML2 auth
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* SugarCRM Community Edition is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
|
||||
*
|
||||
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
|
||||
* Copyright (C) 2011 - 2018 SalesAgility Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
|
||||
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
|
||||
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
|
||||
*/
|
||||
|
||||
if (!defined('sugarEntry') || !sugarEntry) {
|
||||
die('Not A Valid Entry Point');
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/SAML2Authenticate.php';
|
||||
require_once __DIR__ . '/lib/onelogin/settings.php';
|
||||
|
||||
try {
|
||||
$xml = getSAML2Metadata($settingsInfo);
|
||||
header('Content-Type: text/xml');
|
||||
echo $xml;
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
67
tests/unit/phpunit/modules/Users/SAML2AuthenticateTest.php
Normal file
67
tests/unit/phpunit/modules/Users/SAML2AuthenticateTest.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
use SuiteCRM\StateSaver;
|
||||
|
||||
require_once __DIR__ . '/../../../../../modules/Users/authentication/SAML2Authenticate/SAML2Authenticate.php';
|
||||
|
||||
class SAML2MetadataTest extends SuiteCRM\StateCheckerPHPUnitTestCaseAbstract {
|
||||
|
||||
public function testEntryPointNoAuth() {
|
||||
$controller = new SugarController();
|
||||
$result = $controller->checkEntryPointRequiresAuth('SAML2Metadata');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testIncompleteSettings() {
|
||||
$state = new StateSaver();
|
||||
$state->pushErrorLevel();
|
||||
// php-saml triggers deprecation warnings, so disable temporarily
|
||||
error_reporting(E_ALL & ~E_DEPRECATED);
|
||||
|
||||
$failed = false;
|
||||
try {
|
||||
$settings = array('sp' => array(), 'idp' => array());
|
||||
try {
|
||||
getSAML2Metadata($settings);
|
||||
} catch (Exception $e) {
|
||||
$failed = true;
|
||||
}
|
||||
} finally {
|
||||
$state->popErrorLevel();
|
||||
}
|
||||
|
||||
$this->assertTrue($failed);
|
||||
}
|
||||
|
||||
public function testMinimalValidExample() {
|
||||
$settings = array(
|
||||
'sp' => array(
|
||||
'entityId' => 'someid',
|
||||
'assertionConsumerService' => array(
|
||||
'url' => 'https://someurl',
|
||||
),
|
||||
),
|
||||
'idp' => array(
|
||||
'entityId' => 'someotherid',
|
||||
'singleSignOnService' => array(
|
||||
'url' => 'https://localhost/foo',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$state = new StateSaver();
|
||||
$state->pushErrorLevel();
|
||||
// php-saml triggers deprecation warnings, so disable temporarily
|
||||
error_reporting(E_ALL & ~E_DEPRECATED);
|
||||
try {
|
||||
$xml = getSAML2Metadata($settings);
|
||||
} finally {
|
||||
$state->popErrorLevel();
|
||||
}
|
||||
$this->assertNotEmpty($xml);
|
||||
$this->assertRegexp('/someid/', $xml);
|
||||
$this->assertRegexp('/someurl/', $xml);
|
||||
$this->assertNotFalse(simplexml_load_string($xml));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue