1616
1717package org .springframework .security .saml2 .provider .service .web ;
1818
19- import java .util .Objects ;
20-
21- import jakarta .servlet .http .HttpServletRequest ;
22- import org .jspecify .annotations .Nullable ;
23- import org .opensaml .core .xml .schema .XSString ;
24- import org .opensaml .saml .saml2 .core .Issuer ;
2519import org .opensaml .saml .saml2 .core .Response ;
26-
2720import org .springframework .http .HttpMethod ;
21+
22+ import org .jspecify .annotations .Nullable ;
2823import org .springframework .security .saml2 .core .OpenSamlInitializationService ;
2924import org .springframework .security .saml2 .core .Saml2Error ;
3025import org .springframework .security .saml2 .core .Saml2ParameterNames ;
3530import org .springframework .security .saml2 .provider .service .registration .RelyingPartyRegistrationRepository ;
3631import org .springframework .security .saml2 .provider .service .web .RelyingPartyRegistrationPlaceholderResolvers .UriResolver ;
3732import org .springframework .security .web .authentication .AuthenticationConverter ;
33+ import static org .springframework .security .web .servlet .util .matcher .PathPatternRequestMatcher .pathPattern ;
3834import org .springframework .security .web .util .matcher .OrRequestMatcher ;
3935import org .springframework .security .web .util .matcher .RequestMatcher ;
4036import org .springframework .util .Assert ;
4137
42- import static org . springframework . security . web . servlet .util . matcher . PathPatternRequestMatcher . pathPattern ;
38+ import jakarta . servlet .http . HttpServletRequest ;
4339
4440final class BaseOpenSamlAuthenticationTokenConverter implements AuthenticationConverter {
4541
@@ -96,8 +92,14 @@ final class BaseOpenSamlAuthenticationTokenConverter implements AuthenticationCo
9692 * @throws Saml2AuthenticationException if the {@link RequestMatcher} specifies a
9793 * non-existent {@code registrationId}
9894 */
95+
9996 @ Override
97+ <<<<<<< HEAD
10098 public @ Nullable Saml2AuthenticationToken convert (HttpServletRequest request ) {
99+ =======
100+ @ Nullable
101+ public Saml2AuthenticationToken convert (HttpServletRequest request ) {
102+ >>>>>>> 46f fe65384 (Added nullable )
101103 String serialized = request .getParameter (Saml2ParameterNames .SAML_RESPONSE );
102104 if (serialized == null ) {
103105 return null ;
@@ -115,8 +117,9 @@ final class BaseOpenSamlAuthenticationTokenConverter implements AuthenticationCo
115117 }
116118 return token ;
117119 }
118-
119- private @ Nullable Saml2AuthenticationToken tokenByAuthenticationRequest (HttpServletRequest request ) {
120+
121+ @ Nullable
122+ private Saml2AuthenticationToken tokenByAuthenticationRequest (HttpServletRequest request ) {
120123 AbstractSaml2AuthenticationRequest authenticationRequest = this .authenticationRequests
121124 .loadAuthenticationRequest (request );
122125 if (authenticationRequest == null ) {
@@ -129,8 +132,9 @@ final class BaseOpenSamlAuthenticationTokenConverter implements AuthenticationCo
129132 RelyingPartyRegistration registration = this .registrations .findByRegistrationId (registrationId );
130133 return tokenByRegistration (request , registration , authenticationRequest );
131134 }
132-
133- private @ Nullable Saml2AuthenticationToken tokenByRegistrationId (HttpServletRequest request ,
135+
136+ @ Nullable
137+ private Saml2AuthenticationToken tokenByRegistrationId (HttpServletRequest request ,
134138 RequestMatcher .MatchResult result ) {
135139 String registrationId = result .getVariables ().get ("registrationId" );
136140 if (registrationId == null ) {
@@ -140,21 +144,18 @@ final class BaseOpenSamlAuthenticationTokenConverter implements AuthenticationCo
140144 return tokenByRegistration (request , registration , null );
141145 }
142146
143- private @ Nullable Saml2AuthenticationToken tokenByEntityId (HttpServletRequest request ) {
144- String decoded = decode (request );
145- if (decoded == null ) {
146- return null ;
147- }
148- Response response = this .saml .deserialize (decoded );
149- Issuer issuer = response .getIssuer ();
150- Assert .notNull (issuer , "Response#Issuer cannot be null" );
151- RelyingPartyRegistration registration = this .registrations .findUniqueByAssertingPartyEntityId (getValue (issuer ));
147+ @ Nullable
148+ private Saml2AuthenticationToken tokenByEntityId (HttpServletRequest request ) {
149+ Response response = this .saml .deserialize (decode (request ));
150+ String issuer = response .getIssuer ().getValue ();
151+ RelyingPartyRegistration registration = this .registrations .findUniqueByAssertingPartyEntityId (issuer );
152152 return tokenByRegistration (request , registration , null );
153153 }
154154
155- private @ Nullable Saml2AuthenticationToken tokenByRegistration (HttpServletRequest request ,
156- @ Nullable RelyingPartyRegistration registration ,
157- @ Nullable AbstractSaml2AuthenticationRequest authenticationRequest ) {
155+ @ Nullable
156+ private Saml2AuthenticationToken tokenByRegistration (HttpServletRequest request ,
157+ @ Nullable RelyingPartyRegistration registration ,
158+ @ Nulable AbstractSaml2AuthenticationRequest authenticationRequest ) {
158159 if (registration == null ) {
159160 return null ;
160161 }
@@ -205,7 +206,8 @@ void setShouldConvertGetRequests(boolean shouldConvertGetRequests) {
205206 this .shouldConvertGetRequests = shouldConvertGetRequests ;
206207 }
207208
208- private @ Nullable String decode (HttpServletRequest request ) {
209+ @ Nullable
210+ private String decode (HttpServletRequest request ) {
209211 String encoded = request .getParameter (Saml2ParameterNames .SAML_RESPONSE );
210212 boolean isGet = HttpMethod .GET .matches (request .getMethod ());
211213 if (!this .shouldConvertGetRequests && isGet ) {
0 commit comments