-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #675 from systemli/unify-access-token-handlers
Unify Api Access Token Handlers
- Loading branch information
Showing
12 changed files
with
78 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Security; | ||
|
||
use Symfony\Component\Security\Core\Exception\BadCredentialsException; | ||
use Symfony\Component\Security\Http\AccessToken\AccessTokenHandlerInterface; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; | ||
|
||
class ApiAccessTokenHandler implements AccessTokenHandlerInterface | ||
{ | ||
public function __construct( | ||
private string $accessTokenDovecot, | ||
private string $accessTokenKeycloak, | ||
private string $accessTokenPostfix, | ||
private string $accessTokenRetention, | ||
) {} | ||
|
||
public function getUserBadgeFrom(#[\SensitiveParameter] string $accessToken): UserBadge | ||
{ | ||
switch ($accessToken) { | ||
case $this->accessTokenDovecot: | ||
return new UserBadge('dovecot'); | ||
case $this->accessTokenKeycloak: | ||
return new UserBadge('keycloak'); | ||
case $this->accessTokenRetention: | ||
return new UserBadge('retention'); | ||
case $this->accessTokenPostfix: | ||
return new UserBadge('postfix'); | ||
default: | ||
throw new BadCredentialsException('Invalid access token'); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ class DovecotControllerTest extends WebTestCase | |
public function testStatus(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer dovecot', | ||
]); | ||
$client->request('GET', '/api/dovecot/status'); | ||
|
||
|
@@ -29,7 +29,7 @@ public function testStatusWrongApiToken(): void | |
public function testPassdbUser(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer dovecot', | ||
]); | ||
$client->request('POST', '/api/dovecot/[email protected]', ['password' => 'password']); | ||
|
||
|
@@ -39,7 +39,7 @@ public function testPassdbUser(): void | |
public function testPassdbUserWrongPassword(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer dovecot', | ||
]); | ||
$client->request('POST', '/api/dovecot/[email protected]', ['password' => 'wrong']); | ||
|
||
|
@@ -49,7 +49,7 @@ public function testPassdbUserWrongPassword(): void | |
public function testPassdbNonexistentUser(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer dovecot', | ||
]); | ||
$client->request('POST', '/api/dovecot/[email protected]', ['password' => 'password']); | ||
|
||
|
@@ -59,7 +59,7 @@ public function testPassdbNonexistentUser(): void | |
public function testPassdbSpamUser(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer dovecot', | ||
]); | ||
$client->request('POST', '/api/dovecot/[email protected]', ['password' => 'password']); | ||
|
||
|
@@ -69,7 +69,7 @@ public function testPassdbSpamUser(): void | |
public function testPassdbMailCrypt(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer dovecot', | ||
]); | ||
$client->request('POST', '/api/dovecot/[email protected]', ['password' => 'password']); | ||
|
||
|
@@ -82,7 +82,7 @@ public function testPassdbMailCrypt(): void | |
public function testUserdbUser(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer dovecot', | ||
]); | ||
$client->request('GET', '/api/dovecot/[email protected]'); | ||
|
||
|
@@ -96,13 +96,12 @@ public function testUserdbUser(): void | |
self::assertIsInt($data['body']['gid']); | ||
self::assertIsInt($data['body']['uid']); | ||
self::assertNotEquals($data['body']['home'], ''); | ||
|
||
} | ||
|
||
public function testUserdbMailcrypt(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer dovecot', | ||
]); | ||
$client->request('GET', '/api/dovecot/[email protected]'); | ||
|
||
|
@@ -119,7 +118,7 @@ public function testUserdbMailcrypt(): void | |
public function testUserdbNonexistentUser(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer dovecot', | ||
]); | ||
$client->request('GET', '/api/dovecot/[email protected]'); | ||
|
||
|
@@ -130,7 +129,7 @@ public function testUserdbNonexistentUser(): void | |
public function testUserdbSpamUser(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer dovecot', | ||
]); | ||
$client->request('GET', '/api/dovecot/[email protected]'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ public function testGetUsersSearchWrongApiToken(): void | |
public function testGetUsersSearch(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer keycloak', | ||
]); | ||
$client->request('GET', '/api/keycloak/example.org?search=example&max=2'); | ||
|
||
|
@@ -37,7 +37,7 @@ public function testGetUsersSearch(): void | |
public function testGetUsersSearchNonexistentDomain(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer keycloak', | ||
]); | ||
$client->request('GET', '/api/keycloak/nonexistent.org?search=example&max=2'); | ||
|
||
|
@@ -47,7 +47,7 @@ public function testGetUsersSearchNonexistentDomain(): void | |
public function testGetUsersCount(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer keycloak', | ||
]); | ||
$client->request('GET', '/api/keycloak/example.org/count'); | ||
|
||
|
@@ -60,7 +60,7 @@ public function testGetUsersCount(): void | |
public function testGetOneUser(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer keycloak', | ||
]); | ||
$client->request('GET', '/api/keycloak/example.org/user/[email protected]'); | ||
|
||
|
@@ -74,7 +74,7 @@ public function testGetOneUser(): void | |
public function testGetOneNonexistentUser(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer keycloak', | ||
]); | ||
$client->request('GET', '/api/keycloak/example.org/user/[email protected]'); | ||
|
||
|
@@ -84,7 +84,7 @@ public function testGetOneNonexistentUser(): void | |
public function testPostUserValidate(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer keycloak', | ||
]); | ||
$client->request('POST', '/api/keycloak/example.org/validate/[email protected]', ['credentialType' => 'password', 'password' => 'password']); | ||
|
||
|
@@ -114,7 +114,7 @@ public function testPostUserValidate(): void | |
public function testPostUserValidateOTP(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer keycloak', | ||
]); | ||
$client->request('POST', '/api/keycloak/example.org/validate/[email protected]', ['credentialType' => 'otp', 'password' => '123456']); | ||
self::assertResponseStatusCodeSame(403); | ||
|
@@ -131,7 +131,7 @@ public function testPostUserValidateOTP(): void | |
public function testGetIsConfiguredFor(): void | ||
{ | ||
$client = static::createClient([], [ | ||
'HTTP_Authorization' => 'Bearer insecure', | ||
'HTTP_Authorization' => 'Bearer keycloak', | ||
]); | ||
$client->request('GET', '/api/keycloak/example.org/configured/otp/[email protected]'); | ||
self::assertResponseStatusCodeSame(404); | ||
|
Oops, something went wrong.