本文整理汇总了PHP中SimpleSAML_Session类的典型用法代码示例。如果您正苦于以下问题:PHP SimpleSAML_Session类的具体用法?PHP SimpleSAML_Session怎么用?PHP SimpleSAML_Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleSAML_Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveSession
/**
* Save a session to the data store.
*
* @param SimpleSAML_Session $session The session object we should save.
*/
public function saveSession(SimpleSAML_Session $session)
{
$sessionId = $session->getSessionId();
$config = SimpleSAML_Configuration::getInstance();
$sessionDuration = $config->getInteger('session.duration', 8 * 60 * 60);
$expire = time() + $sessionDuration;
$this->store->set('session', $sessionId, $session, $expire);
}
示例2: newSessionId
/**
* Create and set new session id.
*
* @return string The new session id.
*/
public function newSessionId()
{
$this->session_id = self::createSessionID();
SimpleSAML_Session::createSession($this->session_id);
$this->setCookie($this->cookie_name, $this->session_id);
return $this->session_id;
}
示例3: process
public function process(&$state)
{
assert('is_array($state)');
if (empty($state['Expire']) || empty($state['Authority'])) {
return;
}
$now = time();
$delta = $state['Expire'] - $now;
$globalConfig = SimpleSAML_Configuration::getInstance();
$sessionDuration = $globalConfig->getInteger('session.duration', 8 * 60 * 60);
/* Extend only if half of session duration already passed */
if ($delta >= $sessionDuration * 0.5) {
return;
}
/* Update authority expire time */
$session = SimpleSAML_Session::getSessionFromRequest();
$session->setAuthorityExpire($state['Authority']);
/* Update session cookies duration */
/* If remember me is active */
$rememberMeExpire = $session->getRememberMeExpire();
if (!empty($state['RememberMe']) && $rememberMeExpire !== NULL && $globalConfig->getBoolean('session.rememberme.enable', FALSE)) {
$session->setRememberMeExpire();
return;
}
/* Or if session lifetime is more than zero */
$sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
$cookieParams = $sessionHandler->getCookieParams();
if ($cookieParams['lifetime'] > 0) {
$session->updateSessionCookies();
}
}
示例4: loginComplete
/**
* When login is complete, save the SSPAuthentication object to the session
*/
public final function loginComplete()
{
//Use the same session as SimpleSAMLphp to avoid session state loss
Session::start(SimpleSAML_Session::getInstance()->getSessionId());
Session::set('ssp_current_auth_source', $this->getAuthSource()->getAuthId());
Session::set('ssp_current_auth_class', get_class($this));
Session::save();
}
示例5: getUser
function getUser(SimpleSAML_Session $session, ConfigProxy $janus_config)
{
// Get data from config
/** @var string $useridattr */
$useridattr = $janus_config->getValue('useridattr', 'eduPersonPrincipalName');
// Validate user
$attributes = $session->getAttributes();
// Check if userid exists
if (!isset($attributes[$useridattr])) {
echo json_encode(array('status' => 'user_id_is_missing'));
exit;
}
$userid = $attributes[$useridattr][0];
$user = new sspmod_janus_User();
$user->setUserid($userid);
$user->load(sspmod_janus_User::USERID_LOAD);
return $user;
}
示例6: checkLoggedAndSameAuth
public static function checkLoggedAndSameAuth()
{
$session = SimpleSAML_Session::getSessionFromRequest();
$uregconf = SimpleSAML_Configuration::getConfig('module_selfregister.php');
$asId = $uregconf->getString('auth');
$as = new SimpleSAML_Auth_Simple($asId);
if ($as->isAuthenticated()) {
return $as;
}
return false;
}
示例7: show
/**
* Display this error.
*
* This method displays a standard simpleSAMLphp error page and exits.
*/
public function show()
{
$this->setHTTPCode();
$session = SimpleSAML_Session::getInstance();
if ($this->cause !== NULL) {
$e = $this->cause;
} else {
$e = $this;
}
SimpleSAML_Utilities::fatalError($session->getTrackID(), $this->errorCode, $e);
}
示例8: checkLoggedAndSameAuth
public static function checkLoggedAndSameAuth()
{
$session = SimpleSAML_Session::getInstance();
if ($session->isAuthenticated()) {
$uregconf = SimpleSAML_Configuration::getConfig('module_selfregister.php');
/* Get a reference to our authentication source. */
$asId = $uregconf->getString('auth');
if ($session->getAuthority() == $asId) {
return new SimpleSAML_Auth_Simple($asId);
}
}
return false;
}
示例9: process
/**
* Apply filter to add the UID attribute.
*
* @param array &$request The current request
*/
public function process(&$request)
{
assert('is_array($request)');
assert('array_key_exists("Attributes", $request)');
$authModule = NULL;
// Fetch Auth module
if (array_key_exists("SimpleSAML_Auth_State.stage", $request)) {
$authStage = implode(":", array_slice(explode(':', $request["SimpleSAML_Auth_State.stage"]), 0, -1));
$authId = $authStage . ':AuthId';
$authModule = $request[$authId];
} else {
if (isset($request['AuthnInstant']) && isset($request['Expire'])) {
// Probably dealing with a cached response
$cachedAuthModule = SimpleSAML_Session::getInstance()->getData(sspmod_multiauth_Auth_Source_MultiAuth::SESSION_SOURCE, 'multi');
if ($cachedAuthModule) {
$authModule = $cachedAuthModule;
}
}
}
if (!isset($authModule)) {
throw new Exception("Auth module not found?!?!");
}
$attributes =& $request['Attributes'];
$filter = null;
// Set or replace the filter attribute
if (array_key_exists($authModule, $this->map)) {
$filter = $this->map[$authModule];
}
switch ($filter) {
case 'GOOGLE':
$attributes['uid'] = $this->_useEmailAsUid($attributes);
break;
case 'YAHOO':
$attributes['uid'] = $this->_useEmailAsUid($attributes);
break;
case 'HYVES':
if (!array_key_exists('openid.local_id', $attributes)) {
throw new Exception('No local id attribute provided! Cannot use it as UID');
}
$attributes['uid'] = str_replace('.hyves.nl/', '', str_replace('http://', '', $attributes['openid.local_id']));
break;
default:
if (!array_key_exists('uid', $attributes)) {
throw new Exception('No UID set?!?!');
}
break;
}
}
示例10: initLogoutReturn
/**
* @deprecated This method will be removed in SSP 2.0.
*/
public static function initLogoutReturn($returnURL, $authority)
{
assert('is_string($returnURL)');
assert('is_string($authority)');
$session = SimpleSAML_Session::getSessionFromRequest();
$state = $session->getAuthData($authority, 'LogoutState');
$session->doLogout($authority);
$state['SimpleSAML_Auth_Default.ReturnURL'] = $returnURL;
$state['LogoutCompletedHandler'] = array(get_class(), 'logoutCompleted');
$as = SimpleSAML_Auth_Source::getById($authority);
if ($as === NULL) {
// The authority wasn't an authentication source...
self::logoutCompleted($state);
}
$as->logout($state);
}
示例11: getCookieSessionId
/**
* Retrieve the session id of saved in the session cookie.
*
* @return string The session id saved in the cookie.
*/
public function getCookieSessionId()
{
if ($this->session_id === NULL) {
if (self::hasSessionCookie()) {
/* Attempt to retrieve the session id from the cookie. */
$this->session_id = $_COOKIE[$this->cookie_name];
}
/* Check if we have a valid session id. */
if (!self::isValidSessionID($this->session_id)) {
/* We don't have a valid session. Create a new session id. */
$this->session_id = self::createSessionID();
SimpleSAML_Session::createSession($this->session_id);
$this->setCookie($this->cookie_name, $this->session_id);
}
}
return $this->session_id;
}
示例12: __construct
/**
* Constructor
*
* Note that the person is tied to a session and a simplesaml configuration
* here
*/
function __construct($person = NULL)
{
parent::__construct($person);
/* Find the path to simpelsamlphp and run the autoloader */
try {
$sspdir = Config::get_config('simplesaml_path');
} catch (KeyNotFoundException $knfe) {
echo "Cannot find path to simplesaml. This install is not valid. Aborting.<br />\n";
Logger::logEvent(LOG_ALERT, "Confusa_Auth_IdP", "__construct()", "Trying to instantiate SimpleSAMLphp without a configured path.");
exit(0);
}
require_once $sspdir . '/lib/_autoload.php';
SimpleSAML_Configuration::setConfigDir($sspdir . '/config');
/* start a session needed for the IdP-based AuthN approach */
$this->as = new SimpleSAML_Auth_Simple('default-sp');
$this->session = SimpleSAML_Session::getInstance();
}
示例13: authenticate
/**
* Log-in using Facebook platform
*
* @param array &$state Information about the current authentication.
*/
public function authenticate(&$state)
{
assert('is_array($state)');
/* We are going to need the authId in order to retrieve this authentication source later. */
$state[self::AUTHID] = $this->authId;
$stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
// SimpleSAML_Logger::debug('facebook auth state id = ' . $stateID);
$consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
// Get the request token
$requestToken = $consumer->getRequestToken('http://twitter.com/oauth/request_token');
SimpleSAML_Logger::debug("Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]");
$oauthState = array('requestToken' => serialize($requestToken), 'stateid' => $stateID);
$session = SimpleSAML_Session::getInstance();
$session->setData('oauth', 'oauth', $oauthState);
// Authorize the request token
$consumer->getAuthorizeRequest('http://twitter.com/oauth/authenticate', $requestToken);
}
示例14: __construct
/**
* Initializes this discovery service.
*
* The constructor does the parsing of the request. If this is an invalid request, it will
* throw an exception.
*
* @param array $metadataSets Array with metadata sets we find remote entities in.
* @param string $instance The name of this instance of the discovery service.
*/
public function __construct(array $metadataSets, $instance)
{
assert('is_string($instance)');
/* Initialize standard classes. */
$this->config = SimpleSAML_Configuration::getInstance();
$this->metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
$this->session = SimpleSAML_Session::getSessionFromRequest();
$this->instance = $instance;
$this->metadataSets = $metadataSets;
$this->log('Accessing discovery service.');
/* Standard discovery service parameters. */
if (!array_key_exists('entityID', $_GET)) {
throw new Exception('Missing parameter: entityID');
} else {
$this->spEntityId = $_GET['entityID'];
}
if (!array_key_exists('returnIDParam', $_GET)) {
$this->returnIdParam = 'entityID';
} else {
$this->returnIdParam = $_GET['returnIDParam'];
}
$this->log('returnIdParam initially set to [' . $this->returnIdParam . ']');
if (!array_key_exists('return', $_GET)) {
throw new Exception('Missing parameter: return');
} else {
$this->returnURL = SimpleSAML_Utilities::checkURLAllowed($_GET['return']);
}
$this->isPassive = FALSE;
if (array_key_exists('isPassive', $_GET)) {
if ($_GET['isPassive'] === 'true') {
$this->isPassive = TRUE;
}
}
$this->log('isPassive initially set to [' . ($this->isPassive ? 'TRUE' : 'FALSE') . ']');
if (array_key_exists('IdPentityID', $_GET)) {
$this->setIdPentityID = $_GET['IdPentityID'];
} else {
$this->setIdPentityID = NULL;
}
if (array_key_exists('IDPList', $_REQUEST)) {
$this->scopedIDPList = $_REQUEST['IDPList'];
}
}
示例15: newSessionId
/**
* Create and set new session id.
*
* @return string The new session id.
*/
public function newSessionId()
{
$session_cookie_params = session_get_cookie_params();
if ($session_cookie_params['secure'] && !SimpleSAML_Utilities::isHTTPS()) {
throw new SimpleSAML_Error_Exception('Session start with secure cookie not allowed on http.');
}
if (headers_sent()) {
throw new SimpleSAML_Error_Exception('Cannot create new session - headers already sent.');
}
/* Generate new (secure) session id. */
$sessionId = SimpleSAML_Utilities::stringToHex(SimpleSAML_Utilities::generateRandomBytes(16));
SimpleSAML_Session::createSession($sessionId);
if (session_id() !== '') {
/* Session already started, close it. */
session_write_close();
}
session_id($sessionId);
session_start();
return session_id();
}