Created
October 28, 2011 04:20
-
-
Save rimian/1321609 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file tamauth.module | |
* | |
* Authenticate with Tivoli | |
* | |
* @see http://www-01.ibm.com/software/tivoli | |
*/ | |
/** | |
* Implements hook_menu(). | |
*/ | |
function tamauth_menu() { | |
$items['user/tam'] = array( | |
'title' => 'TAM Authentication', | |
'page callback' => 'tamauth_page', | |
'access callback' => TRUE, | |
'type' => MENU_CALLBACK, | |
); | |
return $items; | |
} | |
/** | |
* Access callback | |
* | |
* @return TRUE if not anon. | |
*/ | |
function tamauth_access() { | |
$account = user_load_by_name($_SERVER['HTTP_IV_USER']); | |
return TRUE; | |
} | |
/** | |
* Page callback | |
* | |
* @todo return error when authentication fails | |
* @todo redirect to an admin page | |
*/ | |
function tamauth_page() { | |
// exit(); | |
return 'hi there'; | |
if(!tamauth_access($_SERVER['HTTP_IV_USER']) ) { | |
// return emtpy with set message error | |
} | |
//group synch | |
// | |
//drupal_goto('admin');//factor out into varget or something | |
} | |
/** | |
* Drush callback. Authenticate. | |
* | |
* @todo move me to drush inc | |
* @todo returning something from drupal page callback makes this fail. perhaps another callback or returning something here. | |
* @todo return STDERR on error. | |
*/ | |
function drush_tamauth() { | |
global $base_url; | |
$name = tamauth_get_option('name'); | |
$url = $base_url .'/user/tam'; | |
$headers = array( | |
'iv-user' => $name, | |
); | |
$result = drupal_http_request($url, array('headers' => $headers)); | |
drush_print($result->code == 200 ? $result->headers['set-cookie'] : 'error '. $result->code); | |
} | |
/** | |
* Authenticate a user | |
* | |
* @param | |
* Username | |
* @return | |
* TRUE if authenticate | |
*/ | |
function tamauth_login($name) { | |
$account = user_load_by_name($name); | |
if($account->uid == 0) { | |
return FALSE; | |
} | |
$form_state['uid'] = $account->uid; | |
//TODO check response from this | |
user_login_submit(array(), $form_state); | |
return TRUE; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment