Skip to content

Commit 0617b06

Browse files
authored
Merge pull request #47461 from rsvoboda/ws.checkers
Tweaks for permission checkers for WebSockets Next
2 parents 4e95c7e + cb5bec7 commit 0617b06

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

Diff for: docs/src/main/asciidoc/websockets-next-reference.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,8 @@ public class ProductEndpoint {
10291029
<1> The `getProduct` callback method can only be invoked if the current security identity has an `admin` role or the user is allowed to get the product detail.
10301030
<2> The error handler is invoked in case of the authorization failure.
10311031

1032+
More information about permission checkers can be found on the JavaDoc of link:https://javadoc.io/doc/io.quarkus.security/quarkus-security/latest/io.quarkus.security.api/io/quarkus/security/PermissionChecker.html[`@PermissionChecker`].
1033+
10321034
==== Bearer token authentication
10331035

10341036
The xref:security-oidc-bearer-token-authentication.adoc[OIDC Bearer token authentication] expects that the bearer token is passed in the `Authorization` header during the initial HTTP handshake.

Diff for: extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/security/HttpUpgradePermissionCheckerTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.quarkus.websockets.next.OnTextMessage;
3434
import io.quarkus.websockets.next.WebSocket;
3535
import io.quarkus.websockets.next.test.utils.WSClient;
36+
import io.smallrye.mutiny.Uni;
3637
import io.vertx.core.http.UpgradeRejectedException;
3738

3839
public class HttpUpgradePermissionCheckerTest extends SecurityTestBase {
@@ -138,8 +139,8 @@ String echo(String message) {
138139
public static class AdminEndpoint {
139140

140141
@OnOpen
141-
String open() {
142-
return "ready";
142+
Uni<String> open() {
143+
return Uni.createFrom().item("ready");
143144
}
144145

145146
@OnTextMessage

Diff for: extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/security/PayloadPermissionCheckerTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.quarkus.websockets.next.OnTextMessage;
2626
import io.quarkus.websockets.next.WebSocket;
2727
import io.quarkus.websockets.next.test.utils.WSClient;
28+
import io.smallrye.mutiny.Uni;
2829
import io.vertx.core.Vertx;
2930
import io.vertx.core.http.HttpHeaders;
3031
import io.vertx.core.http.WebSocketConnectOptions;
@@ -70,7 +71,8 @@ public void testHandledFailure() {
7071
// shouldn't close as user declared @OnError
7172
client.waitForMessages(2);
7273
// can't see product 1
73-
assertEquals("forbidden:user", client.getMessages().get(1).toString());
74+
assertEquals("forbidden:user,endpointId:io.quarkus.websockets.next.test.security.ProductEndpoint",
75+
client.getMessages().get(1).toString());
7476
// can see product 2
7577
client.sendAndAwait("2");
7678
client.waitForMessages(3);
@@ -236,9 +238,9 @@ boolean hasPerm1(SecurityIdentity securityIdentity) {
236238
}
237239

238240
@PermissionChecker("perm2")
239-
boolean hasPerm2(SecurityIdentity securityIdentity) {
241+
Uni<Boolean> hasPerm2(SecurityIdentity securityIdentity) {
240242
String principalName = securityIdentity.getPrincipal().getName();
241-
return principalName.equals("user") || principalName.equals("almighty");
243+
return Uni.createFrom().item(Boolean.valueOf(principalName.equals("user") || principalName.equals("almighty")));
242244
}
243245

244246
}

Diff for: extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/security/ProductEndpoint.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.quarkus.websockets.next.OnOpen;
1111
import io.quarkus.websockets.next.OnTextMessage;
1212
import io.quarkus.websockets.next.WebSocket;
13+
import io.quarkus.websockets.next.WebSocketConnection;
1314

1415
@WebSocket(path = "/product")
1516
public class ProductEndpoint {
@@ -32,8 +33,8 @@ Product getProduct(int productId) {
3233
}
3334

3435
@OnError
35-
String error(ForbiddenException t) {
36-
return "forbidden:" + currentIdentity.getPrincipal().getName();
36+
String error(ForbiddenException t, WebSocketConnection conn) {
37+
return "forbidden:" + currentIdentity.getPrincipal().getName() + ",endpointId:" + conn.endpointId();
3738
}
3839

3940
@PermissionChecker("product:get")

0 commit comments

Comments
 (0)