public function MiniorangeSPInformation::upload_metadata in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 8
2 calls to MiniorangeSPInformation::upload_metadata()
File
- src/
Form/ MiniorangeSPInformation.php, line 339 - Contains \Drupal\miniorange_saml\Form\MiniorangeSPInformation.
Class
Namespace
Drupal\miniorange_saml\FormCode
public function upload_metadata($file) {
global $base_url;
$idp_name_stored = \Drupal::config('miniorange_saml.settings')
->get('miniorange_saml_idp_name');
if (empty($idp_name_stored)) {
\Drupal::configFactory()
->getEditable('miniorange_saml.settings')
->set('miniorange_saml_idp_name', 'Identity Provider')
->save();
}
$document = new \DOMDocument();
$document
->loadXML($file);
restore_error_handler();
$first_child = $document->firstChild;
if (!empty($first_child)) {
$metadata = new MetadataReader($document);
$identity_providers = $metadata
->getIdentityProviders();
if (empty($identity_providers)) {
\Drupal::messenger()
->addMessage(t('Please provide a valid metadata file.'), 'error');
return;
}
foreach ($identity_providers as $key => $idp) {
$saml_login_url = $idp
->getLoginURL('HTTP-Redirect');
if (empty($saml_login_url)) {
$saml_login_url = $idp
->getLoginURL('HTTP-POST');
}
$saml_issuer = $idp
->getEntityID();
$saml_x509_certificate = $idp
->getSigningCertificate();
$sp_issuer = $base_url;
\Drupal::configFactory()
->getEditable('miniorange_saml.settings')
->set('miniorange_saml_sp_issuer', $sp_issuer)
->save();
\Drupal::configFactory()
->getEditable('miniorange_saml.settings')
->set('miniorange_saml_idp_issuer', $saml_issuer)
->save();
\Drupal::configFactory()
->getEditable('miniorange_saml.settings')
->set('miniorange_saml_idp_login_url', $saml_login_url)
->save();
\Drupal::configFactory()
->getEditable('miniorange_saml.settings')
->set('miniorange_saml_idp_x509_certificate', $saml_x509_certificate[0])
->save();
}
\Drupal::messenger()
->addStatus(t('Identity Provider Configuration successfully saved.'));
return;
}
else {
\Drupal::messenger()
->addError(t('Please provide a valid metadata file.'));
return;
}
}