Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP-siple_saml_php_plugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
René Češka
Stud.IP-siple_saml_php_plugin
Commits
3513583c
Commit
3513583c
authored
9 months ago
by
René Češka
Committed by
René Češka
9 months ago
Browse files
Options
Downloads
Plain Diff
Merge branch 'simple-saml-review' into 'SimpleSamlPHP'
Simple saml review See merge request
!1
parents
45c745ef
d92f6b11
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
config/config_defaults.inc.php
+9
-7
9 additions, 7 deletions
config/config_defaults.inc.php
lib/classes/auth_plugins/StudipAuthSimpleSamlPHP.php
+50
-61
50 additions, 61 deletions
lib/classes/auth_plugins/StudipAuthSimpleSamlPHP.php
public/logout.php
+1
-2
1 addition, 2 deletions
public/logout.php
with
60 additions
and
70 deletions
config/config_defaults.inc.php
+
9
−
7
View file @
3513583c
...
@@ -403,13 +403,15 @@ $STUDIP_AUTH_CONFIG_OAUTH2 = [
...
@@ -403,13 +403,15 @@ $STUDIP_AUTH_CONFIG_OAUTH2 = [
],
],
];
];
$STUDIP_AUTH_CONFIG_SIMPLESAMLPHP = array("reverse_proxy_url" => '',
$STUDIP_AUTH_CONFIG_SIMPLESAMLPHP = [
"sp_name" => 'default-sp',
'reverse_proxy_url' => '',
"user_data_mapping" => array(
'sp_name' => 'default-sp',
"auth_user_md5.Email" => array("callback" => "getUserData", "map_args" => "email"),
'user_data_mapping' => [
"auth_user_md5.Nachname" => array("callback" => "getUserData", "map_args" => "firstName"),
'auth_user_md5.Email' => ['callback' => 'getUserData', 'map_args' => 'email'],
"auth_user_md5.Vorname" => array("callback" => "getUserData", "map_args" => "lastName")));
'auth_user_md5.Nachname' => ['callback' => 'getUserData', 'map_args' => 'firstName'],
'auth_user_md5.Vorname' => ['callback' => 'getUserData', 'map_args' => 'lastName'],
],
];
*/
*/
//some additional authification-settings
//some additional authification-settings
...
...
This diff is collapsed.
Click to expand it.
lib/classes/auth_plugins/StudipAuthSimpleSamlPHP.php
+
50
−
61
View file @
3513583c
...
@@ -5,21 +5,22 @@
...
@@ -5,21 +5,22 @@
* author: Rene Ceska <ceskar2001@gmail.com>
* author: Rene Ceska <ceskar2001@gmail.com>
* This class is used to authenticate users through SimpleSAMLphp.
* This class is used to authenticate users through SimpleSAMLphp.
* This code was inspired by other Stud.IP auth plugins.
* This code was inspired by other Stud.IP auth plugins.
*
* @since Stud.IP 6.0
*/
*/
// Default location of SimpleSamlPHP _autoload. Change if needed.
require_once
(
'/var/simplesamlphp/src/_autoload.php'
);
class
StudipAuthSimpleSamlPHP
extends
StudipAuthSSO
class
StudipAuthSimpleSamlPHP
extends
StudipAuthSSO
{
{
// Reverse proxy domain
// Reverse proxy domain
public
$reverse_proxy_url
;
public
?string
$reverse_proxy_url
=
null
;
// Name of the SimpleSAMLphp SP
// Name of the SimpleSAMLphp SP
public
$sp_name
;
public
string
$sp_name
;
// Name of attribute that contains username (if empty it will use NameID as username)
// Name of attribute that contains username (if empty it will use NameID as username)
public
$username_attribute
;
public
?string
$username_attribute
=
null
;
public
$userdata
;
public
$as
;
public
?array
$userdata
=
null
;
public
SimpleSAML
\Auth\Simple
$as
;
/**
/**
* Constructor: read auth information from remote SP.
* Constructor: read auth information from remote SP.
...
@@ -27,44 +28,17 @@ class StudipAuthSimpleSamlPHP extends StudipAuthSSO
...
@@ -27,44 +28,17 @@ class StudipAuthSimpleSamlPHP extends StudipAuthSSO
public
function
__construct
(
$config
=
[])
public
function
__construct
(
$config
=
[])
{
{
parent
::
__construct
(
$config
);
parent
::
__construct
(
$config
);
// check if user chosen to login through this plugin
if
(
Request
::
get
(
'sso'
)
===
$this
->
plugin_name
)
{
$this
->
as
=
new
\SimpleSAML\Auth\Simple
(
$this
->
sp_name
);
//return to right url, otherwise stud.ip will break
if
(
empty
(
$this
->
reverse_proxy_url
)){
$return_to_url
=
(
empty
(
$_SERVER
[
'HTTPS'
])
?
'http'
:
'https'
)
.
"://
$_SERVER[HTTP_HOST]
"
.
"/dispatch.php/start?again=yes&sso=simplesamlphp&cancel_login=1"
;
}
else
{
$return_to_url
=
$this
->
reverse_proxy_url
.
"/dispatch.php/start?again=yes&sso=simplesamlphp&cancel_login=1"
;
}
// check if user is already authenticated and if not, authenticate them
if
(
!
$this
->
as
->
isAuthenticated
())
{
$this
->
as
->
requireAuth
([
'ReturnTo'
=>
$return_to_url
]);
}
$this
->
userdata
=
[];
// get username
if
(
empty
(
$username_attribute
)){
$this
->
userdata
[
'username'
]
=
$this
->
as
->
getAuthData
(
'saml:sp:NameID'
)
->
getValue
();
}
else
{
$this
->
userdata
[
'username'
]
=
$this
->
as
->
getAttributes
()[
$this
->
username_attribute
];
}
// get other user attributes
$this
->
userdata
=
array_merge
(
$this
->
userdata
,
$this
->
as
->
getAttributes
());
// cleanup session so it does not interfere with Stud.IP session
$session
=
\SimpleSAML\Session
::
getSessionFromRequest
();
$session
->
cleanup
();
}
if
(
!
isset
(
$this
->
plugin_fullname
))
{
if
(
!
isset
(
$this
->
plugin_fullname
))
{
$this
->
plugin_fullname
=
_
(
'
Federated
'
);
$this
->
plugin_fullname
=
_
(
'
SAML
'
);
}
}
if
(
!
isset
(
$this
->
login_description
))
{
if
(
!
isset
(
$this
->
login_description
))
{
$this
->
login_description
=
_
(
'Login trough your institution'
);
$this
->
login_description
=
_
(
'für Single Sign On mit SAML'
);
}
// check if user chosen to login through this plugin
if
(
Request
::
get
(
'sso'
)
===
$this
->
plugin_name
)
{
$this
->
as
=
new
SimpleSAML\Auth\Simple
(
$this
->
sp_name
);
}
}
}
}
...
@@ -73,7 +47,7 @@ class StudipAuthSimpleSamlPHP extends StudipAuthSSO
...
@@ -73,7 +47,7 @@ class StudipAuthSimpleSamlPHP extends StudipAuthSSO
*/
*/
public
function
getUser
()
public
function
getUser
()
{
{
return
$this
->
u
ser
d
ata
[
'username'
]
;
return
$this
->
getU
ser
D
ata
(
'username'
)
;
}
}
/**
/**
...
@@ -87,38 +61,37 @@ class StudipAuthSimpleSamlPHP extends StudipAuthSSO
...
@@ -87,38 +61,37 @@ class StudipAuthSimpleSamlPHP extends StudipAuthSSO
return
$this
->
getUser
();
return
$this
->
getUser
();
}
}
//return to right url, otherwise stud.ip will break
if
(
empty
(
$this
->
reverse_proxy_url
)){
$return_to_url
=
(
empty
(
$_SERVER
[
'HTTPS'
])
?
'http'
:
'https'
)
.
"://
$_SERVER[HTTP_HOST]
"
.
"/dispatch.php/start?again=yes&sso=simplesamlphp&cancel_login=1"
;
}
else
{
$return_to_url
=
$this
->
reverse_proxy_url
.
"/dispatch.php/start?again=yes&sso=simplesamlphp&cancel_login=1"
;
}
// check if user is already authenticated and if not, authenticate them
// check if user is already authenticated and if not, authenticate them
if
(
!
$this
->
as
->
isAuthenticated
())
{
if
(
!
$this
->
as
->
isAuthenticated
())
{
$this
->
as
->
requireAuth
([
'ReturnTo'
=>
$
return_to_url
]);
$this
->
as
->
requireAuth
([
'ReturnTo'
=>
$
this
->
getReturnToURL
()
]);
}
}
if
(
empty
(
$username_attribute
)){
$this
->
userdata
=
[];
// get username
if
(
empty
(
$this
->
username_attribute
))
{
$this
->
userdata
[
'username'
]
=
$this
->
as
->
getAuthData
(
'saml:sp:NameID'
)
->
getValue
();
$this
->
userdata
[
'username'
]
=
$this
->
as
->
getAuthData
(
'saml:sp:NameID'
)
->
getValue
();
}
else
{
}
else
{
$this
->
userdata
[
'username'
]
=
$this
->
as
->
getAttributes
()[
$this
->
username_attribute
];
$this
->
userdata
[
'username'
]
=
$this
->
as
->
getAttributes
()[
$this
->
username_attribute
];
}
}
$session
=
\SimpleSAML\Session
::
getSessionFromRequest
();
$session
->
cleanup
();
// get other user attributes
$this
->
userdata
=
array_merge
(
$this
->
userdata
,
$this
->
as
->
getAttributes
());
// cleanup session so it does not interfere with Stud.IP session
SimpleSAML\Session
::
getSessionFromRequest
()
->
cleanup
();
return
$this
->
getUser
();
return
$this
->
getUser
();
}
}
/**
/**
* Callback that can be used in user_data_mapping array.
* Callback that can be used in user_data_mapping array.
*/
*/
function
getUserData
(
$key
)
public
function
getUserData
(
$key
)
{
{
return
$this
->
userdata
[
$key
];
return
$this
->
userdata
[
$key
];
}
}
/**
/**
* Logout the user.
* Logout the user.
*/
*/
...
@@ -127,4 +100,20 @@ class StudipAuthSimpleSamlPHP extends StudipAuthSSO
...
@@ -127,4 +100,20 @@ class StudipAuthSimpleSamlPHP extends StudipAuthSSO
$auth
=
new
\SimpleSAML\Auth\Simple
(
$this
->
sp_name
);
$auth
=
new
\SimpleSAML\Auth\Simple
(
$this
->
sp_name
);
$auth
->
Logout
();
$auth
->
Logout
();
}
}
/**
* Returns the required return to url
*/
public
function
getReturnToURL
():
string
{
$old_base
=
URLHelper
::
setBaseURL
(
$this
->
reverse_proxy_url
?:
$GLOBALS
[
'ABSOLUTE_URI_STUDIP'
]);
$return_to_url
=
URLHelper
::
getURL
(
'dispatch.php/start'
,
[
'again'
=>
'yes'
,
'cancel_login'
=>
1
,
'sso'
=>
$this
->
plugin_name
,
]);
URLHelper
::
setBaseURL
(
$old_base
);
return
$return_to_url
;
}
}
}
This diff is collapsed.
Click to expand it.
public/logout.php
+
1
−
2
View file @
3513583c
...
@@ -47,8 +47,7 @@ if ($auth->auth['uid'] !== 'nobody') {
...
@@ -47,8 +47,7 @@ if ($auth->auth['uid'] !== 'nobody') {
if
(
$auth
->
auth
[
'auth_plugin'
]
===
'cas'
)
{
if
(
$auth
->
auth
[
'auth_plugin'
]
===
'cas'
)
{
$casauth
=
StudipAuthAbstract
::
GetInstance
(
'cas'
);
$casauth
=
StudipAuthAbstract
::
GetInstance
(
'cas'
);
$docaslogout
=
true
;
$docaslogout
=
true
;
}
}
elseif
(
$auth
->
auth
[
'auth_plugin'
]
===
'simplesamlphp'
)
{
if
(
$auth
->
auth
[
"auth_plugin"
]
===
"simplesamlphp"
){
$SimpleSamlPHPAuth
=
StudipAuthAbstract
::
GetInstance
(
'simplesamlphp'
);
$SimpleSamlPHPAuth
=
StudipAuthAbstract
::
GetInstance
(
'simplesamlphp'
);
$dosimplesamlphplogout
=
true
;
$dosimplesamlphplogout
=
true
;
}
}
...
...
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