From 739cdc1a4ca160ca36b2e231b0ec2228129fb9aa Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Thu, 18 Nov 2021 13:30:23 -0700 Subject: [PATCH] Polish AuthRequestConverter Sample Doc Issue gh-10364 --- .../saml2/login/authentication-requests.adoc | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/docs/modules/ROOT/pages/servlet/saml2/login/authentication-requests.adoc b/docs/modules/ROOT/pages/servlet/saml2/login/authentication-requests.adoc index 3a299c96b9..ba512b5a4a 100644 --- a/docs/modules/ROOT/pages/servlet/saml2/login/authentication-requests.adoc +++ b/docs/modules/ROOT/pages/servlet/saml2/login/authentication-requests.adoc @@ -195,17 +195,18 @@ public class AuthnRequestConverter implements // ... constructor public AuthnRequest convert(Saml2AuthenticationRequestContext context) { + MySaml2AuthenticationRequestContext myContext = (MySaml2AuthenticationRequestContext) context; Issuer issuer = issuerBuilder.buildObject(); - issuer.setValue(context.getIssuer()); + issuer.setValue(myContext.getIssuer()); AuthnRequest authnRequest = authnRequestBuilder.buildObject(); authnRequest.setIssuer(issuer); - authnRequest.setDestination(context.getDestination()); - authnRequest.setAssertionConsumerServiceURL(context.getAssertionConsumerServiceUrl()); + authnRequest.setDestination(myContext.getDestination()); + authnRequest.setAssertionConsumerServiceURL(myContext.getAssertionConsumerServiceUrl()); // ... additional settings - authRequest.setForceAuthn(context.getForceAuthn()); + authRequest.setForceAuthn(myContext.getForceAuthn()); return authnRequest; } } @@ -220,16 +221,17 @@ class AuthnRequestConverter : Converter { - Saml2AuthenticationRequestContext context = resolver.resolve(request); - return context; - }; + Saml2AuthenticationRequestContextResolver resolver = + new DefaultSaml2AuthenticationRequestContextResolver(); + return request -> { + Saml2AuthenticationRequestContext context = resolver.resolve(request); + return new MySaml2AuthenticationRequestContext(context, request.getParameter("force") != null); + }; } @Bean @@ -267,9 +270,13 @@ Saml2AuthenticationRequestFactory authenticationRequestFactory( ---- @Bean open fun authenticationRequestContextResolver(): Saml2AuthenticationRequestContextResolver { - val resolver = DefaultSaml2AuthenticationRequestContextResolver(relyingPartyRegistrationResolver) - return Saml2AuthenticationRequestContextResolver { request -> - resolver.resolve(request) + val resolver: Saml2AuthenticationRequestContextResolver = DefaultSaml2AuthenticationRequestContextResolver() + return Saml2AuthenticationRequestContextResolver { request: HttpServletRequest -> + val context = resolver.resolve(request) + MySaml2AuthenticationRequestContext( + context, + request.getParameter("force") != null + ) } }