-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
213 additions
and
163 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dbp\Relay\EsignBundle\Authorization; | ||
|
||
use Dbp\Relay\CoreBundle\Authorization\AbstractAuthorizationService; | ||
use Dbp\Relay\EsignBundle\Configuration\BundleConfig; | ||
use Dbp\Relay\EsignBundle\DependencyInjection\Configuration; | ||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; | ||
use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
|
||
class AuthorizationService extends AbstractAuthorizationService | ||
{ | ||
public function __construct(private readonly BundleConfig $config, private readonly AuthorizationCheckerInterface $authorizationChecker) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Throws if the user is not allowed to sign things. | ||
*/ | ||
public function checkCanSign(): void | ||
{ | ||
$this->denyAccessUnlessIsGrantedRole(Configuration::ROLE_SIGNER); | ||
} | ||
|
||
/** | ||
* Throws if the current user doesn't have permissions to sign with the given profile. | ||
*/ | ||
public function checkCanSignWithProfile(string $profileName): void | ||
{ | ||
$profile = $this->config->getProfile($profileName); | ||
if ($profile === null) { | ||
// We don't want to leak which profiles exist | ||
throw new AccessDeniedException(); | ||
} | ||
|
||
// In case the legacy symfony role is specified it takes precedence over the new system | ||
$legacyRole = $profile->getRole(); | ||
if ($legacyRole !== null) { | ||
if ($this->authorizationChecker->isGranted($legacyRole)) { | ||
return; | ||
} | ||
throw new AccessDeniedException(); | ||
} | ||
|
||
$resource = new ProfileData($profile->getName()); | ||
$this->denyAccessUnlessIsGrantedResourcePermission(Configuration::ROLE_PROFILE_SIGNER, $resource); | ||
} | ||
|
||
/** | ||
* Throws if the user is not allowed to verify signatures. | ||
*/ | ||
public function checkCanVerify(): void | ||
{ | ||
$this->denyAccessUnlessIsGrantedRole(Configuration::ROLE_VERIFIER); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dbp\Relay\EsignBundle\Authorization; | ||
|
||
class ProfileData | ||
{ | ||
public function __construct(private readonly string $name) | ||
{ | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
} |
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
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
Oops, something went wrong.