public function SamlauthConfigureForm::validateForm in SAML Authentication 8.2
Same name and namespace in other branches
- 8.3 src/Form/SamlauthConfigureForm.php \Drupal\samlauth\Form\SamlauthConfigureForm::validateForm()
- 8 src/Form/SamlauthConfigureForm.php \Drupal\samlauth\Form\SamlauthConfigureForm::validateForm()
- 4.x src/Form/SamlauthConfigureForm.php \Drupal\samlauth\Form\SamlauthConfigureForm::validateForm()
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ SamlauthConfigureForm.php, line 426
Class
- SamlauthConfigureForm
- Provides a configuration form for samlauth module settings and IDP/SP info.
Namespace
Drupal\samlauth\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
// @TODO: Validate cert. Might be able to just openssl_x509_parse().
// Validate login/logout redirect URLs.
$login_url_path = $form_state
->getValue('login_redirect_url');
if ($login_url_path) {
$login_url_path = $this->token
->replace($login_url_path);
$login_url = $this->pathValidator
->getUrlIfValidWithoutAccessCheck($login_url_path);
if (!$login_url) {
$form_state
->setErrorByName('login_redirect_url', $this
->t('The Login Redirect URL is not a valid path.'));
}
}
$logout_url_path = $form_state
->getValue('logout_redirect_url');
if ($logout_url_path) {
$logout_url_path = $this->token
->replace($logout_url_path);
$logout_url = $this->pathValidator
->getUrlIfValidWithoutAccessCheck($logout_url_path);
if (!$logout_url) {
$form_state
->setErrorByName('logout_redirect_url', $this
->t('The Logout Redirect URL is not a valid path.'));
}
}
// Validate certs folder. Don't allow the user to save an empty folder; if
// they want to save incomplete config data, they can switch to 'fields'.
$sp_cert_type = $form_state
->getValue('sp_cert_type');
$sp_cert_folder = $this
->fixFolderPath($form_state
->getValue('sp_cert_folder'));
if ($sp_cert_type == 'folder') {
if (empty($sp_cert_folder)) {
$form_state
->setErrorByName('sp_cert_folder', $this
->t('@name field is required.', [
'@name' => $form['service_provider']['sp_cert_folder']['#title'],
]));
}
elseif (!file_exists($sp_cert_folder . '/certs/sp.key') || !file_exists($sp_cert_folder . '/certs/sp.crt')) {
$form_state
->setErrorByName('sp_cert_folder', $this
->t('The Certificate folder does not contain the required certs/sp.key or certs/sp.crt files.'));
}
}
}