Skip to content

Commit 5354e4d

Browse files
committed
Check for Null Issuer
Closes gh-16989
1 parent db48d4c commit 5354e4d

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

+10-3
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.
@@ -391,7 +391,7 @@ public static Converter<ResponseToken, Saml2ResponseValidatorResult> createDefau
391391
String inResponseTo = response.getInResponseTo();
392392
result = result.concat(validateInResponseTo(token.getAuthenticationRequest(), inResponseTo));
393393

394-
String issuer = response.getIssuer().getValue();
394+
String issuer = issuer(response);
395395
String destination = response.getDestination();
396396
String location = token.getRelyingPartyRegistration().getAssertionConsumerServiceLocation();
397397
if (StringUtils.hasText(destination) && !destination.equals(location)) {
@@ -414,6 +414,13 @@ public static Converter<ResponseToken, Saml2ResponseValidatorResult> createDefau
414414
};
415415
}
416416

417+
private static String issuer(Response response) {
418+
if (response.getIssuer() == null) {
419+
return null;
420+
}
421+
return response.getIssuer().getValue();
422+
}
423+
417424
private static List<String> getStatusCodes(Response response) {
418425
if (response.getStatus() == null) {
419426
return List.of(StatusCode.SUCCESS);
@@ -576,7 +583,7 @@ private Response parseResponse(String response) throws Saml2Exception, Saml2Auth
576583
}
577584

578585
private void process(Saml2AuthenticationToken token, Response response) {
579-
String issuer = response.getIssuer().getValue();
586+
String issuer = issuer(response);
580587
this.logger.debug(LogMessage.format("Processing SAML response from %s", issuer));
581588
boolean responseSigned = response.isSigned();
582589

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

+10-1
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.
@@ -861,6 +861,15 @@ public void authenticateWhenClockSkewThenVerifiesSignature() {
861861
provider.authenticate(token);
862862
}
863863

864+
// gh-16989
865+
@Test
866+
public void authenticateWhenNullIssuerThenNoNullPointer() {
867+
OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
868+
Response response = TestOpenSamlObjects.signedResponseWithOneAssertion((r) -> r.setIssuer(null));
869+
Saml2AuthenticationToken token = token(response, verifying(registration()));
870+
assertThatExceptionOfType(Saml2AuthenticationException.class).isThrownBy(() -> provider.authenticate(token));
871+
}
872+
864873
private <T extends XMLObject> T build(QName qName) {
865874
return (T) XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(qName).buildObject(qName);
866875
}

0 commit comments

Comments
 (0)