From 3c1f4e5b4547be62e18b02f69f63ee23b7542ea6 Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Wed, 6 Oct 2010 14:51:33 +0000 Subject: [PATCH] First, add an option in the Site Information config to tell drupal the site can use SSL. Second, the CAS module will always use SSL when validating a user's ticket. Third, if a user has any roles other than Anonymous or Authenticated User, they will be given SSL links while "mortal" users will use plain http. git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x@227 20a16fea-79d4-4915-8869-1ea9d5ebf173 --- sites/all/modules/unl/unl.module | 31 +++++++++++++++++++++++++++- sites/all/modules/unl/unl_cas.module | 7 ++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/sites/all/modules/unl/unl.module b/sites/all/modules/unl/unl.module index c13336c6..0a7cf5b3 100644 --- a/sites/all/modules/unl/unl.module +++ b/sites/all/modules/unl/unl.module @@ -126,6 +126,18 @@ function unl_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'menu_edit_item' && $form['mlid']['#value'] == 0) { $form['expanded']['#default_value'] = TRUE; } + if ($form_id == 'system_site_information_settings') { + $form['site_information']['https'] = array( + '#type' => 'checkbox', + '#title' => 'SSL Enabled', + '#default_value' => variable_get('https', FALSE), + ); + $form['#submit'][] = 'unl_system_settings_form_submit'; + } +} + +function unl_system_settings_form_submit($form, &$form_state) { + variable_set('https', (bool) $form_state['values']['https']); } function unl_theme() { @@ -136,6 +148,23 @@ function unl_theme() { ); } - +function unl_url_outbound_alter(&$path, &$options, $original_path) { + $path_parts = parse_url($path); + if (isset($path_parts['scheme']) || $path == 'user/cas') { + return; + } + + $user = $GLOBALS['user']; + $user_roles = array_keys($user->roles); + $generic_user = TRUE; + foreach ($user_roles as $user_role) { + if (in_array($user_role, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { + continue; + } + $generic_user = FALSE; + } + + $options['https'] = (bool) (variable_get('https', 0) && !$generic_user); +} diff --git a/sites/all/modules/unl/unl_cas.module b/sites/all/modules/unl/unl_cas.module index 76ce8fd0..339d9e6e 100644 --- a/sites/all/modules/unl/unl_cas.module +++ b/sites/all/modules/unl/unl_cas.module @@ -31,7 +31,12 @@ function unl_cas_init() { function unl_cas_get_adapter() { static $adapter; if (!$adapter) { - $adapter = new Unl_Cas(url('user/cas', array('absolute' => TRUE)), 'https://login.unl.edu/cas'); + if (variable_get('https', FALSE)) { + $url = url('user/cas', array('absolute' => TRUE, 'https' => TRUE)); + } else { + $url = url('user/cas', array('absolute' => TRUE)); + } + $adapter = new Unl_Cas($url, 'https://login.unl.edu/cas'); } return $adapter; } -- GitLab