Skip to content

Commit

Permalink
Make @testsecurity work correctly with unannotated JAX-RS endpoints s…
Browse files Browse the repository at this point in the history
…ecurity feature

The use of `quarkus.security.jaxrs.deny-unannotated-endpoints=true` essentially
results in the addition of a `DenyAllInterceptor` to the invocation chain
of a JAX-RS endpoint.
Because this interceptor did not take into account the `AuthorizationController`
(like the `RolesAllowedInterceptor` already does), it would result in endpoints
being secured even though security was supposed to be disabled for the specific test.

Fixes: quarkusio#19896
(cherry picked from commit b9359bf)
  • Loading branch information
geoand authored and gsmet committed Nov 30, 2021
1 parent 83c608a commit 75bfe7d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/security-authorization.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ There are three configuration settings that alter the RBAC Deny behavior:

`quarkus.security.jaxrs.deny-unannotated-endpoints=true|false`::
If set to true, the access will be denied for all JAX-RS endpoints by default, so if a JAX-RS endpoint does not have any security annotations
then it will default to `@DenyAll` behaviour. This is useful to ensure you cannot accidently expose an endpoint that is supposed to be secured. Defaults to `false`.
then it will default to `@DenyAll` behaviour. This is useful to ensure you cannot accidentally expose an endpoint that is supposed to be secured. Defaults to `false`.

`quarkus.security.jaxrs.default-roles-allowed=role1,role2`::
Defines the default role requirements for unannotated endpoints. The role '**' is a special role that means any authenticated user. This cannot be combined with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

import io.quarkus.security.spi.runtime.AuthorizationController;

/**
*
* @author Michal Szynkiewicz, [email protected]
Expand All @@ -19,8 +21,15 @@ public class DenyAllInterceptor {
@Inject
SecurityHandler handler;

@Inject
AuthorizationController controller;

@AroundInvoke
public Object intercept(InvocationContext ic) throws Exception {
return handler.handle(ic);
if (controller.isAuthorizationEnabled()) {
return handler.handle(ic);
} else {
return ic.proceed();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
* Contains classes that need to have @DenyAll on all methods that don't have security annotations
*/
public final class AdditionalSecuredClassesBuildItem extends MultiBuildItem {

public final Collection<ClassInfo> additionalSecuredClasses;
/**
* The roles alloe
*/
public final Optional<List<String>> rolesAllowed;

public AdditionalSecuredClassesBuildItem(Collection<ClassInfo> additionalSecuredClasses) {
Expand Down

0 comments on commit 75bfe7d

Please sign in to comment.