1 | <?php |
||
18 | class HeaderCheckerManager |
||
19 | { |
||
20 | /** |
||
21 | * @var HeaderChecker[] |
||
22 | */ |
||
23 | private $checkers = []; |
||
24 | |||
25 | /** |
||
26 | * @var TokenTypeSupport[] |
||
27 | */ |
||
28 | private $tokenTypes = []; |
||
29 | |||
30 | /** |
||
31 | * HeaderCheckerManager constructor. |
||
32 | * |
||
33 | * @param HeaderChecker[] $checkers |
||
34 | * @param TokenTypeSupport[] $tokenTypes |
||
35 | */ |
||
36 | private function __construct(array $checkers, array $tokenTypes) |
||
45 | |||
46 | /** |
||
47 | * This method creates the HeaderCheckerManager. |
||
48 | * The first argument is a list of header parameter checkers objects. |
||
49 | * The second argument is a list of token type support objects. |
||
50 | * It is recommended to support only one token type per manager. |
||
51 | * |
||
52 | * @param HeaderChecker[] $checkers |
||
53 | * @param TokenTypeSupport[] $tokenTypes |
||
54 | * |
||
55 | * @return HeaderCheckerManager |
||
56 | */ |
||
57 | public static function create(array $checkers, array $tokenTypes): self |
||
61 | |||
62 | /** |
||
63 | * This method returns all checkers handled by this manager. |
||
64 | * |
||
65 | * @return HeaderChecker[] |
||
66 | */ |
||
67 | public function getCheckers(): array |
||
71 | |||
72 | /** |
||
73 | * @param TokenTypeSupport $tokenType |
||
74 | * |
||
75 | * @return HeaderCheckerManager |
||
76 | */ |
||
77 | private function addTokenTypeSupport(TokenTypeSupport $tokenType): self |
||
83 | |||
84 | /** |
||
85 | * @param HeaderChecker $checker |
||
86 | * |
||
87 | * @return HeaderCheckerManager |
||
88 | */ |
||
89 | private function add(HeaderChecker $checker): self |
||
96 | |||
97 | /** |
||
98 | * This method checks all the header parameters passed as argument. |
||
99 | * All header parameters are checked against the header parameter checkers. |
||
100 | * If one fails, the InvalidHeaderException is thrown. |
||
101 | * |
||
102 | * @param JWT $jwt |
||
103 | * @param int $index |
||
104 | * @param string[] $mandatoryHeaderParameters |
||
105 | * |
||
106 | * @throws InvalidHeaderException |
||
107 | * @throws MissingMandatoryHeaderParameterException |
||
108 | */ |
||
109 | public function check(JWT $jwt, int $index, array $mandatoryHeaderParameters = []) |
||
126 | |||
127 | /** |
||
128 | * @param array $header1 |
||
129 | * @param array $header2 |
||
130 | */ |
||
131 | private function checkDuplicatedHeaderParameters(array $header1, array $header2) |
||
138 | |||
139 | /** |
||
140 | * @param string[] $mandatoryHeaderParameters |
||
141 | * @param array $protected |
||
142 | * @param array $unprotected |
||
143 | * |
||
144 | * @throws MissingMandatoryHeaderParameterException |
||
145 | */ |
||
146 | private function checkMandatoryHeaderParameters(array $mandatoryHeaderParameters, array $protected, array $unprotected) |
||
157 | |||
158 | /** |
||
159 | * @param array $protected |
||
160 | * @param array $header |
||
161 | * |
||
162 | * @throws InvalidHeaderException |
||
163 | */ |
||
164 | private function checkHeaders(array $protected, array $header) |
||
187 | |||
188 | /** |
||
189 | * @param array $protected |
||
190 | * @param array $header |
||
191 | * @param array $checkedHeaderParameters |
||
192 | * |
||
193 | * @throws InvalidHeaderException |
||
194 | */ |
||
195 | private function checkCriticalHeader(array $protected, array $header, array $checkedHeaderParameters) |
||
209 | } |
||
210 |