1
1
package cz .muni .ics .oidc .saml ;
2
2
3
+ import static cz .muni .ics .oidc .server .filters .PerunFilterConstants .CLIENT_ID_PREFIX ;
3
4
import static cz .muni .ics .oidc .server .filters .PerunFilterConstants .EFILTER_PREFIX ;
4
5
import static cz .muni .ics .oidc .server .filters .PerunFilterConstants .FILTER_PREFIX ;
5
6
import static cz .muni .ics .oidc .server .filters .PerunFilterConstants .IDP_ENTITY_ID_PREFIX ;
7
+ import static cz .muni .ics .oidc .server .filters .PerunFilterConstants .PARAM_CLIENT_ID ;
6
8
import static cz .muni .ics .oidc .server .filters .PerunFilterConstants .PARAM_PROMPT ;
7
9
import static cz .muni .ics .oidc .server .filters .PerunFilterConstants .REFEDS_MFA ;
8
10
14
16
import cz .muni .ics .oidc .server .filters .PerunFilterConstants ;
15
17
import java .io .IOException ;
16
18
import java .util .ArrayList ;
19
+ import java .util .Arrays ;
17
20
import java .util .HashMap ;
21
+ import java .util .HashSet ;
22
+ import java .util .LinkedList ;
18
23
import java .util .List ;
19
24
import java .util .Map ;
25
+ import java .util .Set ;
20
26
import javax .servlet .ServletException ;
21
27
import javax .servlet .http .HttpServletRequest ;
22
28
import javax .servlet .http .HttpServletResponse ;
@@ -43,14 +49,18 @@ public class PerunSamlEntryPoint extends SAMLEntryPoint {
43
49
private final PerunAdapter perunAdapter ;
44
50
private final PerunOidcConfig config ;
45
51
private final FacilityAttrsConfig facilityAttrsConfig ;
52
+ private final SamlProperties samlProperties ;
46
53
47
54
@ Autowired
48
- public PerunSamlEntryPoint (PerunAdapter perunAdapter , PerunOidcConfig config ,
49
- FacilityAttrsConfig facilityAttrsConfig )
55
+ public PerunSamlEntryPoint (PerunAdapter perunAdapter ,
56
+ PerunOidcConfig config ,
57
+ FacilityAttrsConfig facilityAttrsConfig ,
58
+ SamlProperties samlProperties )
50
59
{
51
60
this .perunAdapter = perunAdapter ;
52
61
this .config = config ;
53
62
this .facilityAttrsConfig = facilityAttrsConfig ;
63
+ this .samlProperties = samlProperties ;
54
64
}
55
65
56
66
@ Override
@@ -163,15 +173,57 @@ private void processAcrValues(HttpServletRequest request, WebSSOProfileOptions o
163
173
options .setForceAuthN (true );
164
174
}
165
175
176
+ if (StringUtils .hasText (request .getParameter (PARAM_CLIENT_ID )) && config .isAddClientIdToAcrs ()) {
177
+ String clientIdAcr = CLIENT_ID_PREFIX + request .getParameter (PARAM_CLIENT_ID );
178
+ log .debug ("Adding client_id ACR ({}) to list of AuthnContextClassRefs for purposes" +
179
+ " of displaying service name on the wayf" , clientIdAcr );
180
+ acrs .add (clientIdAcr );
181
+ }
182
+
166
183
if (acrs .size () > 0 ) {
184
+
185
+
167
186
options .setAuthnContexts (acrs );
168
187
log .debug ("Transformed acr_values ({}) to SAML AuthnContextClassRef ({})" ,
169
188
acrValues , options .getAuthnContexts ());
170
189
}
171
190
}
172
191
192
+ private void processAcrs (List <String > acrs ) {
193
+ if (acrs == null || acrs .isEmpty ()) {
194
+ return ;
195
+ }
196
+
197
+ String [] reservedAcrsPrefixes = samlProperties .getAcrReservedPrefixes ();
198
+ Set <String > reservedPrefixes = (reservedAcrsPrefixes != null ) ?
199
+ new HashSet <>(Arrays .asList (reservedAcrsPrefixes )) : new HashSet <>();
200
+ if (reservedPrefixes .isEmpty ()) {
201
+ return ;
202
+ }
203
+
204
+ boolean hasNonReserved = false ;
205
+ for (String prefix : reservedPrefixes ) {
206
+ for (String acr : acrs ) {
207
+ if (!acr .startsWith (prefix )) {
208
+ log .debug ("ACR with non reserved prefix found: {}" , acr );
209
+ hasNonReserved = true ;
210
+ break ;
211
+ }
212
+ }
213
+ if (hasNonReserved ) {
214
+ break ;
215
+ }
216
+ }
217
+
218
+ if (!hasNonReserved ) {
219
+ List <String > toBeAdded = new LinkedList <>(Arrays .asList (samlProperties .getAcrsToBeAdded ()));
220
+ log .debug ("NO ACR with non reserved prefix found, adding following: {}" , toBeAdded );
221
+ acrs .addAll (toBeAdded );
222
+ }
223
+ }
224
+
173
225
private List <String > convertAcrValuesToList (String acrValues ) {
174
- List <String > acrs = new ArrayList <>();
226
+ List <String > acrs = new LinkedList <>();
175
227
if (StringUtils .hasText (acrValues )) {
176
228
String [] parts = acrValues .split (" " );
177
229
if (parts .length > 0 ) {
0 commit comments