function saml_sp__get_settings in SAML Service Provider 8.2
Same name and namespace in other branches
- 8.3 saml_sp.module \saml_sp__get_settings()
- 7.8 saml_sp.module \saml_sp__get_settings()
- 7 saml_sp.module \saml_sp__get_settings()
- 7.2 saml_sp.module \saml_sp__get_settings()
- 7.3 saml_sp.module \saml_sp__get_settings()
- 4.x saml_sp.module \saml_sp__get_settings()
- 3.x saml_sp.module \saml_sp__get_settings()
Get the SAML settings for an IdP.
Parameters
Object $idp: An IDP object, such as that provided by saml_sp_idp_load($machine_name).
Return value
OneLogin_Saml_Settings IdP Settings data.
4 calls to saml_sp__get_settings()
- SamlSPController::consume in src/
Controller/ SamlSPController.php - receive data back from the IdP
- saml_sp_start in ./
saml_sp.module - Start a SAML authentication request.
- saml_sp__get_metadata in ./
saml_sp.module - load the settings and get the metadata
- saml_sp__logout in ./
saml_sp.pages.inc - Page callback to initiate the SAML SLO process.
File
- ./
saml_sp.module, line 101 - SAML Service Provider
Code
function saml_sp__get_settings($idp = NULL) {
if (empty($idp)) {
$idp = new Idp(array());
}
$settings = array();
// The consumer endpoint will always be /saml/consume.
$endpoint_url = \Drupal::url('saml_sp.consume', array(), array(
'absolute' => TRUE,
));
$settings['idp']['entityId'] = $idp->id ?: 'none_given';
// URL to login of the IdP server.
$settings['idp']['singleSignOnService']['url'] = $idp->login_url ?: 'https://www.example.com/login';
// URL to logout of the IdP server.
$settings['idp']['singleLogoutService'] = array(
'url' => $idp->logout_url,
'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
);
// The IdP's public x.509 certificate.
if (is_array($idp->x509_cert)) {
// we only need one key, so use the first one
$settings['idp']['x509cert'] = $idp->x509_cert[0] ?: 'blank';
}
else {
$settings['idp']['x509cert'] = $idp->x509_cert ?: 'blank';
}
// The authentication method we want to use with the IdP
$settings['idp']['AuthnContextClassRef'] = $idp->authn_context_class_ref ?: 'blank';
// Name to identify IdP
$settings['idp']['entityId'] = $idp->entity_id ?: 'blank';
$config = \Drupal::config('saml_sp.settings');
$settings['strict'] = (bool) $config
->get('strict');
// Name to identify this application, if none is given use the absolute URL
// instead
$settings['sp']['entityId'] = $config
->get('entity_id') ?: \Drupal::url('user.page', array(), array(
'absolute' => TRUE,
));
// Drupal URL to consume the response from the IdP.
$settings['sp']['assertionConsumerService'] = array(
'url' => $endpoint_url,
'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
);
// Tells the IdP to return the email address of the current user
$settings['sp']['NameIDFormat'] = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress';
// add the contact information for the SP
$settings['contactPerson'] = array();
if (!empty($config
->get('contact.technical.name')) && !empty($config
->get('contact.technical.email'))) {
$settings['contactPerson']['technical'] = array(
'givenName' => $config
->get('contact.technical.name'),
'emailAddress' => $config
->get('contact.technical.email'),
);
}
if (!empty($config
->get('contact.support.name')) && !empty($config
->get('contact.support.email'))) {
$settings['contactPerson']['support'] = array(
'givenName' => $config
->get('contact.support.name'),
'emailAddress' => $config
->get('contact.support.email'),
);
}
// add the organization information
//$organization = variable_get('saml_sp__organization', array());
$settings['organization'] = array(
'en-US' => array(
'name' => $config
->get('organization.name'),
'displayname' => $config
->get('organization.display_name'),
'url' => $config
->get('organization.url'),
),
);
$refs = saml_sp_authn_context_class_refs(TRUE);
$authnContexts = array();
if (isset($idp->authn_context_class_ref) && !empty($idp->authn_context_class_ref)) {
foreach ($idp->authn_context_class_ref as $value) {
if (!empty($value)) {
$authnContexts[] = $refs[$value];
}
}
}
// add the security settings
$settings['security'] = array(
// signatures and encryptions offered
'nameIdEncrypted' => (bool) $config
->get('security.nameIdEncrypted'),
'authnRequestsSigned' => (bool) $config
->get('security.authnRequestsSigned'),
'logoutRequestSigned' => (bool) $config
->get('security.logoutRequestSigned'),
'logoutResponseSigned' => (bool) $config
->get('security.logoutResponseSigned'),
// Sign the Metadata
'signMetadata' => (bool) $config
->get('security.signMetaData'),
// signatures and encryptions required
'wantMessagesSigned' => (bool) $config
->get('security.wantMessagesSigned'),
'wantAssertionsSigned' => (bool) $config
->get('security.wantAssertionsSigned'),
'wantNameIdEncrypted' => (bool) $config
->get('security.wantNameIdEncrypted'),
'signatureAlgorithm' => $config
->get('security.signatureAlgorithm'),
'lowercaseUrlencoding' => (bool) $config
->get('security.lowercaseUrlencoding'),
'requestedAuthnContext' => empty($authnContexts) ? FALSE : $authnContexts,
);
$cert_location = $config
->get('cert_location');
if ($cert_location && file_exists($cert_location)) {
$settings['sp']['x509cert'] = file_get_contents($cert_location);
}
$new_cert_location = $config
->get('new_cert_location');
if ($new_cert_location && file_exists($new_cert_location)) {
$settings['sp']['x509certNew'] = file_get_contents($new_cert_location);
}
// Invoke hook_saml_sp_settings_alter().
\Drupal::moduleHandler()
->alter('saml_sp_settings', $settings);
// we are adding in the private key after the alter function because we don't
// want to risk the private key getting out and in the hands of a rogue module
$key_location = $config
->get('key_location');
if ($key_location && file_exists($key_location)) {
$settings['sp']['privateKey'] = file_get_contents($key_location);
}
return $settings;
}