Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp-module-proxystatistics
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp-module-proxystatistics
Commits
9055805c
Verified
Commit
9055805c
authored
1 year ago
by
Dominik Frantisek Bucik
Browse files
Options
Downloads
Patches
Plain Diff
feat:
Support multiple credentials write API
parent
a7a0ccb7
No related branches found
No related tags found
1 merge request
!94
feat: 🎸 Support multiple credentials write API
Pipeline
#415014
passed
1 year ago
Stage: .pre
Stage: test
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config-templates/module_proxystatistics.php
+10
-0
10 additions, 0 deletions
config-templates/module_proxystatistics.php
lib/Config.php
+18
-16
18 additions, 16 deletions
lib/Config.php
www/writeLoginApi.php
+9
-3
9 additions, 3 deletions
www/writeLoginApi.php
with
37 additions
and
19 deletions
config-templates/module_proxystatistics.php
+
10
−
0
View file @
9055805c
...
...
@@ -104,6 +104,16 @@ $config = [
*/
//'apiWritePasswordHash' => password_hash('ap1Wr1T3rP@S$'),
/*
* Map of credentials for API writer (has no effect if write is disabled).
* Either apiWriteUsername and apiWritePasswordHash or this array has to contain valid credentials pair.
*/
//'apiWriters' => [
// 'api_writer' => password_hash('ap1Wr1T3rP@S$'),
// 'api_writer2' => password_hash('ap1Wr1T3rP@S$'),
//],
/*
* List of IDP and/or SP EntityIDs for which the login statistic will be ignored even
* when requested to be instered into the storage. By default lists are empty
...
...
This diff is collapsed.
Click to expand it.
lib/Config.php
+
18
−
16
View file @
9055805c
...
...
@@ -41,6 +41,8 @@ class Config
private
const
API_WRITE_PASSWORD_HASH
=
'apiWritePasswordHash'
;
private
const
API_WRITERS_CREDENTIALS
=
'apiWriteCredentials'
;
private
const
IGNORED_IDS
=
'ignoredIds'
;
private
const
CRON_ENABLED
=
'cronEnabled'
;
...
...
@@ -63,9 +65,7 @@ class Config
private
$apiWriteEnabled
;
private
$apiWriteUsername
;
private
$apiWritePasswordHash
;
private
$apiWriters
;
private
$ignoredIds
;
...
...
@@ -87,13 +87,20 @@ class Config
$this
->
apiWriteEnabled
=
$this
->
config
->
getBoolean
(
self
::
API_WRITE_ENABLED
,
false
);
$this
->
ignoredIds
=
$this
->
config
->
getArray
(
self
::
IGNORED_IDS
,
[]);
if
(
$this
->
apiWriteEnabled
)
{
$this
->
apiWriteUsername
=
$this
->
config
->
getString
(
self
::
API_WRITE_USERNAME
);
if
(
empty
(
trim
(
$this
->
apiWriteUsername
)))
{
throw
new
Exception
(
'Username for API write cannot be empty'
);
$apiWriteUsername
=
$this
->
config
->
getString
(
self
::
API_WRITE_USERNAME
,
null
);
$apiWritePasswordHash
=
$this
->
config
->
getString
(
self
::
API_WRITE_PASSWORD_HASH
,
null
);
$this
->
apiWriters
=
$this
->
config
->
getArray
(
self
::
API_WRITERS_CREDENTIALS
,
[]);
if
(
!
empty
(
trim
(
$apiWriteUsername
))
&&
!
empty
(
trim
(
$apiWritePasswordHash
)))
{
$this
->
apiWriters
[
$apiWriteUsername
]
=
$apiWritePasswordHash
;
}
$this
->
apiWritePasswordHash
=
$this
->
config
->
getString
(
self
::
API_WRITE_PASSWORD_HASH
);
if
(
empty
(
trim
(
$this
->
apiWritePasswordHash
)))
{
throw
new
Exception
(
'Password for API write cannot be empty'
);
foreach
(
$this
->
apiWriters
as
$username
=>
$passwordHash
)
{
if
(
empty
(
trim
(
$username
)))
{
throw
new
Exception
(
'Username for API write cannot be empty'
);
}
if
(
empty
(
trim
(
$passwordHash
)))
{
throw
new
Exception
(
'Password for API write ('
.
$username
.
') cannot be empty'
);
}
}
}
}
...
...
@@ -163,14 +170,9 @@ class Config
return
$this
->
apiWriteEnabled
;
}
public
function
getApiWriteUsername
()
{
return
$this
->
apiWriteUsername
;
}
public
function
getApiWritePasswordHash
()
public
function
getApiWriteCredentials
()
{
return
$this
->
apiWrite
PasswordHash
;
return
$this
->
apiWrite
rs
;
}
public
function
getIgnoredIds
()
...
...
This diff is collapsed.
Click to expand it.
www/writeLoginApi.php
+
9
−
3
View file @
9055805c
...
...
@@ -26,11 +26,17 @@ if (!$config->isApiWriteEnabled()) {
$authUsername
=
$_SERVER
[
'PHP_AUTH_USER'
]
??
''
;
$authPass
=
$_SERVER
[
'PHP_AUTH_PW'
]
??
''
;
$username
=
$config
->
getApiWriteUsername
();
$passwordHash
=
$config
->
getApiWritePasswordHash
();
$apiCredentials
=
$config
->
getApiWriteCredentials
();
$validCreds
=
false
;
foreach
(
$apiCredentials
as
$username
=>
$passwordHash
)
{
if
(
$authUsername
===
$username
&&
password_verify
(
$authPass
,
$passwordHash
))
{
$validCreds
=
true
;
break
;
}
}
// If we get here, username was provided. Check password.
if
(
$authUsername
!==
$username
||
!
password_verify
(
$authPass
,
$passwordHash
)
)
{
if
(
!
$validCreds
)
{
Logger
::
info
(
sprintf
(
"%s - API write called with bad credentials (%s:%s) returning 401 response code"
,
...
...
This diff is collapsed.
Click to expand it.
Perun-GitLab Service Account
@9045464
mentioned in commit
82896174
·
1 year ago
mentioned in commit
82896174
mentioned in commit 828961744d9b404a271c4e4ec852f4940bf78d7c
Toggle commit list
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