You are here

cas.install in CAS 2.x

The Drupal install file.

File

cas.install
View source
<?php

/**
 * @file
 * The Drupal install file.
 */
use Drupal\Core\Database\Database;

/**
 * Implements hook_schema().
 */
function cas_schema() {
  $schema = [];
  $schema['cas_login_data'] = [
    'description' => "Store CAS login data for single sign out purposes.",
    'fields' => [
      'sid' => [
        'description' => "A session ID (hashed). The value is generated by Drupal's session handlers.",
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ],
      'plainsid' => [
        'description' => 'An unhashed session ID.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ],
      'ticket' => [
        'description' => "A CAS service ticket.",
        'type' => 'varchar',
        'length' => 256,
        'not null' => TRUE,
        'default' => '',
      ],
      'created' => [
        'description' => 'The timestamp when this user session was created.',
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
      ],
    ],
    'primary key' => [
      'sid',
    ],
    'indexes' => [
      'ticket' => [
        'sid',
      ],
    ],
    'foreign keys' => [
      'session_user' => [
        'table' => 'session',
        'columns' => [
          'sid' => 'sid',
        ],
      ],
    ],
  ];
  $schema['cas_pgt_storage'] = [
    // Database table for storing PGT/PGTIOU relationships.
    'description' => 'Stores PGT/PGTIOU relationships.',
    'fields' => [
      'pgt_iou' => [
        'description' => 'PGTIOU is the key returned from the CAS server for the PGT',
        'type' => 'varchar_ascii',
        'length' => 256,
        'not null' => TRUE,
      ],
      'pgt' => [
        'description' => 'The actual ProxyGrantingTicket value.',
        'type' => 'varchar_ascii',
        'length' => 256,
        'not null' => TRUE,
      ],
      'timestamp' => [
        'description' => 'Created time. Used to delete unused, stale PGTs',
        'type' => 'int',
        'not null' => TRUE,
      ],
    ],
    'unique keys' => [
      'pgtiou_pgt' => [
        'pgt_iou',
        'pgt',
      ],
    ],
    'primary key' => [
      'pgt_iou',
    ],
  ];
  return $schema;
}

/**
 * Adds the 'created' field to the cas_login_data table and new related config.
 */
function cas_update_8001(&$sandbox) {
  $created_spec = [
    'type' => 'int',
    'description' => 'The timestamp when this user session was created.',
    'length' => 11,
    'not null' => TRUE,
  ];
  $schema = Database::getConnection()
    ->schema();
  $schema
    ->addField('cas_login_data', 'created', $created_spec);
  $config_factory = \Drupal::configFactory();
  $config = $config_factory
    ->getEditable('cas.settings');
  $config
    ->set('logout.single_logout_session_lifetime', 25);
  $config
    ->save(TRUE);
}

/**
 * Rename the configuration setting for debug log.
 */
function cas_update_8002(&$sandbox) {
  $config_factory = \Drupal::configFactory();
  $config = $config_factory
    ->getEditable('cas.settings');
  $config
    ->set('advanced.debug_log', $config
    ->get('debugging.log'));
  $config
    ->clear('debugging');
  $config
    ->save();
}

/**
 * Disable the newly added "prevent normal login" feature.
 */
function cas_update_8003() {
  $config_factory = \Drupal::configFactory();
  $config = $config_factory
    ->getEditable('cas.settings');

  // Even though this is a recommended feature to turn on, we don't want to
  // break any sites that may be relying on normal login working for CASified
  // accounts.
  $config
    ->set('user_accounts.prevent_normal_login', FALSE);
  $config
    ->save();
}

/**
 * Set new 'protocol' config option to HTTPS.
 */
function cas_update_8004() {
  $config_factory = \Drupal::configFactory();
  $config = $config_factory
    ->getEditable('cas.settings');
  $config
    ->set('server.protocol', 'https');
  $config
    ->save();
}

/**
 * Set CAS login and error message defaults.
 */
function cas_update_8005() {
  $config = \Drupal::configFactory()
    ->getEditable('cas.settings');
  $config
    ->set('login_success_message', 'You have been logged in.');

  // Instead of displaying the same error message for all users, we allow admins
  // to specify different messages for different situations. To keep the
  // previous behavior for existing sites, set all the new messages to the old
  // one.
  $previous_default_message = 'There was a problem logging in, please contact a site administrator.';
  $config
    ->set('error_handling.message_validation_failure', $previous_default_message);
  $config
    ->set('error_handling.message_no_local_account', $previous_default_message);
  $config
    ->set('error_handling.message_subscriber_denied_reg', $previous_default_message);
  $config
    ->set('error_handling.message_account_blocked', $previous_default_message);
  $config
    ->set('error_handling.message_subscriber_denied_login', $previous_default_message);
  $config
    ->set('error_handling.message_username_already_exists', $previous_default_message);
  $config
    ->save();
}

Functions

Namesort descending Description
cas_schema Implements hook_schema().
cas_update_8001 Adds the 'created' field to the cas_login_data table and new related config.
cas_update_8002 Rename the configuration setting for debug log.
cas_update_8003 Disable the newly added "prevent normal login" feature.
cas_update_8004 Set new 'protocol' config option to HTTPS.
cas_update_8005 Set CAS login and error message defaults.