[java-oidc-common] branch main updated: JCOMOIDC-197 - JSONErrorResponse returns true for indicatesSuccess
Codeberg
noreply at shibboleth.net
Thu Nov 26 12:19:01 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-oidc-common.
View the commit online:
https://codeberg.org/Shibboleth/java-oidc-common/commit/8123c4898e810fbca4ec1184bf29121473f562d1
The following commit(s) were added to refs/heads/main by this push:
new 8123c489 JCOMOIDC-197 - JSONErrorResponse returns true for indicatesSuccess
8123c489 is described below
commit 8123c4898e810fbca4ec1184bf29121473f562d1
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Thu Nov 26 12:18:49 2026 +0000
JCOMOIDC-197 - JSONErrorResponse returns true for indicatesSuccess
- Change indicateSuccess to return false, as this is an error response
- Guard against a Nimbus ErrorObject from returning a 0 HTTP status
code, add 400 if it does.
- change deprecated setContent to correct setBody.
https://shibboleth.atlassian.net/browse/JCOMOIDC-197
---
.../oidc/profile/messaging/JSONErrorResponse.java | 17 +++---
.../profile/messaging/JSONErrorResponseTest.java | 71 ++++++++++++++++++++++
2 files changed, 79 insertions(+), 9 deletions(-)
diff --git a/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/messaging/JSONErrorResponse.java b/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/messaging/JSONErrorResponse.java
index 5d5bc7a4..63f06c2e 100644
--- a/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/messaging/JSONErrorResponse.java
+++ b/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/messaging/JSONErrorResponse.java
@@ -33,13 +33,13 @@ import net.shibboleth.shared.logic.Constraint;
public class JSONErrorResponse implements ErrorResponse {
/** Error object. */
- private ErrorObject error;
+ private final ErrorObject error;
/** cache control value. */
- private String cacheControl;
+ private final String cacheControl;
/** pragma value. */
- private String pragma;
+ private final String pragma;
/**
* Constructor.
@@ -68,7 +68,7 @@ public class JSONErrorResponse implements ErrorResponse {
/** {@inheritDoc} */
@Override
public boolean indicatesSuccess() {
- return true;
+ return false;
}
/**
@@ -78,9 +78,6 @@ public class JSONErrorResponse implements ErrorResponse {
*/
private String getContent() {
final JSONObject content = new JSONObject();
- if (error == null) {
- return null;
- }
content.put("error", error.getCode());
if (error.getDescription() != null) {
content.put("error_description", error.getDescription());
@@ -94,7 +91,9 @@ public class JSONErrorResponse implements ErrorResponse {
/** {@inheritDoc} */
@Override
public HTTPResponse toHTTPResponse() {
- final HTTPResponse httpResponse = new HTTPResponse(error.getHTTPStatusCode());
+ final int statusCode = error.getHTTPStatusCode();
+ final HTTPResponse httpResponse =
+ new HTTPResponse(statusCode > 0 ? statusCode : HTTPResponse.SC_BAD_REQUEST);
httpResponse.setEntityContentType(ContentType.APPLICATION_JSON);
if (cacheControl != null) {
httpResponse.setCacheControl(cacheControl);
@@ -102,7 +101,7 @@ public class JSONErrorResponse implements ErrorResponse {
if (pragma != null) {
httpResponse.setPragma(pragma);
}
- httpResponse.setContent(getContent());
+ httpResponse.setBody(getContent());
return httpResponse;
}
diff --git a/oidc-common-profile-api/src/test/java/net/shibboleth/oidc/profile/messaging/JSONErrorResponseTest.java b/oidc-common-profile-api/src/test/java/net/shibboleth/oidc/profile/messaging/JSONErrorResponseTest.java
new file mode 100644
index 00000000..0536f789
--- /dev/null
+++ b/oidc-common-profile-api/src/test/java/net/shibboleth/oidc/profile/messaging/JSONErrorResponseTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.oidc.profile.messaging;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.nimbusds.oauth2.sdk.ErrorObject;
+import com.nimbusds.oauth2.sdk.http.HTTPResponse;
+
+import net.minidev.json.JSONObject;
+import net.minidev.json.parser.JSONParser;
+import net.minidev.json.parser.ParseException;
+
+/** Tests for {@link JSONErrorResponse}. */
+ at SuppressWarnings("null")
+public class JSONErrorResponseTest {
+
+ private JSONErrorResponse response;
+
+ ErrorObject content;
+
+ @BeforeMethod
+ public void init() throws ParseException {
+ content = new ErrorObject("errorCode", "errorDescription", HTTPResponse.SC_BAD_REQUEST);
+ }
+
+ @Test
+ public void testSuccess() throws ParseException {
+ response = new JSONErrorResponse(content, "no-store", "no-cache");
+ Assert.assertFalse(response.indicatesSuccess());
+ final HTTPResponse httpResponse = response.toHTTPResponse();
+ Assert.assertEquals(HTTPResponse.SC_BAD_REQUEST, httpResponse.getStatusCode());
+ Assert.assertEquals("application/json; charset=UTF-8", httpResponse.getEntityContentType().toString());
+ Assert.assertEquals("no-store", httpResponse.getCacheControl());
+ Assert.assertEquals("no-cache", httpResponse.getPragma());
+ final JSONObject parsedContent =
+ (JSONObject) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(httpResponse.getContent());
+ Assert.assertEquals("errorCode", parsedContent.get("error"));
+ Assert.assertEquals("errorDescription", parsedContent.get("error_description"));
+ }
+
+ @Test
+ public void testSuccess2() throws ParseException {
+ response = new JSONErrorResponse(content);
+ Assert.assertFalse(response.indicatesSuccess());
+ final HTTPResponse httpResponse = response.toHTTPResponse();
+ Assert.assertEquals(HTTPResponse.SC_BAD_REQUEST, httpResponse.getStatusCode());
+ Assert.assertEquals("application/json; charset=UTF-8", httpResponse.getEntityContentType().toString());
+ Assert.assertNull(httpResponse.getCacheControl());
+ Assert.assertNull(httpResponse.getPragma());
+ final JSONObject parsedContent =
+ (JSONObject) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(httpResponse.getContent());
+ Assert.assertEquals("errorCode", parsedContent.get("error"));
+ Assert.assertEquals("errorDescription", parsedContent.get("error_description"));
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list