19
19
20
20
class TestController
21
21
{
22
+ protected readonly Federation $ federationWithArrayLogger ;
23
+
22
24
public function __construct (
23
25
protected readonly ModuleConfig $ moduleConfig ,
24
26
protected readonly TemplateFactory $ templateFactory ,
@@ -28,6 +30,14 @@ public function __construct(
28
30
protected readonly ArrayLogger $ arrayLogger ,
29
31
) {
30
32
$ 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
+ );
31
41
}
32
42
33
43
/**
@@ -37,14 +47,6 @@ public function __construct(
37
47
*/
38
48
public function trustChainResolution (Request $ request ): Response
39
49
{
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
-
48
50
$ leafEntityId = $ this ->moduleConfig ->getIssuer ();
49
51
$ trustChainBag = null ;
50
52
$ resolvedMetadata = [];
@@ -69,7 +71,8 @@ public function trustChainResolution(Request $request): Response
69
71
$ trustAnchorIds = $ this ->helpers ->str ()->convertTextToArray ($ rawTrustAnchorIds );
70
72
71
73
try {
72
- $ trustChainBag = $ federation ->trustChainResolver ()->for ($ leafEntityId , $ trustAnchorIds );
74
+ $ trustChainBag = $ this ->federationWithArrayLogger ->trustChainResolver ()
75
+ ->for ($ leafEntityId , $ trustAnchorIds );
73
76
74
77
foreach ($ trustChainBag ->getAll () as $ index => $ trustChain ) {
75
78
$ metadataEntries = [];
@@ -94,7 +97,7 @@ public function trustChainResolution(Request $request): Response
94
97
95
98
$ trustAnchorIds = implode ("\n" , $ trustAnchorIds );
96
99
$ logMessages = $ this ->arrayLogger ->getEntries ();
97
- //dd($this->arrayLogger->getEntries());
100
+
98
101
return $ this ->templateFactory ->build (
99
102
'oidc:tests/trust-chain-resolution.twig ' ,
100
103
compact (
@@ -108,4 +111,62 @@ public function trustChainResolution(Request $request): Response
108
111
RoutesEnum::AdminTestTrustChainResolution->value ,
109
112
);
110
113
}
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
+ }
111
172
}
0 commit comments