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
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
GitLab 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
f4277ec2
Commit
f4277ec2
authored
Aug 3, 2015
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Reformat SimpleSAML_Auth_Source.
parent
8be35a61
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SimpleSAML/Auth/Source.php
+367
-344
367 additions, 344 deletions
lib/SimpleSAML/Auth/Source.php
with
367 additions
and
344 deletions
lib/SimpleSAML/Auth/Source.php
+
367
−
344
View file @
f4277ec2
<?php
<?php
/**
/**
* This class defines a base class for authentication source.
* This class defines a base class for authentication source.
*
*
...
@@ -8,7 +9,8 @@
...
@@ -8,7 +9,8 @@
* @author Olav Morken, UNINETT AS.
* @author Olav Morken, UNINETT AS.
* @package simpleSAMLphp
* @package simpleSAMLphp
*/
*/
abstract
class
SimpleSAML_Auth_Source
{
abstract
class
SimpleSAML_Auth_Source
{
/**
/**
...
@@ -29,7 +31,8 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -29,7 +31,8 @@ abstract class SimpleSAML_Auth_Source {
* @param array $info Information about this authentication source.
* @param array $info Information about this authentication source.
* @param array &$config Configuration for this authentication source.
* @param array &$config Configuration for this authentication source.
*/
*/
public
function
__construct
(
$info
,
&
$config
)
{
public
function
__construct
(
$info
,
&
$config
)
{
assert
(
'is_array($info)'
);
assert
(
'is_array($info)'
);
assert
(
'is_array($config)'
);
assert
(
'is_array($config)'
);
...
@@ -42,10 +45,12 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -42,10 +45,12 @@ abstract class SimpleSAML_Auth_Source {
* Get sources of a specific type.
* Get sources of a specific type.
*
*
* @param string $type The type of the authentication source.
* @param string $type The type of the authentication source.
*
* @return SimpleSAML_Auth_Source[] Array of SimpleSAML_Auth_Source objects of the specified type.
* @return SimpleSAML_Auth_Source[] Array of SimpleSAML_Auth_Source objects of the specified type.
* @throws Exception If the authentication source is invalid.
* @throws Exception If the authentication source is invalid.
*/
*/
public
static
function
getSourcesOfType
(
$type
)
{
public
static
function
getSourcesOfType
(
$type
)
{
assert
(
'is_string($type)'
);
assert
(
'is_string($type)'
);
$config
=
SimpleSAML_Configuration
::
getConfig
(
'authsources.php'
);
$config
=
SimpleSAML_Configuration
::
getConfig
(
'authsources.php'
);
...
@@ -57,8 +62,10 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -57,8 +62,10 @@ abstract class SimpleSAML_Auth_Source {
$source
=
$config
->
getArray
(
$id
);
$source
=
$config
->
getArray
(
$id
);
if
(
!
array_key_exists
(
0
,
$source
)
||
!
is_string
(
$source
[
0
]))
{
if
(
!
array_key_exists
(
0
,
$source
)
||
!
is_string
(
$source
[
0
]))
{
throw
new
Exception
(
'Invalid authentication source \''
.
$id
.
throw
new
Exception
(
'\': First element must be a string which identifies the authentication source.'
);
'Invalid authentication source \''
.
$id
.
'\': First element must be a string which identifies the authentication source.'
);
}
}
if
(
$source
[
0
]
!==
$type
)
{
if
(
$source
[
0
]
!==
$type
)
{
...
@@ -77,8 +84,8 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -77,8 +84,8 @@ abstract class SimpleSAML_Auth_Source {
*
*
* @return string The ID of this authentication source.
* @return string The ID of this authentication source.
*/
*/
public
function
getAuthId
()
{
public
function
getAuthId
()
{
return
$this
->
authId
;
return
$this
->
authId
;
}
}
...
@@ -108,10 +115,11 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -108,10 +115,11 @@ abstract class SimpleSAML_Auth_Source {
*
*
* @param array &$state Information about the current authentication.
* @param array &$state Information about the current authentication.
*/
*/
public
function
reauthenticate
(
array
&
$state
)
{
public
function
reauthenticate
(
array
&
$state
)
{
assert
(
'isset($state["ReturnCallback"])'
);
assert
(
'isset($state["ReturnCallback"])'
);
/* T
he default implementation just copies over the previous authentication data
. */
// t
he default implementation just copies over the previous authentication data
$session
=
SimpleSAML_Session
::
getSessionFromRequest
();
$session
=
SimpleSAML_Session
::
getSessionFromRequest
();
$data
=
$session
->
getAuthState
(
$this
->
authId
);
$data
=
$session
->
getAuthState
(
$this
->
authId
);
foreach
(
$data
as
$k
=>
$v
)
{
foreach
(
$data
as
$k
=>
$v
)
{
...
@@ -129,7 +137,8 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -129,7 +137,8 @@ abstract class SimpleSAML_Auth_Source {
*
*
* @param array &$state Information about the current authentication.
* @param array &$state Information about the current authentication.
*/
*/
public
static
function
completeAuth
(
&
$state
)
{
public
static
function
completeAuth
(
&
$state
)
{
assert
(
'is_array($state)'
);
assert
(
'is_array($state)'
);
assert
(
'array_key_exists("LoginCompletedHandler", $state)'
);
assert
(
'array_key_exists("LoginCompletedHandler", $state)'
);
...
@@ -139,7 +148,7 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -139,7 +148,7 @@ abstract class SimpleSAML_Auth_Source {
assert
(
'is_callable($func)'
);
assert
(
'is_callable($func)'
);
call_user_func
(
$func
,
$state
);
call_user_func
(
$func
,
$state
);
assert
(
FALSE
);
assert
(
false
);
}
}
...
@@ -156,10 +165,10 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -156,10 +165,10 @@ abstract class SimpleSAML_Auth_Source {
*
*
* @param array &$state Information about the current logout operation.
* @param array &$state Information about the current logout operation.
*/
*/
public
function
logout
(
&
$state
)
{
public
function
logout
(
&
$state
)
{
assert
(
'is_array($state)'
);
assert
(
'is_array($state)'
);
// default logout handler which doesn't do anything
/* Default logout handler which doesn't do anything. */
}
}
...
@@ -172,7 +181,8 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -172,7 +181,8 @@ abstract class SimpleSAML_Auth_Source {
*
*
* @param array &$state Information about the current authentication.
* @param array &$state Information about the current authentication.
*/
*/
public
static
function
completeLogout
(
&
$state
)
{
public
static
function
completeLogout
(
&
$state
)
{
assert
(
'is_array($state)'
);
assert
(
'is_array($state)'
);
assert
(
'array_key_exists("LogoutCompletedHandler", $state)'
);
assert
(
'array_key_exists("LogoutCompletedHandler", $state)'
);
...
@@ -182,7 +192,7 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -182,7 +192,7 @@ abstract class SimpleSAML_Auth_Source {
assert
(
'is_callable($func)'
);
assert
(
'is_callable($func)'
);
call_user_func
(
$func
,
$state
);
call_user_func
(
$func
,
$state
);
assert
(
FALSE
);
assert
(
false
);
}
}
...
@@ -194,20 +204,23 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -194,20 +204,23 @@ abstract class SimpleSAML_Auth_Source {
*
*
* @param string $authId The authentication source identifier.
* @param string $authId The authentication source identifier.
* @param array $config The configuration.
* @param array $config The configuration.
*
* @return SimpleSAML_Auth_Source The parsed authentication source.
* @return SimpleSAML_Auth_Source The parsed authentication source.
* @throws Exception If the authentication source is invalid.
* @throws Exception If the authentication source is invalid.
*/
*/
private
static
function
parseAuthSource
(
$authId
,
$config
)
{
private
static
function
parseAuthSource
(
$authId
,
$config
)
{
assert
(
'is_string($authId)'
);
assert
(
'is_string($authId)'
);
assert
(
'is_array($config)'
);
assert
(
'is_array($config)'
);
if
(
!
array_key_exists
(
0
,
$config
)
||
!
is_string
(
$config
[
0
]))
{
if
(
!
array_key_exists
(
0
,
$config
)
||
!
is_string
(
$config
[
0
]))
{
throw
new
Exception
(
'Invalid authentication source \''
.
$authId
.
throw
new
Exception
(
'\': First element must be a string which identifies the authentication source.'
);
'Invalid authentication source \''
.
$authId
.
'\': First element must be a string which identifies the authentication source.'
);
}
}
$className
=
SimpleSAML_Module
::
resolveClass
(
$config
[
0
],
'Auth_Source'
,
$className
=
SimpleSAML_Module
::
resolveClass
(
$config
[
0
],
'Auth_Source'
,
'SimpleSAML_Auth_Source'
);
'SimpleSAML_Auth_Source'
);
$info
=
array
(
'AuthId'
=>
$authId
);
$info
=
array
(
'AuthId'
=>
$authId
);
unset
(
$config
[
0
]);
unset
(
$config
[
0
]);
...
@@ -228,36 +241,42 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -228,36 +241,42 @@ abstract class SimpleSAML_Auth_Source {
*
*
* @param string $authId The authentication source identifier.
* @param string $authId The authentication source identifier.
* @param string|NULL $type The type of authentication source. If NULL, any type will be accepted.
* @param string|NULL $type The type of authentication source. If NULL, any type will be accepted.
*
* @return SimpleSAML_Auth_Source|NULL The AuthSource object, or NULL if no authentication
* @return SimpleSAML_Auth_Source|NULL The AuthSource object, or NULL if no authentication
* source with the given identifier is found.
* source with the given identifier is found.
* @throws SimpleSAML_Error_Exception If no such authentication source is found or it is invalid.
* @throws SimpleSAML_Error_Exception If no such authentication source is found or it is invalid.
*/
*/
public
static
function
getById
(
$authId
,
$type
=
NULL
)
{
public
static
function
getById
(
$authId
,
$type
=
null
)
{
assert
(
'is_string($authId)'
);
assert
(
'is_string($authId)'
);
assert
(
'is_null($type) || is_string($type)'
);
assert
(
'is_null($type) || is_string($type)'
);
/* F
or now - load and parse config file
. */
// f
or now - load and parse config file
$config
=
SimpleSAML_Configuration
::
getConfig
(
'authsources.php'
);
$config
=
SimpleSAML_Configuration
::
getConfig
(
'authsources.php'
);
$authConfig
=
$config
->
getArray
(
$authId
,
NULL
);
$authConfig
=
$config
->
getArray
(
$authId
,
null
);
if
(
$authConfig
===
NULL
)
{
if
(
$authConfig
===
null
)
{
if
(
$type
!==
NULL
)
{
if
(
$type
!==
null
)
{
throw
new
SimpleSAML_Error_Exception
(
'No authentication source with id '
.
throw
new
SimpleSAML_Error_Exception
(
var_export
(
$authId
,
TRUE
)
.
' found.'
);
'No authentication source with id '
.
var_export
(
$authId
,
true
)
.
' found.'
);
}
}
return
NULL
;
return
null
;
}
}
$ret
=
self
::
parseAuthSource
(
$authId
,
$authConfig
);
$ret
=
self
::
parseAuthSource
(
$authId
,
$authConfig
);
if
(
$type
===
NULL
||
$ret
instanceof
$type
)
{
if
(
$type
===
null
||
$ret
instanceof
$type
)
{
return
$ret
;
return
$ret
;
}
}
/* The authentication source doesn't have the correct type. */
// the authentication source doesn't have the correct type
throw
new
SimpleSAML_Error_Exception
(
'Invalid type of authentication source '
.
throw
new
SimpleSAML_Error_Exception
(
var_export
(
$authId
,
TRUE
)
.
'. Was '
.
var_export
(
get_class
(
$ret
),
TRUE
)
.
'Invalid type of authentication source '
.
', should be '
.
var_export
(
$type
,
TRUE
)
.
'.'
);
var_export
(
$authId
,
true
)
.
'. Was '
.
var_export
(
get_class
(
$ret
),
true
)
.
', should be '
.
var_export
(
$type
,
true
)
.
'.'
);
}
}
...
@@ -273,12 +292,13 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -273,12 +292,13 @@ abstract class SimpleSAML_Auth_Source {
* @param string $assoc The identifier for this logout association.
* @param string $assoc The identifier for this logout association.
* @param array $state The state array passed to the authenticate-function.
* @param array $state The state array passed to the authenticate-function.
*/
*/
protected
function
addLogoutCallback
(
$assoc
,
$state
)
{
protected
function
addLogoutCallback
(
$assoc
,
$state
)
{
assert
(
'is_string($assoc)'
);
assert
(
'is_string($assoc)'
);
assert
(
'is_array($state)'
);
assert
(
'is_array($state)'
);
if
(
!
array_key_exists
(
'LogoutCallback'
,
$state
))
{
if
(
!
array_key_exists
(
'LogoutCallback'
,
$state
))
{
/* T
he authentication requester doesn't have a logout callback
. */
// t
he authentication requester doesn't have a logout callback
return
;
return
;
}
}
$callback
=
$state
[
'LogoutCallback'
];
$callback
=
$state
[
'LogoutCallback'
];
...
@@ -296,10 +316,13 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -296,10 +316,13 @@ abstract class SimpleSAML_Auth_Source {
'state'
=>
$callbackState
,
'state'
=>
$callbackState
,
);
);
$session
=
SimpleSAML_Session
::
getSessionFromRequest
();
$session
=
SimpleSAML_Session
::
getSessionFromRequest
();
$session
->
setData
(
'SimpleSAML_Auth_Source.LogoutCallbacks'
,
$id
,
$data
,
$session
->
setData
(
SimpleSAML_Session
::
DATA_TIMEOUT_SESSION_END
);
'SimpleSAML_Auth_Source.LogoutCallbacks'
,
$id
,
$data
,
SimpleSAML_Session
::
DATA_TIMEOUT_SESSION_END
);
}
}
...
@@ -313,7 +336,8 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -313,7 +336,8 @@ abstract class SimpleSAML_Auth_Source {
*
*
* @param string $assoc The logout association which should be called.
* @param string $assoc The logout association which should be called.
*/
*/
protected
function
callLogoutCallback
(
$assoc
)
{
protected
function
callLogoutCallback
(
$assoc
)
{
assert
(
'is_string($assoc)'
);
assert
(
'is_string($assoc)'
);
$id
=
strlen
(
$this
->
authId
)
.
':'
.
$this
->
authId
.
$assoc
;
$id
=
strlen
(
$this
->
authId
)
.
':'
.
$this
->
authId
.
$assoc
;
...
@@ -321,8 +345,8 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -321,8 +345,8 @@ abstract class SimpleSAML_Auth_Source {
$session
=
SimpleSAML_Session
::
getSessionFromRequest
();
$session
=
SimpleSAML_Session
::
getSessionFromRequest
();
$data
=
$session
->
getData
(
'SimpleSAML_Auth_Source.LogoutCallbacks'
,
$id
);
$data
=
$session
->
getData
(
'SimpleSAML_Auth_Source.LogoutCallbacks'
,
$id
);
if
(
$data
===
NULL
)
{
if
(
$data
===
null
)
{
/*
FIXME: fix for IdP-first flow (issue 397) -> reevaluate logout callback infrastructure
*/
//
FIXME: fix for IdP-first flow (issue 397) -> reevaluate logout callback infrastructure
$session
->
doLogout
(
$this
->
authId
);
$session
->
doLogout
(
$this
->
authId
);
return
;
return
;
...
@@ -345,11 +369,10 @@ abstract class SimpleSAML_Auth_Source {
...
@@ -345,11 +369,10 @@ abstract class SimpleSAML_Auth_Source {
*
*
* @return array The id of all authentication sources.
* @return array The id of all authentication sources.
*/
*/
public
static
function
getSources
()
{
public
static
function
getSources
()
{
$config
=
SimpleSAML_Configuration
::
getOptionalConfig
(
'authsources.php'
);
$config
=
SimpleSAML_Configuration
::
getOptionalConfig
(
'authsources.php'
);
return
$config
->
getOptions
();
return
$config
->
getOptions
();
}
}
}
}
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