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.
Transform security annotations to be inherited; add tests
- Loading branch information
Showing
11 changed files
with
194 additions
and
0 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
95 changes: 95 additions & 0 deletions
95
...y/deployment/src/test/java/io/quarkus/security/test/cdi/CdiClassLevelInheritanceTest.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,95 @@ | ||
package io.quarkus.security.test.cdi; | ||
|
||
import static io.quarkus.security.test.utils.IdentityMock.ADMIN; | ||
import static io.quarkus.security.test.utils.IdentityMock.ANONYMOUS; | ||
import static io.quarkus.security.test.utils.IdentityMock.USER; | ||
import static io.quarkus.security.test.utils.SecurityTestUtils.assertFailureFor; | ||
import static io.quarkus.security.test.utils.SecurityTestUtils.assertSuccess; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.security.ForbiddenException; | ||
import io.quarkus.security.StringPermission; | ||
import io.quarkus.security.UnauthorizedException; | ||
import io.quarkus.security.test.cdi.app.TestException; | ||
import io.quarkus.security.test.cdi.inheritance.AuthenticatedBean; | ||
import io.quarkus.security.test.cdi.inheritance.DenyAllBean; | ||
import io.quarkus.security.test.cdi.inheritance.PermissionsAllowedBean; | ||
import io.quarkus.security.test.cdi.inheritance.RolesAllowedBean; | ||
import io.quarkus.security.test.cdi.inheritance.SubclassAuthenticatedBean; | ||
import io.quarkus.security.test.cdi.inheritance.SubclassDenyAllBean; | ||
import io.quarkus.security.test.cdi.inheritance.SubclassPermissionsAllowedBean; | ||
import io.quarkus.security.test.cdi.inheritance.SubclassRolesAllowedBean; | ||
import io.quarkus.security.test.utils.AuthData; | ||
import io.quarkus.security.test.utils.IdentityMock; | ||
import io.quarkus.security.test.utils.SecurityTestUtils; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class CdiClassLevelInheritanceTest { | ||
|
||
@Inject | ||
SubclassDenyAllBean subclassDenyAll; | ||
|
||
@Inject | ||
SubclassRolesAllowedBean subclassRolesAllowed; | ||
|
||
@Inject | ||
SubclassAuthenticatedBean subclassAuthenticated; | ||
|
||
@Inject | ||
SubclassPermissionsAllowedBean subclassPermissionsAllowed; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(IdentityMock.class, | ||
AuthData.class, | ||
DenyAllBean.class, | ||
RolesAllowedBean.class, | ||
AuthenticatedBean.class, | ||
PermissionsAllowedBean.class, | ||
SubclassPermissionsAllowedBean.class, | ||
SubclassDenyAllBean.class, | ||
SubclassRolesAllowedBean.class, | ||
SubclassAuthenticatedBean.class, | ||
TestException.class, | ||
SecurityTestUtils.class)) | ||
// Following configuration tells Arc to *not* automatically inherit all class level annotations | ||
.overrideConfigKey("quarkus.arc.strict-compatibility", "true"); | ||
|
||
@Test | ||
public void testDenyAllInherited() { | ||
assertFailureFor(() -> subclassDenyAll.ping(), UnauthorizedException.class, ANONYMOUS); | ||
assertFailureFor(() -> subclassDenyAll.ping(), ForbiddenException.class, USER, ADMIN); | ||
} | ||
|
||
@Test | ||
public void testRolesAllowedInherited() { | ||
assertFailureFor(() -> subclassRolesAllowed.ping(), UnauthorizedException.class, ANONYMOUS); | ||
assertFailureFor(() -> subclassRolesAllowed.ping(), ForbiddenException.class, USER); | ||
assertSuccess(() -> subclassRolesAllowed.ping(), RolesAllowedBean.class.getSimpleName(), ADMIN); | ||
} | ||
|
||
@Test | ||
public void testAuthenticatedInherited() { | ||
assertFailureFor(() -> subclassAuthenticated.ping(), UnauthorizedException.class, ANONYMOUS); | ||
assertSuccess(() -> subclassAuthenticated.ping(), AuthenticatedBean.class.getSimpleName(), USER); | ||
assertSuccess(() -> subclassAuthenticated.ping(), AuthenticatedBean.class.getSimpleName(), ADMIN); | ||
} | ||
|
||
@Test | ||
public void testPermissionAllowedInherited() { | ||
AuthData USER_READ = new AuthData(Collections.singleton("user_read"), false, "user_read", | ||
Set.of(new StringPermission("read"))); | ||
AuthData USER_WRITE = new AuthData(Collections.singleton("user_write"), false, "user_write", | ||
Set.of(new StringPermission("write"))); | ||
assertSuccess(() -> subclassPermissionsAllowed.ping(), PermissionsAllowedBean.class.getSimpleName(), USER_READ); | ||
assertFailureFor(() -> subclassPermissionsAllowed.ping(), ForbiddenException.class, USER_WRITE); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../deployment/src/test/java/io/quarkus/security/test/cdi/inheritance/AuthenticatedBean.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,14 @@ | ||
package io.quarkus.security.test.cdi.inheritance; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.security.Authenticated; | ||
|
||
@ApplicationScoped | ||
@Authenticated | ||
public class AuthenticatedBean { | ||
|
||
public String ping() { | ||
return AuthenticatedBean.class.getSimpleName(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...curity/deployment/src/test/java/io/quarkus/security/test/cdi/inheritance/DenyAllBean.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,13 @@ | ||
package io.quarkus.security.test.cdi.inheritance; | ||
|
||
import jakarta.annotation.security.DenyAll; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
@DenyAll | ||
public class DenyAllBean { | ||
|
||
public String ping() { | ||
return DenyAllBean.class.getSimpleName(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...oyment/src/test/java/io/quarkus/security/test/cdi/inheritance/PermissionsAllowedBean.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,14 @@ | ||
package io.quarkus.security.test.cdi.inheritance; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.security.PermissionsAllowed; | ||
|
||
@ApplicationScoped | ||
@PermissionsAllowed("read") | ||
public class PermissionsAllowedBean { | ||
|
||
public String ping() { | ||
return PermissionsAllowedBean.class.getSimpleName(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...y/deployment/src/test/java/io/quarkus/security/test/cdi/inheritance/RolesAllowedBean.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,13 @@ | ||
package io.quarkus.security.test.cdi.inheritance; | ||
|
||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
@RolesAllowed("admin") | ||
public class RolesAllowedBean { | ||
|
||
public String ping() { | ||
return RolesAllowedBean.class.getSimpleName(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ent/src/test/java/io/quarkus/security/test/cdi/inheritance/SubclassAuthenticatedBean.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,7 @@ | ||
package io.quarkus.security.test.cdi.inheritance; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class SubclassAuthenticatedBean extends AuthenticatedBean { | ||
} |
7 changes: 7 additions & 0 deletions
7
...eployment/src/test/java/io/quarkus/security/test/cdi/inheritance/SubclassDenyAllBean.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,7 @@ | ||
package io.quarkus.security.test.cdi.inheritance; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class SubclassDenyAllBean extends DenyAllBean { | ||
} |
7 changes: 7 additions & 0 deletions
7
...rc/test/java/io/quarkus/security/test/cdi/inheritance/SubclassPermissionsAllowedBean.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,7 @@ | ||
package io.quarkus.security.test.cdi.inheritance; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class SubclassPermissionsAllowedBean extends PermissionsAllowedBean { | ||
} |
7 changes: 7 additions & 0 deletions
7
...ment/src/test/java/io/quarkus/security/test/cdi/inheritance/SubclassRolesAllowedBean.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,7 @@ | ||
package io.quarkus.security.test.cdi.inheritance; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class SubclassRolesAllowedBean extends RolesAllowedBean { | ||
} |