Complex classes like ClientAssertionJwt often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ClientAssertionJwt, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | class ClientAssertionJwt implements AuthenticationMethod |
||
| 35 | {/** |
||
|
|
|||
| 36 | * @var JWSVerifier |
||
| 37 | */ |
||
| 38 | private $jwsVerifier; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var null|TrustedIssuerRepository |
||
| 42 | */ |
||
| 43 | private $trustedIssuerRepository = null; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var null|JKUFactory |
||
| 47 | */ |
||
| 48 | private $jkuFactory = null; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var null|JWELoader |
||
| 52 | */ |
||
| 53 | private $jweLoader = null; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var null|JWKSet |
||
| 57 | */ |
||
| 58 | private $keyEncryptionKeySet = null; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var bool |
||
| 62 | */ |
||
| 63 | private $encryptionRequired = false; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var int |
||
| 67 | */ |
||
| 68 | private $secretLifetime; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var HeaderCheckerManager |
||
| 72 | */ |
||
| 73 | private $headerCheckerManager; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var ClaimCheckerManager |
||
| 77 | */ |
||
| 78 | private $claimCheckerManager; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var JsonConverter |
||
| 82 | */ |
||
| 83 | private $jsonConverter; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * ClientAssertionJwt constructor. |
||
| 87 | * |
||
| 88 | * @param JsonConverter $jsonConverter |
||
| 89 | * @param JWSVerifier $jwsVerifier |
||
| 90 | * @param HeaderCheckerManager $headerCheckerManager |
||
| 91 | * @param ClaimCheckerManager $claimCheckerManager |
||
| 92 | * @param int $secretLifetime |
||
| 93 | */ |
||
| 94 | public function __construct(JsonConverter $jsonConverter, JWSVerifier $jwsVerifier, HeaderCheckerManager $headerCheckerManager, ClaimCheckerManager $claimCheckerManager, int $secretLifetime = 0) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @param TrustedIssuerRepository $trustedIssuerRepository |
||
| 108 | */ |
||
| 109 | public function enableTrustedIssuerSupport(TrustedIssuerRepository $trustedIssuerRepository) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @param JKUFactory $jkuFactory |
||
| 116 | */ |
||
| 117 | public function enableJkuSupport(JKUFactory $jkuFactory) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @param JWELoader $jweLoader |
||
| 124 | * @param JWKSet $keyEncryptionKeySet |
||
| 125 | * @param bool $encryptionRequired |
||
| 126 | */ |
||
| 127 | public function enableEncryptedAssertions(JWELoader $jweLoader, JWKSet $keyEncryptionKeySet, bool $encryptionRequired) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @return string[] |
||
| 136 | */ |
||
| 137 | public function getSupportedSignatureAlgorithms(): array |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @return string[] |
||
| 144 | */ |
||
| 145 | public function getSupportedContentEncryptionAlgorithms(): array |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @return string[] |
||
| 152 | */ |
||
| 153 | public function getSupportedKeyEncryptionAlgorithms(): array |
||
| 157 | |||
| 158 | /** |
||
| 159 | * {@inheritdoc} |
||
| 160 | */ |
||
| 161 | public function getSchemesParameters(): array |
||
| 165 | |||
| 166 | /** |
||
| 167 | * {@inheritdoc} |
||
| 168 | */ |
||
| 169 | public function findClientIdAndCredentials(ServerRequestInterface $request, &$clientCredentials = null): ? ClientId |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @param string $assertion |
||
| 212 | * |
||
| 213 | * @return string |
||
| 214 | * |
||
| 215 | * @throws OAuth2Exception |
||
| 216 | */ |
||
| 217 | private function tryToDecryptClientAssertion(string $assertion): string |
||
| 238 | |||
| 239 | /** |
||
| 240 | * {@inheritdoc} |
||
| 241 | */ |
||
| 242 | public function isClientAuthenticated(Client $client, $clientCredentials, ServerRequestInterface $request): bool |
||
| 257 | |||
| 258 | /** |
||
| 259 | * {@inheritdoc} |
||
| 260 | */ |
||
| 261 | public function getSupportedMethods(): array |
||
| 265 | |||
| 266 | /** |
||
| 267 | * {@inheritdoc} |
||
| 268 | */ |
||
| 269 | public function checkClientConfiguration(DataBag $commandParameters, DataBag $validatedParameters): DataBag |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @return string |
||
| 300 | */ |
||
| 301 | private function createClientSecret(): string |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @param Client $client |
||
| 308 | * @param array $claims |
||
| 309 | * |
||
| 310 | * @return JWKSet |
||
| 311 | */ |
||
| 312 | private function retrieveIssuerKeySet(Client $client, array $claims): JWKSet |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @param Client $client |
||
| 327 | * @return JWKSet |
||
| 328 | */ |
||
| 329 | private function getClientKeySet(Client $client): JWKSet |
||
| 348 | } |
||
| 349 |