Skip to content

Commit

Permalink
Fix exception wrapping issue with SecurityHandler
Browse files Browse the repository at this point in the history
Fixes quarkusio#21679

(cherry picked from commit 46a2de0)
  • Loading branch information
stuartwdouglas authored and gsmet committed Nov 29, 2021
1 parent 17c0188 commit 65a5e52
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.quarkus.security.test.cdi.app.SubclassWithDenyAll;
import io.quarkus.security.test.cdi.app.SubclassWithPermitAll;
import io.quarkus.security.test.cdi.app.SubclassWithoutAnnotations;
import io.quarkus.security.test.cdi.app.TestException;
import io.quarkus.security.test.utils.AuthData;
import io.quarkus.security.test.utils.IdentityMock;
import io.quarkus.security.test.utils.SecurityTestUtils;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class CDIAccessDefaultTest {
AuthData.class,
SubclassWithDenyAll.class,
SubclassWithoutAnnotations.class,
TestException.class,
SubclassWithPermitAll.class,
SecurityTestUtils.class));

Expand Down Expand Up @@ -101,6 +103,18 @@ public void shouldRestrictAccessToSpecificRoleCompletionState() {
}, "accessibleForAdminOnly", ADMIN);
}

@Test
public void testExceptionWrapping() {
Executable executable = () -> {
try {
bean.securedMethodCompletionStageException().toCompletableFuture().get();
} catch (ExecutionException e) {
throw e.getCause();
}
};
assertFailureFor(executable, TestException.class, ADMIN);
}

@Test
public void shouldFailToAccessForbiddenOnClass() {
assertFailureFor(() -> denyAllBean.noAdditionalConstraints(), UnauthorizedException.class, ANONYMOUS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public CompletionStage<String> securedMethodCompletionStage() {
return Uni.createFrom().item("accessibleForAdminOnly").subscribeAsCompletionStage();
}

@RolesAllowed("admin")
public CompletionStage<String> securedMethodCompletionStageException() {
throw new TestException();
}

public String unsecuredMethod() {
return "accessibleForAll";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.quarkus.security.test.cdi.app;

public class TestException extends RuntimeException {
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Object handle(InvocationContext ic) throws Exception {
try {
return Uni.createFrom().completionStage((CompletionStage<?>) ic.proceed());
} catch (Exception e) {
throw new RuntimeException(e);
return Uni.createFrom().failure(e);
}
}).subscribeAsCompletionStage();
} else if (Multi.class.isAssignableFrom(returnType)) {
Expand Down

0 comments on commit 65a5e52

Please sign in to comment.