-
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.
Merge pull request #19598 from stuartwdouglas/resteasy-reactive-eager…
…-security Push security checks further up the handler chain
- Loading branch information
Showing
38 changed files
with
409 additions
and
74 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
64 changes: 64 additions & 0 deletions
64
...rc/main/java/io/quarkus/resteasy/reactive/server/deployment/SecurityTransformerUtils.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,64 @@ | ||
package io.quarkus.resteasy.reactive.server.deployment; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import javax.annotation.security.DenyAll; | ||
import javax.annotation.security.PermitAll; | ||
import javax.annotation.security.RolesAllowed; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.MethodInfo; | ||
|
||
import io.quarkus.security.Authenticated; | ||
|
||
public class SecurityTransformerUtils { | ||
public static final Set<DotName> SECURITY_BINDINGS = new HashSet<>(); | ||
|
||
static { | ||
// keep the contents the same as in io.quarkus.resteasy.deployment.SecurityTransformerUtils | ||
SECURITY_BINDINGS.add(DotName.createSimple(RolesAllowed.class.getName())); | ||
SECURITY_BINDINGS.add(DotName.createSimple(Authenticated.class.getName())); | ||
SECURITY_BINDINGS.add(DotName.createSimple(DenyAll.class.getName())); | ||
SECURITY_BINDINGS.add(DotName.createSimple(PermitAll.class.getName())); | ||
} | ||
|
||
public static boolean hasStandardSecurityAnnotation(MethodInfo methodInfo) { | ||
return hasStandardSecurityAnnotation(methodInfo.annotations()); | ||
} | ||
|
||
public static boolean hasStandardSecurityAnnotation(ClassInfo classInfo) { | ||
return hasStandardSecurityAnnotation(classInfo.classAnnotations()); | ||
} | ||
|
||
private static boolean hasStandardSecurityAnnotation(Collection<AnnotationInstance> instances) { | ||
for (AnnotationInstance instance : instances) { | ||
if (SECURITY_BINDINGS.contains(instance.name())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static Optional<AnnotationInstance> findFirstStandardSecurityAnnotation(MethodInfo methodInfo) { | ||
return findFirstStandardSecurityAnnotation(methodInfo.annotations()); | ||
} | ||
|
||
public static Optional<AnnotationInstance> findFirstStandardSecurityAnnotation(ClassInfo classInfo) { | ||
return findFirstStandardSecurityAnnotation(classInfo.classAnnotations()); | ||
} | ||
|
||
private static Optional<AnnotationInstance> findFirstStandardSecurityAnnotation(Collection<AnnotationInstance> instances) { | ||
for (AnnotationInstance instance : instances) { | ||
if (SECURITY_BINDINGS.contains(instance.name())) { | ||
return Optional.of(instance); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
} |
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
30 changes: 30 additions & 0 deletions
30
.../java/io/quarkus/resteasy/reactive/server/test/security/RolesAllowedBlockingResource.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,30 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import javax.annotation.security.PermitAll; | ||
import javax.annotation.security.RolesAllowed; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import io.smallrye.common.annotation.Blocking; | ||
|
||
/** | ||
* @author Michal Szynkiewicz, [email protected] | ||
*/ | ||
@Path("/roles-blocking") | ||
@PermitAll | ||
@Blocking | ||
public class RolesAllowedBlockingResource { | ||
@GET | ||
@RolesAllowed({ "user", "admin" }) | ||
public String defaultSecurity() { | ||
return "default"; | ||
} | ||
|
||
@Path("/admin") | ||
@RolesAllowed("admin") | ||
@GET | ||
public String admin() { | ||
return "admin"; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,11 @@ | |
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import io.smallrye.common.annotation.Blocking; | ||
|
||
/** | ||
* @author Michal Szynkiewicz, [email protected] | ||
*/ | ||
@Path("/roles") | ||
@PermitAll | ||
@Blocking | ||
public class RolesAllowedResource { | ||
@GET | ||
@RolesAllowed({ "user", "admin" }) | ||
|
14 changes: 14 additions & 0 deletions
14
.../src/test/java/io/quarkus/resteasy/reactive/server/test/security/SerializationEntity.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.resteasy.reactive.server.test.security; | ||
|
||
public class SerializationEntity { | ||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public SerializationEntity setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...st/java/io/quarkus/resteasy/reactive/server/test/security/SerializationRolesResource.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,27 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import javax.annotation.security.PermitAll; | ||
import javax.annotation.security.RolesAllowed; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
|
||
import io.smallrye.common.annotation.Blocking; | ||
|
||
@Path("/roles-validate") | ||
@PermitAll | ||
@Blocking | ||
public class SerializationRolesResource { | ||
@POST | ||
@RolesAllowed({ "user", "admin" }) | ||
public String defaultSecurity(SerializationEntity entity) { | ||
return entity.getName(); | ||
} | ||
|
||
@Path("/admin") | ||
@RolesAllowed("admin") | ||
@POST | ||
public String admin(SerializationEntity entity) { | ||
return entity.getName(); | ||
} | ||
|
||
} |
Oops, something went wrong.