16
16
17
17
package org .springframework .security .config .annotation .web .configurers .saml2 ;
18
18
19
- import java .io .ByteArrayOutputStream ;
20
19
import java .io .IOException ;
21
20
import java .net .URLDecoder ;
22
- import java .nio .charset .StandardCharsets ;
23
21
import java .time .Duration ;
24
- import java .util .Arrays ;
25
22
import java .util .Base64 ;
26
23
import java .util .Collection ;
27
24
import java .util .Collections ;
28
- import java .util .zip .Inflater ;
29
- import java .util .zip .InflaterOutputStream ;
30
25
31
26
import javax .servlet .ServletException ;
32
27
import javax .servlet .http .HttpServletRequest ;
63
58
import org .springframework .security .core .GrantedAuthority ;
64
59
import org .springframework .security .core .authority .SimpleGrantedAuthority ;
65
60
import org .springframework .security .core .authority .mapping .GrantedAuthoritiesMapper ;
66
- import org .springframework .security .saml2 .Saml2Exception ;
67
61
import org .springframework .security .saml2 .core .Saml2ErrorCodes ;
68
62
import org .springframework .security .saml2 .core .Saml2Utils ;
69
63
import org .springframework .security .saml2 .core .TestSaml2X509Credentials ;
112
106
public class Saml2LoginConfigurerTests {
113
107
114
108
private static final Converter <Assertion , Collection <? extends GrantedAuthority >> AUTHORITIES_EXTRACTOR = (
115
- a ) -> Arrays . asList (new SimpleGrantedAuthority ("TEST" ));
109
+ a ) -> Collections . singletonList (new SimpleGrantedAuthority ("TEST" ));
116
110
117
- private static final GrantedAuthoritiesMapper AUTHORITIES_MAPPER = (authorities ) -> Arrays
118
- .asList (new SimpleGrantedAuthority ("TEST CONVERTED" ));
111
+ private static final GrantedAuthoritiesMapper AUTHORITIES_MAPPER = (authorities ) -> Collections
112
+ .singletonList (new SimpleGrantedAuthority ("TEST CONVERTED" ));
119
113
120
114
private static final Duration RESPONSE_TIME_VALIDATION_SKEW = Duration .ZERO ;
121
115
@@ -194,7 +188,7 @@ public void authenticationRequestWhenAuthnRequestContextConverterThenUses() thro
194
188
UriComponents components = UriComponentsBuilder .fromHttpUrl (result .getResponse ().getRedirectedUrl ()).build ();
195
189
String samlRequest = components .getQueryParams ().getFirst ("SAMLRequest" );
196
190
String decoded = URLDecoder .decode (samlRequest , "UTF-8" );
197
- String inflated = samlInflate (samlDecode (decoded ));
191
+ String inflated = Saml2Utils . samlInflate (Saml2Utils . samlDecode (decoded ));
198
192
assertThat (inflated ).contains ("ForceAuthn=\" true\" " );
199
193
}
200
194
@@ -205,7 +199,7 @@ public void authenticateWhenCustomAuthenticationConverterThenUses() throws Excep
205
199
.assertingPartyDetails ((party ) -> party .verificationX509Credentials (
206
200
(c ) -> c .add (TestSaml2X509Credentials .relyingPartyVerifyingCredential ())))
207
201
.build ();
208
- String response = new String (samlDecode (SIGNED_RESPONSE ));
202
+ String response = new String (Saml2Utils . samlDecode (SIGNED_RESPONSE ));
209
203
given (CustomAuthenticationConverter .authenticationConverter .convert (any (HttpServletRequest .class )))
210
204
.willReturn (new Saml2AuthenticationToken (relyingPartyRegistration , response ));
211
205
// @formatter:off
@@ -268,26 +262,6 @@ private void performSaml2Login(String expected) throws IOException, ServletExcep
268
262
.hasToString (expected );
269
263
}
270
264
271
- private static org .apache .commons .codec .binary .Base64 BASE64 = new org .apache .commons .codec .binary .Base64 (0 ,
272
- new byte [] { '\n' });
273
-
274
- private static byte [] samlDecode (String s ) {
275
- return BASE64 .decode (s );
276
- }
277
-
278
- private static String samlInflate (byte [] b ) {
279
- try {
280
- ByteArrayOutputStream out = new ByteArrayOutputStream ();
281
- InflaterOutputStream iout = new InflaterOutputStream (out , new Inflater (true ));
282
- iout .write (b );
283
- iout .finish ();
284
- return new String (out .toByteArray (), StandardCharsets .UTF_8 );
285
- }
286
- catch (IOException ex ) {
287
- throw new Saml2Exception ("Unable to inflate string" , ex );
288
- }
289
- }
290
-
291
265
private static AuthenticationManager getAuthenticationManagerMock (String role ) {
292
266
return new AuthenticationManager () {
293
267
@ Override
0 commit comments