Skip to content

Commit fcaad06

Browse files
authored
Merge pull request quarkusio#48086 from sberyozkin/check_vertx_remote_user_attribute
Avoid class cast exception when reading Vert.x Remote User attribute if Vert.x UserImpl is available
2 parents a33682e + 3277401 commit fcaad06

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/attribute/RemoteUserAttribute.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.quarkus.vertx.http.runtime.attribute;
22

33
import io.quarkus.vertx.http.runtime.security.QuarkusHttpUser;
4+
import io.vertx.ext.auth.User;
45
import io.vertx.ext.web.RoutingContext;
56

67
/**
@@ -11,6 +12,7 @@ public class RemoteUserAttribute implements ExchangeAttribute {
1112

1213
public static final String REMOTE_USER_SHORT = "%u";
1314
public static final String REMOTE_USER = "%{REMOTE_USER}";
15+
public static final String VERTX_USER_NAME = "username";
1416

1517
public static final ExchangeAttribute INSTANCE = new RemoteUserAttribute();
1618

@@ -20,11 +22,15 @@ private RemoteUserAttribute() {
2022

2123
@Override
2224
public String readAttribute(final RoutingContext exchange) {
23-
QuarkusHttpUser sc = (QuarkusHttpUser) exchange.user();
24-
if (sc == null) {
25+
User user = exchange.user();
26+
if (user == null) {
2527
return null;
2628
}
27-
return sc.getSecurityIdentity().getPrincipal().getName();
29+
if (user instanceof QuarkusHttpUser quarkusUser) {
30+
return quarkusUser.getSecurityIdentity().getPrincipal().getName();
31+
} else {
32+
return user.principal().getString(VERTX_USER_NAME);
33+
}
2834
}
2935

3036
@Override

0 commit comments

Comments
 (0)