Skip to content

Commit ce000ed

Browse files
committed
Merge branch '6.3.x' into 6.4.x
Closes gh-17008
2 parents e6957bb + 5354e4d commit ce000ed

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/authentication/BaseOpenSamlAuthenticationProvider.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -160,7 +160,7 @@ static Converter<ResponseToken, Saml2ResponseValidatorResult> createDefaultRespo
160160
String inResponseTo = response.getInResponseTo();
161161
result = result.concat(validateInResponseTo(token.getAuthenticationRequest(), inResponseTo));
162162

163-
String issuer = response.getIssuer().getValue();
163+
String issuer = issuer(response);
164164
String destination = response.getDestination();
165165
String location = token.getRelyingPartyRegistration().getAssertionConsumerServiceLocation();
166166
if (StringUtils.hasText(destination) && !destination.equals(location)) {
@@ -183,6 +183,13 @@ static Converter<ResponseToken, Saml2ResponseValidatorResult> createDefaultRespo
183183
};
184184
}
185185

186+
private static String issuer(Response response) {
187+
if (response.getIssuer() == null) {
188+
return null;
189+
}
190+
return response.getIssuer().getValue();
191+
}
192+
186193
private static List<String> getStatusCodes(Response response) {
187194
if (response.getStatus() == null) {
188195
return List.of(StatusCode.SUCCESS);
@@ -308,7 +315,7 @@ private Response parseResponse(String response) throws Saml2Exception, Saml2Auth
308315
}
309316

310317
private void process(Saml2AuthenticationToken token, Response response) {
311-
String issuer = response.getIssuer().getValue();
318+
String issuer = issuer(response);
312319
this.logger.debug(LogMessage.format("Processing SAML response from %s", issuer));
313320
boolean responseSigned = response.isSigned();
314321

saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProviderTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,15 @@ public void authenticateWhenClockSkewThenVerifiesSignature() {
889889
provider.authenticate(token);
890890
}
891891

892+
// gh-16989
893+
@Test
894+
public void authenticateWhenNullIssuerThenNoNullPointer() {
895+
OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
896+
Response response = TestOpenSamlObjects.signedResponseWithOneAssertion((r) -> r.setIssuer(null));
897+
Saml2AuthenticationToken token = token(response, verifying(registration()));
898+
assertThatExceptionOfType(Saml2AuthenticationException.class).isThrownBy(() -> provider.authenticate(token));
899+
}
900+
892901
private <T extends XMLObject> T build(QName qName) {
893902
return (T) XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(qName).buildObject(qName);
894903
}

0 commit comments

Comments
 (0)