1919
2020class TestController
2121{
22+ protected readonly Federation $ federationWithArrayLogger ;
23+
2224 public function __construct (
2325 protected readonly ModuleConfig $ moduleConfig ,
2426 protected readonly TemplateFactory $ templateFactory ,
@@ -28,6 +30,14 @@ public function __construct(
2830 protected readonly ArrayLogger $ arrayLogger ,
2931 ) {
3032 $ this ->authorization ->requireAdmin (true );
33+
34+ $ this ->arrayLogger ->setWeight (ArrayLogger::WEIGHT_WARNING );
35+ // Let's create new Federation instance so we can inject our debug logger and go without cache.
36+ $ this ->federationWithArrayLogger = new Federation (
37+ supportedAlgorithms: $ this ->federation ->supportedAlgorithms (),
38+ cache: null ,
39+ logger: $ this ->arrayLogger ,
40+ );
3141 }
3242
3343 /**
@@ -37,14 +47,6 @@ public function __construct(
3747 */
3848 public function trustChainResolution (Request $ request ): Response
3949 {
40- $ this ->arrayLogger ->setWeight (ArrayLogger::WEIGHT_WARNING );
41- // Let's create new Federation instance so we can inject our debug logger and go without cache.
42- $ federation = new Federation (
43- supportedAlgorithms: $ this ->federation ->supportedAlgorithms (),
44- cache: null ,
45- logger: $ this ->arrayLogger ,
46- );
47-
4850 $ leafEntityId = $ this ->moduleConfig ->getIssuer ();
4951 $ trustChainBag = null ;
5052 $ resolvedMetadata = [];
@@ -69,7 +71,8 @@ public function trustChainResolution(Request $request): Response
6971 $ trustAnchorIds = $ this ->helpers ->str ()->convertTextToArray ($ rawTrustAnchorIds );
7072
7173 try {
72- $ trustChainBag = $ federation ->trustChainResolver ()->for ($ leafEntityId , $ trustAnchorIds );
74+ $ trustChainBag = $ this ->federationWithArrayLogger ->trustChainResolver ()
75+ ->for ($ leafEntityId , $ trustAnchorIds );
7376
7477 foreach ($ trustChainBag ->getAll () as $ index => $ trustChain ) {
7578 $ metadataEntries = [];
@@ -94,7 +97,7 @@ public function trustChainResolution(Request $request): Response
9497
9598 $ trustAnchorIds = implode ("\n" , $ trustAnchorIds );
9699 $ logMessages = $ this ->arrayLogger ->getEntries ();
97- //dd($this->arrayLogger->getEntries());
100+
98101 return $ this ->templateFactory ->build (
99102 'oidc:tests/trust-chain-resolution.twig ' ,
100103 compact (
@@ -108,4 +111,62 @@ public function trustChainResolution(Request $request): Response
108111 RoutesEnum::AdminTestTrustChainResolution->value ,
109112 );
110113 }
114+
115+ public function trustMarkValidation (Request $ request ): Response
116+ {
117+ $ trustMarkId = null ;
118+ $ leafEntityId = null ;
119+ $ trustAnchorId = null ;
120+ $ isFormSubmitted = false ;
121+
122+ if ($ request ->isMethod (Request::METHOD_POST )) {
123+ $ isFormSubmitted = true ;
124+
125+ !empty ($ trustMarkId = $ request ->request ->getString ('trustMarkId ' )) ||
126+ throw new OidcException ('Empty Trust Mark ID. ' );
127+ !empty ($ leafEntityId = $ request ->request ->getString ('leafEntityId ' )) ||
128+ throw new OidcException ('Empty leaf entity ID. ' );
129+ !empty ($ trustAnchorId = $ request ->request ->getString ('trustAnchorId ' )) ||
130+ throw new OidcException ('Empty Trust Anchor ID. ' );
131+
132+ try {
133+ // We should not try to validate Trust Marks until we have resolved trust chain between leaf and TA.
134+ $ trustChain = $ this ->federation ->trustChainResolver ()->for (
135+ $ leafEntityId ,
136+ [$ trustAnchorId ],
137+ )->getShortest ();
138+
139+ try {
140+ $ this ->federationWithArrayLogger ->trustMarkValidator ()->doForTrustMarkId (
141+ $ trustMarkId ,
142+ $ trustChain ->getResolvedLeaf (),
143+ $ trustChain ->getResolvedTrustAnchor (),
144+ );
145+ } catch (\Throwable $ exception ) {
146+ $ this ->arrayLogger ->error ('Trust Mark validation error: ' . $ exception ->getMessage ());
147+ }
148+ } catch (TrustChainException $ exception ) {
149+ $ this ->arrayLogger ->error (sprintf (
150+ 'Could not resolve Trust Chain for leaf entity %s under Trust Anchor %s. Error was %s ' ,
151+ $ leafEntityId ,
152+ $ trustAnchorId ,
153+ $ exception ->getMessage (),
154+ ));
155+ }
156+ }
157+
158+ $ logMessages = $ this ->arrayLogger ->getEntries ();
159+
160+ return $ this ->templateFactory ->build (
161+ 'oidc:tests/trust-mark-validation.twig ' ,
162+ compact (
163+ 'trustMarkId ' ,
164+ 'leafEntityId ' ,
165+ 'trustAnchorId ' ,
166+ 'logMessages ' ,
167+ 'isFormSubmitted ' ,
168+ ),
169+ RoutesEnum::AdminTestTrustMarkValidation->value ,
170+ );
171+ }
111172}
0 commit comments