Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
13a2ca61
Commit
13a2ca61
authored
9 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Reformat SimpleSAML_AuthMemCookie.
parent
f04f9a2b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SimpleSAML/AuthMemCookie.php
+149
-137
149 additions, 137 deletions
lib/SimpleSAML/AuthMemCookie.php
with
149 additions
and
137 deletions
lib/SimpleSAML/AuthMemCookie.php
+
149
−
137
View file @
13a2ca61
<?php
/**
* This is a helper class for the Auth MemCookie module.
* It handles the configuration, and implements the logout handler.
*
* @author Olav Morken, UNINETT AS.
* @package
s
impleSAMLphp
* @package
S
impleSAMLphp
*/
class
SimpleSAML_AuthMemCookie
{
/**
* @var SimpleSAML_AuthMemCookie This is the singleton instance of this class.
*/
private
static
$instance
=
NULL
;
/**
* @var SimpleSAML_Configuration The configuration for Auth MemCookie.
*/
private
$amcConfig
;
/**
* This function is used to retrieve the singleton instance of this class.
*
* @return SimpleSAML_AuthMemCookie The singleton instance of this class.
*/
public
static
function
getInstance
()
{
if
(
self
::
$instance
===
NULL
)
{
self
::
$instance
=
new
SimpleSAML_AuthMemCookie
();
}
return
self
::
$instance
;
}
/**
* This function implements the constructor for this class. It loads the Auth MemCookie configuration.
*/
private
function
__construct
()
{
/* Load Auth MemCookie configuration. */
$this
->
amcConfig
=
SimpleSAML_Configuration
::
getConfig
(
'authmemcookie.php'
);
}
/**
* Retrieve the authentication source that should be used to authenticate the user.
*
* @return string The login type which should be used for Auth MemCookie.
*/
public
function
getAuthSource
()
{
return
$this
->
amcConfig
->
getString
(
'authsource'
);
}
/**
* This function retrieves the name of the cookie from the configuration.
*
* @return string The name of the cookie.
*/
public
function
getCookieName
()
{
$cookieName
=
$this
->
amcConfig
->
getString
(
'cookiename'
,
'AuthMemCookie'
);
if
(
!
is_string
(
$cookieName
)
||
strlen
(
$cookieName
)
===
0
)
{
throw
new
Exception
(
'Configuration option \'cookiename\' contains an invalid value. This option should be a string.'
);
}
return
$cookieName
;
}
/**
* This function retrieves the name of the attribute which contains the username from the configuration.
*
* @return string The name of the attribute which contains the username.
*/
public
function
getUsernameAttr
()
{
$usernameAttr
=
$this
->
amcConfig
->
getString
(
'username'
,
NULL
);
return
$usernameAttr
;
}
/**
* This function retrieves the name of the attribute which contains the groups from the configuration.
*
* @return string The name of the attribute which contains the groups.
*/
public
function
getGroupsAttr
()
{
$groupsAttr
=
$this
->
amcConfig
->
getString
(
'groups'
,
NULL
);
return
$groupsAttr
;
}
/**
* This function creates and initializes a Memcache object from our configuration.
*
* @return Memcache A Memcache object initialized from our configuration.
*/
public
function
getMemcache
()
{
$memcacheHost
=
$this
->
amcConfig
->
getString
(
'memcache.host'
,
'127.0.0.1'
);
$memcachePort
=
$this
->
amcConfig
->
getInteger
(
'memcache.port'
,
11211
);
$memcache
=
new
Memcache
;
foreach
(
explode
(
','
,
$memcacheHost
)
as
$memcacheHost
)
{
$memcache
->
addServer
(
$memcacheHost
,
$memcachePort
);
}
return
$memcache
;
}
/**
* This function logs the user out by deleting the session information from memcache.
*/
private
function
doLogout
()
{
$cookieName
=
$this
->
getCookieName
();
/* Check if we have a valid cookie. */
if
(
!
array_key_exists
(
$cookieName
,
$_COOKIE
))
{
return
;
}
$sessionID
=
$_COOKIE
[
$cookieName
];
/* Delete the session from memcache. */
$memcache
=
$this
->
getMemcache
();
$memcache
->
delete
(
$sessionID
);
/* Delete the session cookie. */
$sessionHandler
=
SimpleSAML_SessionHandler
::
getSessionHandler
();
$sessionHandler
->
setCookie
(
$cookieName
,
NULL
);
}
/**
* This function implements the logout handler. It deletes the information from Memcache.
*/
public
static
function
logoutHandler
()
{
self
::
getInstance
()
->
doLogout
();
}
class
SimpleSAML_AuthMemCookie
{
/**
* @var SimpleSAML_AuthMemCookie This is the singleton instance of this class.
*/
private
static
$instance
=
null
;
/**
* @var SimpleSAML_Configuration The configuration for Auth MemCookie.
*/
private
$amcConfig
;
/**
* This function is used to retrieve the singleton instance of this class.
*
* @return SimpleSAML_AuthMemCookie The singleton instance of this class.
*/
public
static
function
getInstance
()
{
if
(
self
::
$instance
===
null
)
{
self
::
$instance
=
new
SimpleSAML_AuthMemCookie
();
}
return
self
::
$instance
;
}
/**
* This function implements the constructor for this class. It loads the Auth MemCookie configuration.
*/
private
function
__construct
()
{
// load AuthMemCookie configuration
$this
->
amcConfig
=
SimpleSAML_Configuration
::
getConfig
(
'authmemcookie.php'
);
}
/**
* Retrieve the authentication source that should be used to authenticate the user.
*
* @return string The login type which should be used for Auth MemCookie.
*/
public
function
getAuthSource
()
{
return
$this
->
amcConfig
->
getString
(
'authsource'
);
}
/**
* This function retrieves the name of the cookie from the configuration.
*
* @return string The name of the cookie.
* @throws Exception If the value of the 'cookiename' configuration option is invalid.
*/
public
function
getCookieName
()
{
$cookieName
=
$this
->
amcConfig
->
getString
(
'cookiename'
,
'AuthMemCookie'
);
if
(
!
is_string
(
$cookieName
)
||
strlen
(
$cookieName
)
===
0
)
{
throw
new
Exception
(
"Configuration option 'cookiename' contains an invalid value. This option should be a string."
);
}
return
$cookieName
;
}
/**
* This function retrieves the name of the attribute which contains the username from the configuration.
*
* @return string The name of the attribute which contains the username.
*/
public
function
getUsernameAttr
()
{
$usernameAttr
=
$this
->
amcConfig
->
getString
(
'username'
,
null
);
return
$usernameAttr
;
}
/**
* This function retrieves the name of the attribute which contains the groups from the configuration.
*
* @return string The name of the attribute which contains the groups.
*/
public
function
getGroupsAttr
()
{
$groupsAttr
=
$this
->
amcConfig
->
getString
(
'groups'
,
null
);
return
$groupsAttr
;
}
/**
* This function creates and initializes a Memcache object from our configuration.
*
* @return Memcache A Memcache object initialized from our configuration.
*/
public
function
getMemcache
()
{
$memcacheHost
=
$this
->
amcConfig
->
getString
(
'memcache.host'
,
'127.0.0.1'
);
$memcachePort
=
$this
->
amcConfig
->
getInteger
(
'memcache.port'
,
11211
);
$memcache
=
new
Memcache
;
foreach
(
explode
(
','
,
$memcacheHost
)
as
$memcacheHost
)
{
$memcache
->
addServer
(
$memcacheHost
,
$memcachePort
);
}
return
$memcache
;
}
/**
* This function logs the user out by deleting the session information from memcache.
*/
private
function
doLogout
()
{
$cookieName
=
$this
->
getCookieName
();
// check if we have a valid cookie
if
(
!
array_key_exists
(
$cookieName
,
$_COOKIE
))
{
return
;
}
$sessionID
=
$_COOKIE
[
$cookieName
];
// delete the session from memcache
$memcache
=
$this
->
getMemcache
();
$memcache
->
delete
(
$sessionID
);
// delete the session cookie
$sessionHandler
=
SimpleSAML_SessionHandler
::
getSessionHandler
();
$sessionHandler
->
setCookie
(
$cookieName
,
null
);
}
/**
* This function implements the logout handler. It deletes the information from Memcache.
*/
public
static
function
logoutHandler
()
{
self
::
getInstance
()
->
doLogout
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment