Skip to content

Commit a55c25c

Browse files
barchettatjquinno
andauthored
For MP CORS, suppress explanation of rejection in response; log it instead (#10655) (#10671)
Signed-off-by: Tim Quinn <[email protected]> Co-authored-by: Tim Quinn <[email protected]>
1 parent df78452 commit a55c25c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

microprofile/cors/src/main/java/io/helidon/microprofile/cors/CorsSupportMp.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2025 Oracle and/or its affiliates.
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.
@@ -42,6 +42,8 @@
4242
*/
4343
class CorsSupportMp extends CorsSupportBase<ContainerRequestContext, Response, CorsSupportMp, CorsSupportMp.Builder> {
4444

45+
private static final System.Logger LOGGER = System.getLogger(CorsSupportMp.class.getName());
46+
4547
/**
4648
*
4749
* @return a new builder of CorsSupportMp
@@ -205,7 +207,8 @@ public CorsResponseAdapter<Response> header(HeaderName key, Object value) {
205207

206208
@Override
207209
public Response forbidden(String message) {
208-
return Response.status(Response.Status.FORBIDDEN).entity(message).build();
210+
LOGGER.log(System.Logger.Level.TRACE, "Rejecting CORS request: " + message);
211+
return Response.status(Response.Status.FORBIDDEN).build();
209212
}
210213

211214
@Override

microprofile/cors/src/test/java/io/helidon/microprofile/cors/CrossOriginTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2025 Oracle and/or its affiliates.
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.
@@ -31,6 +31,7 @@
3131
import jakarta.ws.rs.client.WebTarget;
3232
import jakarta.ws.rs.core.MediaType;
3333
import jakarta.ws.rs.core.Response;
34+
import org.hamcrest.Matchers;
3435
import org.junit.jupiter.api.Test;
3536

3637
import static io.helidon.http.HeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS;
@@ -45,6 +46,7 @@
4546
import static org.hamcrest.CoreMatchers.is;
4647
import static org.hamcrest.CoreMatchers.nullValue;
4748
import static org.hamcrest.MatcherAssert.assertThat;
49+
import static org.hamcrest.Matchers.isEmptyString;
4850

4951
/**
5052
* Class CrossOriginTest.
@@ -201,6 +203,7 @@ void test2PreFlightForbiddenOrigin() {
201203
.header(ACCESS_CONTROL_REQUEST_METHOD.defaultCase(), "PUT")
202204
.options();
203205
assertThat(res.getStatusInfo(), is(Response.Status.FORBIDDEN));
206+
assertThat(res.readEntity(String.class), isEmptyString());
204207
}
205208

206209
@Test
@@ -226,6 +229,7 @@ void test2PreFlightForbiddenMethod() {
226229
.header(ACCESS_CONTROL_REQUEST_METHOD.defaultCase(), "POST")
227230
.options();
228231
assertThat(res.getStatusInfo(), is(Response.Status.FORBIDDEN));
232+
assertThat(res.readEntity(String.class), isEmptyString());
229233
}
230234

231235
@Test
@@ -237,6 +241,7 @@ void test2PreFlightForbiddenHeader() {
237241
.header(ACCESS_CONTROL_REQUEST_HEADERS.defaultCase(), "X-foo, X-bar, X-oops")
238242
.options();
239243
assertThat(res.getStatusInfo(), is(Response.Status.FORBIDDEN));
244+
assertThat(res.readEntity(String.class), isEmptyString());
240245
}
241246

242247
@Test

0 commit comments

Comments
 (0)