FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » FUDforum Suggestions » SSO with TYPO3
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Aw: Re: Aw: Re: Aw: Re: Aw: Re: SSO with TYPO3 [message #166298 is a reply to message #166293] Wed, 02 November 2011 10:35 Go to previous message
kaystrobach is currently offline  kaystrobach   
Messages: 28
Registered: May 2006
Location: Bannewitz
Karma:
Junior Member

is db_sab buffering ready, for me it seems, that using that function is the problem, so i replaced it as well.

the following function should be modified for future releases:

function db_all($q)
{
	$r = uq($q);
	if($r) {
		return $r->fetchAll(PDO::FETCH_COLUMN);
	} else {
		return array();
	}
}


i still have the same problem, it always occurs in sso_get_userByUsername

This is my current state (same error and a bit frustrated Very Happy ):

<?php
/*
* Signature-Based Single Sign-On Framework
* TPA Adapter for
* fudforum (http://www.fudforum.org )
*
*  Version            : 3.0.3
*  Last update        : 13.10.2011
*
* (c) Kay Strobach, Bannewitz, Germany
*  http://www.kay-strobach.de
*  http://www.single-signon.com
*/

/**
*  function which is called after including this file in the SSO-Agent.
*
*  @param
*    User_Name    string    Username the Session will be created for
*    remote_addr  string    Remoteaddress of the users system
*    agent        string    Browser
*    sso_url      string    Url where the user will be redirected after establishing a session for him
*    sso_version  string    the protocol version of the calling agent
*    sso_action   string    the action to perform. Right now this is either 'logon' or 'create_modify'
*    sso_userdata string    the userdata submitted by the agent
*
*  @return        string    return the session data
*
*  Leave stubs if you dont need all four params.
*/

/*
* return the protocol version
*/

//include libs
require_once('GLOBALS.php');
require_once($INCLUDE.'../scripts/forum_login.php');
require_once($INCLUDE.'../scripts/fudapi.inc.php');


define('fud_debug', 1);

function get_version(){
	return "2.0";
}

function sso($User_Name,$ip,$agent,$sso_url,$sso_version="",$sso_action="",$sso_userdata="") {
		// alternative: return error
	if ($sso_version == "") return array("Error"=>"sso version out of date");

		//process sso data
	$sso_userdata = process_userdata($sso_userdata);

	__fud_login_common(1);
	$User_ID   = sso_get_userByUsername($User_Name);

	$err = null;

	switch($sso_action){	
		// action: create user / update userdata
		case 'create_modify':
			$vals = array(
				'login' =>$User_Name,
				'passwd'=>md5(microtime(true)),
				'email' =>$sso_userdata['email'],
				'name'  =>$sso_userdata['name']
			);

			

			if(!$User_ID) {
				$User_ID = fud_add_user(
					$vals,
					$err
				);
			} else {
				fud_update_user(
					$User_ID,
					$vals,
					$err
				);
			}
			if(array_key_exists('usergroup', $sso_userdata)) {
				sso_syncGroups($User_ID, explode(',', $sso_userdata['usergroup']));
			}
		break;
		// perform logon for given $User_Name
		case 'logon':
			if (external_fud_login($User_ID)) {
				$return_val    = array();
				$return_val[0] = array();
				$return_val   += array( "redirecturl" => $sso_url);
				return $return_val;
			}
			return array("Error"=>"no account for this user");
		break;
	}
}

/* 
* process the userdata string and return an associative array
* @param string $sso_userdata: the data from fe_users (pipe-separated)
* @return array	$data: the userdata
*/
function process_userdata($sso_userdata){
	$sso_userdata = split("\|",$sso_userdata);
	for ($i=0;$i<count($sso_userdata);$i++) {
		$sso_userdata[$i]=split("=",$sso_userdata[$i]);
		$data[$sso_userdata[$i][0]]=$sso_userdata[$i][1];
	}
	unset ($sso_userdata);
	return $data;
}


function sso_get_userByUsername($login) {
	$r = db_all('SELECT id FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users WHERE login='. _esc($login));
	if(count($r)) {
		return $r[0];
	}
}
function sso_syncGroups($userID, $groupNames) {
		// iterate
	foreach($groupNames as $groupName) {
			// Use special name
		$groupName = 'SSO: ' . $groupName;
			// Check wether group exists
		
		$r = db_all('SELECT id FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'groups WHERE name='. _esc($groupName));
		
		if(count($r)) {
			$groupId = $r[0];
		} else {
			$groupId = ins_m(
				$GLOBALS['DBHOST_TBL_PREFIX'] .'groups',
				'name',
				0,
				array(
					_esc($groupName)
				)
			);
		}
			// Check wether user is in group and add it
		$r = db_all('SELECT id FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'group_members WHERE group_id='. _esc($groupId) . ' AND user_id=' . _esc($userID));
		if(!count($r)) {
			ins_m(
				$GLOBALS['DBHOST_TBL_PREFIX'] .'group_members',
				'group_id, user_id',
				0,
				array(
					_esc($groupId) . ',' . _esc($userID)
				)
			);
		}
	}
		// remove groups which are removed in external adapter
	$list = '';
	foreach($groupNames as $groupName) {
		if($list !== '') {
			$list.= ', ';
		}
		$list.= _esc($groupName);
	}
	$q = '
		SELECT fud_group_members.id 
		FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'group_members 
		LEFT JOIN '. $GLOBALS['DBHOST_TBL_PREFIX'] .'groups ON '. $GLOBALS['DBHOST_TBL_PREFIX'] .'group_members.group_id = fud_groups.id
		WHERE '. $GLOBALS['DBHOST_TBL_PREFIX'] .'group_members.user_id = ' . _esc($userID) . '
		AND '. $GLOBALS['DBHOST_TBL_PREFIX'] .'groups.name NOT IN (' . $list . ')
		AND '. $GLOBALS['DBHOST_TBL_PREFIX'] .'groups.name LIKE "SSO:%"
	';
	$groupsToRemove = db_all($q);
	if(count($groupsToRemove)) {
		foreach($groupsToRemove as $group) {
			echo $group;
			q('DELETE FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'group_members WHERE id = ' . _esc($group));
		}
	}
}
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: RSS 2 Topic
Next Topic: list all smilies on the same page
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 09:01:24 GMT 2024

Total time taken to generate the page: 0.04005 seconds