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.
Add ability to specify default JAX-RS roles allowed
Also improve docs around this Fixes quarkusio#10362
- Loading branch information
1 parent
5cf94dc
commit 5a8bc59
Showing
13 changed files
with
492 additions
and
14 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
85 changes: 85 additions & 0 deletions
85
...loyment/src/test/java/io/quarkus/resteasy/test/security/DefaultRolesAllowedJaxRsTest.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,85 @@ | ||
package io.quarkus.resteasy.test.security; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.RestAssured.when; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
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.test.utils.TestIdentityController; | ||
import io.quarkus.security.test.utils.TestIdentityProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class DefaultRolesAllowedJaxRsTest { | ||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(PermitAllResource.class, UnsecuredResource.class, | ||
TestIdentityProvider.class, | ||
TestIdentityController.class, | ||
UnsecuredSubResource.class) | ||
.addAsResource(new StringAsset("quarkus.security.jaxrs.default-roles-allowed = admin\n"), | ||
"application.properties")); | ||
|
||
@BeforeAll | ||
public static void setupUsers() { | ||
TestIdentityController.resetRoles() | ||
.add("admin", "admin", "admin") | ||
.add("user", "user", "user"); | ||
} | ||
|
||
@Test | ||
public void shouldDenyUnannotated() { | ||
String path = "/unsecured/defaultSecurity"; | ||
assertStatus(path, 200, 403, 401); | ||
} | ||
|
||
@Test | ||
public void shouldDenyDenyAllMethod() { | ||
String path = "/unsecured/denyAll"; | ||
assertStatus(path, 403, 403, 401); | ||
} | ||
|
||
@Test | ||
public void shouldPermitPermitAllMethod() { | ||
assertStatus("/unsecured/permitAll", 200, 200, 200); | ||
} | ||
|
||
@Test | ||
public void shouldDenySubResource() { | ||
String path = "/unsecured/sub/subMethod"; | ||
assertStatus(path, 200, 403, 401); | ||
} | ||
|
||
@Test | ||
public void shouldAllowPermitAllSubResource() { | ||
String path = "/unsecured/permitAllSub/subMethod"; | ||
assertStatus(path, 200, 200, 200); | ||
} | ||
|
||
@Test | ||
public void shouldAllowPermitAllClass() { | ||
String path = "/permitAll/sub/subMethod"; | ||
assertStatus(path, 200, 200, 200); | ||
} | ||
|
||
private void assertStatus(String path, int adminStatus, int userStatus, int anonStatus) { | ||
given().auth().preemptive() | ||
.basic("admin", "admin").get(path) | ||
.then() | ||
.statusCode(adminStatus); | ||
given().auth().preemptive() | ||
.basic("user", "user").get(path) | ||
.then() | ||
.statusCode(userStatus); | ||
when().get(path) | ||
.then() | ||
.statusCode(anonStatus); | ||
|
||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
...ent/src/test/java/io/quarkus/resteasy/test/security/DefaultRolesAllowedStarJaxRsTest.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,85 @@ | ||
package io.quarkus.resteasy.test.security; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.RestAssured.when; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
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.test.utils.TestIdentityController; | ||
import io.quarkus.security.test.utils.TestIdentityProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class DefaultRolesAllowedStarJaxRsTest { | ||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(PermitAllResource.class, UnsecuredResource.class, | ||
TestIdentityProvider.class, | ||
TestIdentityController.class, | ||
UnsecuredSubResource.class) | ||
.addAsResource(new StringAsset("quarkus.security.jaxrs.default-roles-allowed = **\n"), | ||
"application.properties")); | ||
|
||
@BeforeAll | ||
public static void setupUsers() { | ||
TestIdentityController.resetRoles() | ||
.add("admin", "admin", "admin") | ||
.add("user", "user", "user"); | ||
} | ||
|
||
@Test | ||
public void shouldDenyUnannotated() { | ||
String path = "/unsecured/defaultSecurity"; | ||
assertStatus(path, 200, 200, 401); | ||
} | ||
|
||
@Test | ||
public void shouldDenyDenyAllMethod() { | ||
String path = "/unsecured/denyAll"; | ||
assertStatus(path, 403, 403, 401); | ||
} | ||
|
||
@Test | ||
public void shouldPermitPermitAllMethod() { | ||
assertStatus("/unsecured/permitAll", 200, 200, 200); | ||
} | ||
|
||
@Test | ||
public void shouldDenySubResource() { | ||
String path = "/unsecured/sub/subMethod"; | ||
assertStatus(path, 200, 200, 401); | ||
} | ||
|
||
@Test | ||
public void shouldAllowPermitAllSubResource() { | ||
String path = "/unsecured/permitAllSub/subMethod"; | ||
assertStatus(path, 200, 200, 200); | ||
} | ||
|
||
@Test | ||
public void shouldAllowPermitAllClass() { | ||
String path = "/permitAll/sub/subMethod"; | ||
assertStatus(path, 200, 200, 200); | ||
} | ||
|
||
private void assertStatus(String path, int adminStatus, int userStatus, int anonStatus) { | ||
given().auth().preemptive() | ||
.basic("admin", "admin").get(path) | ||
.then() | ||
.statusCode(adminStatus); | ||
given().auth().preemptive() | ||
.basic("user", "user").get(path) | ||
.then() | ||
.statusCode(userStatus); | ||
when().get(path) | ||
.then() | ||
.statusCode(anonStatus); | ||
|
||
} | ||
|
||
} |
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
85 changes: 85 additions & 0 deletions
85
.../java/io/quarkus/resteasy/reactive/server/test/security/DefaultRolesAllowedJaxRsTest.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,85 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.RestAssured.when; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
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.test.utils.TestIdentityController; | ||
import io.quarkus.security.test.utils.TestIdentityProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class DefaultRolesAllowedJaxRsTest { | ||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(PermitAllResource.class, UnsecuredResource.class, | ||
TestIdentityProvider.class, | ||
TestIdentityController.class, | ||
UnsecuredSubResource.class) | ||
.addAsResource(new StringAsset("quarkus.security.jaxrs.default-roles-allowed = admin\n"), | ||
"application.properties")); | ||
|
||
@BeforeAll | ||
public static void setupUsers() { | ||
TestIdentityController.resetRoles() | ||
.add("admin", "admin", "admin") | ||
.add("user", "user", "user"); | ||
} | ||
|
||
@Test | ||
public void shouldDenyUnannotated() { | ||
String path = "/unsecured/defaultSecurity"; | ||
assertStatus(path, 200, 403, 401); | ||
} | ||
|
||
@Test | ||
public void shouldDenyDenyAllMethod() { | ||
String path = "/unsecured/denyAll"; | ||
assertStatus(path, 403, 403, 401); | ||
} | ||
|
||
@Test | ||
public void shouldPermitPermitAllMethod() { | ||
assertStatus("/unsecured/permitAll", 200, 200, 200); | ||
} | ||
|
||
@Test | ||
public void shouldDenySubResource() { | ||
String path = "/unsecured/sub/subMethod"; | ||
assertStatus(path, 200, 403, 401); | ||
} | ||
|
||
@Test | ||
public void shouldAllowPermitAllSubResource() { | ||
String path = "/unsecured/permitAllSub/subMethod"; | ||
assertStatus(path, 200, 200, 200); | ||
} | ||
|
||
@Test | ||
public void shouldAllowPermitAllClass() { | ||
String path = "/permitAll/sub/subMethod"; | ||
assertStatus(path, 200, 200, 200); | ||
} | ||
|
||
private void assertStatus(String path, int adminStatus, int userStatus, int anonStatus) { | ||
given().auth().preemptive() | ||
.basic("admin", "admin").get(path) | ||
.then() | ||
.statusCode(adminStatus); | ||
given().auth().preemptive() | ||
.basic("user", "user").get(path) | ||
.then() | ||
.statusCode(userStatus); | ||
when().get(path) | ||
.then() | ||
.statusCode(anonStatus); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.