forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#20060 from geoand/2.2.3-backports1
2.2.3 backports1
- Loading branch information
Showing
9 changed files
with
182 additions
and
12 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
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
111 changes: 111 additions & 0 deletions
111
...ava/io/quarkus/resteasy/reactive/server/test/security/SecurityWithMethodGenericsTest.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,111 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.jboss.resteasy.reactive.server.providers.serialisers.ServerDefaultTextPlainBodyHandler; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.security.Authenticated; | ||
import io.quarkus.security.test.utils.TestIdentityController; | ||
import io.quarkus.security.test.utils.TestIdentityProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.restassured.specification.RequestSpecification; | ||
|
||
public class SecurityWithMethodGenericsTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(TestIdentityProvider.class, | ||
TestIdentityController.class, | ||
BaseResource.class, AuthenticatedResource.class, | ||
CustomServerDefaultTextPlainBodyHandler.class)); | ||
|
||
@BeforeAll | ||
public static void setupUsers() { | ||
TestIdentityController.resetRoles() | ||
.add("admin", "admin", "admin") | ||
.add("user", "user", "user"); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
requestWithBasicAuth().get("/auth/allow").then().statusCode(200) | ||
.body(is("allow")); | ||
requestWithBasicAuth().contentType(MediaType.TEXT_PLAIN).body("12345") | ||
.post("/auth/generic").then() | ||
.statusCode(200); | ||
requestWithBasicAuth().contentType(MediaType.TEXT_PLAIN).body("54321").post("/auth/specific").then() | ||
.statusCode(200); | ||
} | ||
|
||
private RequestSpecification requestWithBasicAuth() { | ||
return RestAssured.given().auth().preemptive().basic("admin", "admin"); | ||
} | ||
|
||
public static abstract class BaseResource<T> { | ||
|
||
@Path("generic") | ||
@POST | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
public String generic(T body) { | ||
return "generic"; | ||
} | ||
|
||
@Path("specific") | ||
@POST | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
public String specific(String body) { | ||
return "specific"; | ||
} | ||
} | ||
|
||
@Path("auth") | ||
@Authenticated | ||
public static class AuthenticatedResource extends BaseResource<String> { | ||
|
||
@Path("allow") | ||
@GET | ||
public String allow() { | ||
return "allow"; | ||
} | ||
} | ||
|
||
@Provider | ||
@Consumes("text/plain") | ||
public static class CustomServerDefaultTextPlainBodyHandler extends ServerDefaultTextPlainBodyHandler { | ||
|
||
@Override | ||
public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, | ||
MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { | ||
return "dummy"; | ||
} | ||
} | ||
} |
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
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