-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RESTEasy Classic - apply ex. mappers for auth failures before processing
(cherry picked from commit 8bfa76e)
- Loading branch information
1 parent
7f3f666
commit a0f316d
Showing
8 changed files
with
273 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...test/java/io/quarkus/resteasy/test/security/HttpPolicyAuthFailureExceptionMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.quarkus.resteasy.test.security; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.security.AuthenticationFailedException; | ||
import io.quarkus.security.test.utils.TestIdentityController; | ||
import io.quarkus.security.test.utils.TestIdentityProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class HttpPolicyAuthFailureExceptionMapperTest { | ||
|
||
private static final String EXPECTED_RESPONSE = "expect response"; | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(TestIdentityProvider.class, TestIdentityController.class) | ||
.addAsResource( | ||
new StringAsset("quarkus.http.auth.proactive=false\n" + | ||
"quarkus.http.auth.permission.basic.paths=/*\n" + | ||
"quarkus.http.auth.permission.basic.policy=authenticated\n"), | ||
"application.properties")); | ||
|
||
@BeforeAll | ||
public static void setupUsers() { | ||
TestIdentityController.resetRoles() | ||
.add("user", "user", "user"); | ||
} | ||
|
||
@Test | ||
public void testAuthFailedExceptionMapper() { | ||
RestAssured | ||
.given() | ||
.auth().basic("user", "unknown-pwd") | ||
.get("/") | ||
.then() | ||
.statusCode(401) | ||
.body(Matchers.equalTo(EXPECTED_RESPONSE)); | ||
} | ||
|
||
@Provider | ||
public static class AuthFailedExceptionMapper implements ExceptionMapper<AuthenticationFailedException> { | ||
|
||
@Override | ||
public Response toResponse(AuthenticationFailedException exception) { | ||
return Response.status(401).entity(EXPECTED_RESPONSE).build(); | ||
} | ||
} | ||
|
||
@Path("hello") | ||
public static final class HelloResource { | ||
|
||
@GET | ||
public String hello() { | ||
return "hello world"; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...tron-resteasy/src/main/java/io/quarkus/it/resteasy/elytron/AuthFailedExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quarkus.it.resteasy.elytron; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import io.quarkus.security.AuthenticationFailedException; | ||
|
||
@Provider | ||
public class AuthFailedExceptionMapper implements ExceptionMapper<AuthenticationFailedException> { | ||
|
||
static final String EXPECTED_RESPONSE = "expected response"; | ||
|
||
@Override | ||
public Response toResponse(AuthenticationFailedException exception) { | ||
return Response.status(401).entity(EXPECTED_RESPONSE).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.