Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion toolkit/src/main/java/org/codelibs/saml2/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,11 @@ public void processResponse(final String requestId) {
errorReason = samlResponse.getError();
validationException = samlResponse.getValidationException();
final SamlResponseStatus samlResponseStatus = samlResponse.getResponseStatus();
if (samlResponseStatus.getStatusCode() == null || !Constants.STATUS_SUCCESS.equals(samlResponseStatus.getStatusCode())) {
// The status is read after the version and the ID are checked, so it is null when the
// response failed one of those (a document that is not a SAML response at all, for example).
// That is an invalid response like any other, not a status the IdP reported.
if (samlResponseStatus != null
&& (samlResponseStatus.getStatusCode() == null || !Constants.STATUS_SUCCESS.equals(samlResponseStatus.getStatusCode()))) {
errors.add("response_not_success");
// Debug rather than warn: "response_not_success" is already in getErrors(), and
// the detail is in getLastErrorReason() and getLastValidationException(). Logging
Expand Down
21 changes: 21 additions & 0 deletions toolkit/src/test/java/org/codelibs/saml2/test/AuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,27 @@ public void testProcessSLOResponseStatusResponder() throws Exception {
* @see org.codelibs.saml2.Auth#getErrors
* @see org.codelibs.saml2.Auth#getLastErrorReason
*/
/**
* A well-formed document that is not a SAML response has no Version and no Status, so the response
* is refused before its status is read. processResponse must report that as an invalid response, not
* throw a NullPointerException on the missing status.
*/
@Test
public void testProcessResponseWithoutStatus() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
String samlResponseEncoded = java.util.Base64.getEncoder().encodeToString("<foo/>".getBytes(java.nio.charset.StandardCharsets.UTF_8));
when(request.getParameterMap()).thenReturn(singletonMap("SAMLResponse", new String[] { samlResponseEncoded }));
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/java-saml-jspsample/acs.jsp"));

Saml2Settings settings = new SettingsBuilder().fromFile("config/config.my.properties").build();
Auth auth = new Auth(settings, request, response);
auth.processResponse();
assertFalse(auth.isAuthenticated());
assertEquals(java.util.Collections.singletonList("invalid_response"), auth.getErrors());
assertTrue(auth.getLastValidationException() instanceof ValidationException);
}

@Test
public void testIsAuthenticated() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
Expand Down
Loading