You are here

public function MiniorangeSPInformation::submitForm in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 8

Configure IdP.

Overrides FormInterface::submitForm

File

src/Form/MiniorangeSPInformation.php, line 281
Contains \Drupal\miniorange_saml\Form\MiniorangeSPInformation.

Class

MiniorangeSPInformation

Namespace

Drupal\miniorange_saml\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  global $base_url;
  $form_values = $form_state
    ->getValues();
  $issuer = $form_values['miniorange_saml_idp_issuer'];
  $idp_name = $form_values['miniorange_saml_idp_name'];
  $nameid_format = 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified';
  $login_url = $form_values['miniorange_saml_idp_login_url'];
  $x509_cert_value = Utilities::sanitize_certificate($form_values['miniorange_saml_idp_x509_certificate']);
  $enable_login_value = $form_values['miniorange_saml_enable_login'];
  $enable_signed_response = $form_values['miniorange_saml_enable_sign_check'];
  if (empty($idp_name) || empty($issuer) || empty($login_url)) {
    \Drupal::messenger()
      ->addMessage(t('The <b><u>Identity Provider Name, IdP Entity ID or Issuer</u></b> and <b><u>SAML Login URL</u></b> fields are mandatory.'), 'error');
    return;
  }
  $enable_login = $enable_login_value == 1 ? TRUE : FALSE;
  $sp_issuer = $base_url . '/samlassertion';
  \Drupal::configFactory()
    ->getEditable('miniorange_saml.settings')
    ->set('miniorange_saml_base', $base_url)
    ->save();
  \Drupal::configFactory()
    ->getEditable('miniorange_saml.settings')
    ->set('miniorange_saml_idp_name', $idp_name)
    ->save();
  \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', str_replace(' ', '', $issuer))
    ->save();
  \Drupal::configFactory()
    ->getEditable('miniorange_saml.settings')
    ->set('miniorange_saml_nameid_format', $nameid_format)
    ->save();
  \Drupal::configFactory()
    ->getEditable('miniorange_saml.settings')
    ->set('miniorange_saml_idp_login_url', str_replace(' ', '', $login_url))
    ->save();
  \Drupal::configFactory()
    ->getEditable('miniorange_saml.settings')
    ->set('miniorange_saml_idp_x509_certificate', $x509_cert_value)
    ->save();
  \Drupal::configFactory()
    ->getEditable('miniorange_saml.settings')
    ->set('miniorange_saml_enable_login', $enable_login)
    ->save();
  \Drupal::messenger()
    ->addStatus(t('Identity Provider Configuration successfully saved'));
}