Newer
Older
Olav Morken
committed
<?php
namespace SimpleSAML\Module\saml\Auth\Source;
use SAML2\AuthnRequest;
use SAML2\Binding;
use SAML2\Constants;
use SAML2\Exception\Protocol\NoAvailableIDPException;
use SAML2\Exception\Protocol\NoPassiveException;
use SAML2\Exception\Protocol\NoSupportedIDPException;
use SAML2\XML\saml\NameID;
use SimpleSAML\Assert\Assert;
use SimpleSAML\Auth;
use SimpleSAML\Configuration;
use SimpleSAML\Error;
use SimpleSAML\IdP;
use SimpleSAML\Logger;
use SimpleSAML\Metadata\MetaDataStorageHandler;
use SimpleSAML\Module;
use SimpleSAML\Session;
use SimpleSAML\Store;
use SimpleSAML\Utils;
class SP extends \SimpleSAML\Auth\Source
{
/**
* The entity ID of this SP.
*
* @var string
*/
* @var \SimpleSAML\Configuration
/**
* The IdP the user is allowed to log into.
*
* @var string|null The IdP the user can log into, or null if the user can log into all IdPs.
*/
/**
* URL to discovery service.
*
* @var string|null
*/
/**
* Flag to indicate whether to disable sending the Scoping element.
*
/**
* If pass AuthnContextClassRef back to the IdPs in front of the SP/IdP Proxy.
*
* @var bool
*/
private bool $passAuthnContextClassRef;
/**
* A list of supported protocols.
*
private array $protocols = [Constants::NS_SAMLP];
/**
* Constructor for SAML SP authentication source.
*
* @param array $info Information about this authentication source.
* @param array $config Configuration.
*/
public function __construct(array $info, array $config)
{
// Call the parent constructor first, as required by the interface
parent::__construct($info, $config);
/* For compatibility with code that assumes that $metadata->getString('entityid')
* gives the entity id. */
$config['entityid'] = $config['entityID'];
$this->metadata = Configuration::loadFromArray(
'authsources[' . var_export($this->authId, true) . ']'
$entityId = $this->metadata->getString('entityID');
Assert::validURI($entityId);
Assert::maxLength(
$entityId,
Constants::SAML2INT_ENTITYID_MAX_LENGTH,
sprintf('The entityID cannot be longer than %d characters.', Constants::SAML2INT_ENTITYID_MAX_LENGTH)
Assert::notEq(
$entityId,
'https://myapp.example.org/',
'Please set a valid and unique entityID',
);
$this->idp = $this->metadata->getOptionalString('idp', null);
$this->discoURL = $this->metadata->getOptionalString('discoURL', null);
$this->disable_scoping = $this->metadata->getOptionalBoolean('disable_scoping', false);
$this->passAuthnContextClassRef = $this->metadata->getOptionalBoolean(
'proxymode.passAuthnContextClassRef',
false
);
/**
* Retrieve the URL to the metadata of this SP.
*
* @return string The metadata URL.
*/
return Module::getModuleURL('saml/sp/metadata/' . urlencode($this->authId));
/**
* Retrieve the entity id of this SP.
*
* @return string The entity id of this SP.
*/
* Retrieve the metadata array of this SP, as a remote IdP would see it.
* @return array The metadata array for its use by a remote IdP.
$entityid = $this->getEntityId();
$metadata = [
'entityid' => $entityid,
'SingleLogoutService' => $this->getSLOEndpoints(),
'AssertionConsumerService' => $this->getACSEndpoints(),
];
// add NameIDPolicy
if ($this->metadata->hasValue('NameIDPolicy')) {
$format = $this->metadata->getValue('NameIDPolicy');
if (is_array($format)) {
$metadata['NameIDFormat'] = Configuration::loadFromArray($format)->getOptionalString(
'Format',
Constants::NAMEID_TRANSIENT
);
} elseif (is_string($format)) {
$metadata['NameIDFormat'] = $format;
}
}
// add attributes
$name = $this->metadata->getOptionalLocalizedString('name', null);
$attributes = $this->metadata->getOptionalArray('attributes', []);
if ($name !== null) {
if (!empty($attributes)) {
$metadata['name'] = $name;
$metadata['attributes'] = $attributes;
if ($this->metadata->hasValue('attributes.required')) {
$metadata['attributes.required'] = $this->metadata->getArray('attributes.required');
}
if ($this->metadata->hasValue('description')) {
$metadata['description'] = $this->metadata->getArray('description');
}
if ($this->metadata->hasValue('attributes.NameFormat')) {
$metadata['attributes.NameFormat'] = $this->metadata->getString('attributes.NameFormat');
}
if ($this->metadata->hasValue('attributes.index')) {
$metadata['attributes.index'] = $this->metadata->getInteger('attributes.index');
}
if ($this->metadata->hasValue('attributes.isDefault')) {
$metadata['attributes.isDefault'] = $this->metadata->getBoolean('attributes.isDefault');
}
}
}
// add organization info
$org = $this->metadata->getOptionalLocalizedString('OrganizationName', null);
if ($org !== null) {
Loading
Loading full blame...