Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp-module-authswitcher
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
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp-module-authswitcher
Commits
04eb5e48
Unverified
Commit
04eb5e48
authored
Apr 14, 2022
by
Pavel Břoušek
Committed by
GitHub
Apr 14, 2022
Browse files
Options
Downloads
Plain Diff
Merge pull request #31 from CESNET/realm
Improvements for problematic situations
parents
b4d04d9b
f52389be
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
README.md
+3
-0
3 additions, 0 deletions
README.md
lib/Auth/Process/GetMfaTokensPrivacyIDEA.php
+22
-2
22 additions, 2 deletions
lib/Auth/Process/GetMfaTokensPrivacyIDEA.php
lib/Auth/Process/SwitchAuth.php
+8
-11
8 additions, 11 deletions
lib/Auth/Process/SwitchAuth.php
with
33 additions
and
13 deletions
README.md
+
3
−
0
View file @
04eb5e48
...
...
@@ -38,6 +38,7 @@ Use this filter to read user mfa tokens from PrivacyIDEA server to state attribu
'tokens_Attr'
=>
'privacyIDEATokens'
,
'privacy_idea_username'
=>
'admin'
,
'privacy_idea_passwd'
=>
'secret'
,
//'privacy_idea_realm' => 'superadminrealm', // optional
'privacy_idea_domain'
=>
'https://mfa.id.muni.cz'
,
'tokens_type'
=>
[
'TOTP'
,
...
...
@@ -45,6 +46,8 @@ Use this filter to read user mfa tokens from PrivacyIDEA server to state attribu
],
'user_attribute'
=>
'eduPersonPrincipalName'
,
'token_type_attr'
=>
'type'
,
//'connect_timeout' => 10, // optional, connect timeout in seconds
//'timeout' => 10, // optional, timeout in seconds
],
],
```
...
...
This diff is collapsed.
Click to expand it.
lib/Auth/Process/GetMfaTokensPrivacyIDEA.php
+
22
−
2
View file @
04eb5e48
...
...
@@ -16,12 +16,18 @@ class GetMfaTokensPrivacyIDEA extends \SimpleSAML\Auth\ProcessingFilter
private
const
AS_PI_AUTH_TOKEN
=
'auth_token'
;
private
const
AS_PI_AUTH_TOKEN_ISSUED_AT
=
'auth_token_issued_at'
;
private
$connect_timeout
=
0
;
private
$timeout
;
private
$tokens_attr
=
'mfaTokens'
;
private
$privacy_idea_username
;
private
$privacy_idea_passwd
;
private
$privacy_idea_realm
;
private
$privacy_idea_domain
;
private
$tokens_type
=
[
'TOTP'
,
'WebAuthn'
];
...
...
@@ -39,9 +45,12 @@ class GetMfaTokensPrivacyIDEA extends \SimpleSAML\Auth\ProcessingFilter
parent
::
__construct
(
$config
,
$reserved
);
$config
=
Configuration
::
loadFromArray
(
$config
[
'config'
]);
$this
->
connect_timeout
=
$config
->
getInteger
(
'connect_timeout'
,
$this
->
connect_timeout
);
$this
->
timeout
=
$config
->
getInteger
(
'timeout'
,
$this
->
timeout
);
$this
->
tokens_attr
=
$config
->
getString
(
'tokens_Attr'
,
$this
->
tokens_attr
);
$this
->
privacy_idea_username
=
$config
->
getString
(
'privacy_idea_username'
);
$this
->
privacy_idea_passwd
=
$config
->
getString
(
'privacy_idea_passwd'
);
$this
->
privacy_idea_realm
=
$config
->
getString
(
'privacy_idea_realm'
,
null
);
$this
->
privacy_idea_domain
=
$config
->
getString
(
'privacy_idea_domain'
);
$this
->
tokens_type
=
$config
->
getArray
(
'tokens_type'
,
$this
->
tokens_type
);
$this
->
user_attribute
=
$config
->
getString
(
'user_attribute'
,
$this
->
user_attribute
);
...
...
@@ -58,7 +67,7 @@ class GetMfaTokensPrivacyIDEA extends \SimpleSAML\Auth\ProcessingFilter
$state
[
Authswitcher
::
PRIVACY_IDEA_FAIL
]
=
false
;
$state
[
'Attributes'
][
$this
->
tokens_attr
]
=
[];
$admin_token
=
$this
->
getAdminToken
();
if
(
null
===
$admin_token
)
{
if
(
empty
(
$admin_token
)
)
{
$state
[
AuthSwitcher
::
PRIVACY_IDEA_FAIL
]
=
true
;
return
;
...
...
@@ -98,8 +107,15 @@ class GetMfaTokensPrivacyIDEA extends \SimpleSAML\Auth\ProcessingFilter
'username'
=>
$this
->
privacy_idea_username
,
'password'
=>
$this
->
privacy_idea_passwd
,
];
if
(
null
!==
$this
->
privacy_idea_realm
)
{
$data
[
'realm'
]
=
$this
->
privacy_idea_realm
;
}
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_CONNECTTIMEOUT
,
$this
->
connect_timeout
);
if
(
null
!==
$this
->
timeout
)
{
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
$this
->
timeout
);
}
curl_setopt
(
$ch
,
CURLOPT_URL
,
$this
->
privacy_idea_domain
.
'/auth'
);
curl_setopt
(
$ch
,
CURLOPT_CUSTOMREQUEST
,
'POST'
);
$paramsJson
=
json_encode
(
$data
);
...
...
@@ -118,9 +134,13 @@ class GetMfaTokensPrivacyIDEA extends \SimpleSAML\Auth\ProcessingFilter
return
$response
[
'result'
][
'value'
][
'token'
];
}
private
function
getPrivacyIdeaTokensByType
(
$state
,
$type
,
$admin_token
)
private
function
getPrivacyIdeaTokensByType
(
&
$state
,
$type
,
$admin_token
)
{
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_CONNECTTIMEOUT
,
$this
->
connect_timeout
);
if
(
null
!==
$this
->
timeout
)
{
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
$this
->
timeout
);
}
curl_setopt
(
$ch
,
CURLOPT_URL
,
$this
->
privacy_idea_domain
.
'/token/?user='
.
$state
[
'Attributes'
][
$this
->
user_attribute
][
0
]
.
'&active=True&type='
.
$type
);
curl_setopt
(
$ch
,
CURLOPT_CUSTOMREQUEST
,
'GET'
);
...
...
This diff is collapsed.
Click to expand it.
lib/Auth/Process/SwitchAuth.php
+
8
−
11
View file @
04eb5e48
...
...
@@ -122,22 +122,19 @@ class SwitchAuth extends \SimpleSAML\Auth\ProcessingFilter
self
::
info
(
'supported requested contexts: '
.
json_encode
(
$state
[
AuthSwitcher
::
SUPPORTED_REQUESTED_CONTEXTS
]));
if
(
$this
->
mfa_preferred_privacyidea_fail
&&
isset
(
$state
[
AuthSwitcher
::
PRIVACY_IDEA_FAIL
])
&&
$state
[
AuthSwitcher
::
PRIVACY_IDEA_FAIL
]
&&
AuthnContextHelper
::
isMFAprefered
(
$state
[
Authswitcher
::
SUPPORTED_REQUESTED_CONTEXTS
])
&&
!
AuthnContextHelper
::
MFAin
([
$upstreamContext
])
)
{
throw
new
Exception
(
self
::
DEBUG_PREFIX
.
'MFA is preferred but connection to privacyidea failed.'
);
}
// switch to MFA if enforced or preferred but not already done if we handle the proxy mode
$performMFA
=
AuthnContextHelper
::
MFAin
(
$usersCapabilities
)
&&
!
AuthnContextHelper
::
MFAin
([
$shouldPerformMFA
=
!
AuthnContextHelper
::
MFAin
([
$upstreamContext
,
])
&&
(
$this
->
mfa_enforced
||
AuthnContextHelper
::
isMFAprefered
(
$state
[
AuthSwitcher
::
SUPPORTED_REQUESTED_CONTEXTS
]
));
if
(
$this
->
mfa_preferred_privacyidea_fail
&&
!
empty
(
$state
[
AuthSwitcher
::
PRIVACY_IDEA_FAIL
])
&&
$shouldPerformMFA
)
{
throw
new
Exception
(
self
::
DEBUG_PREFIX
.
'MFA should be performed but connection to privacyidea failed.'
);
}
// switch to MFA if enforced or preferred but not already done if we handle the proxy mode
$performMFA
=
AuthnContextHelper
::
MFAin
(
$usersCapabilities
)
&&
$shouldPerformMFA
;
$maxUserCapability
=
''
;
if
(
in_array
(
AuthSwitcher
::
MFA
,
$usersCapabilities
,
true
))
{
$maxUserCapability
=
AuthSwitcher
::
MFA
;
...
...
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