Skip to content

Commit aa291fe

Browse files
authored
Merge pull request #9358 from mkouba/reactive-route-cache-sec-identity-event
Reactive routes security - use shared Event instance
2 parents 979b854 + e6e2291 commit aa291fe

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

extensions/vertx-web/deployment/src/main/java/io/quarkus/vertx/web/deployment/VertxWebProcessor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import io.quarkus.deployment.annotations.Record;
6060
import io.quarkus.deployment.builditem.FeatureBuildItem;
6161
import io.quarkus.deployment.builditem.GeneratedClassBuildItem;
62+
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
6263
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
6364
import io.quarkus.deployment.util.HashUtil;
6465
import io.quarkus.gizmo.AssignableResultHandle;
@@ -211,7 +212,8 @@ void addAdditionalRoutes(
211212
BuildProducer<RouteBuildItem> routeProducer,
212213
BuildProducer<FilterBuildItem> filterProducer,
213214
List<RequireBodyHandlerBuildItem> bodyHandlerRequired,
214-
BeanArchiveIndexBuildItem beanArchive) throws IOException {
215+
BeanArchiveIndexBuildItem beanArchive,
216+
ShutdownContextBuildItem shutdown) throws IOException {
215217

216218
ClassOutput classOutput = new GeneratedClassGizmoAdaptor(generatedClass, true);
217219
IndexView index = beanArchive.getIndex();
@@ -326,6 +328,8 @@ void addAdditionalRoutes(
326328
}
327329

328330
detectConflictingRoutes(matchers);
331+
332+
recorder.clearCacheOnShutdown(shutdown);
329333
}
330334

331335
@BuildStep

extensions/vertx-web/runtime/src/main/java/io/quarkus/vertx/web/runtime/RouteHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ default void handle(RoutingContext context) {
2828
//todo: how should we handle non-proactive authentication here?
2929
if (requestContext.isActive()) {
3030
if (user != null) {
31-
Arc.container().beanManager().fireEvent(user.getSecurityIdentity());
31+
RouteHandlers.fireSecurityIdentity(user.getSecurityIdentity());
3232
}
3333
invoke(context);
3434
} else {
3535
try {
3636
requestContext.activate();
3737
if (user != null) {
38-
Arc.container().beanManager().fireEvent(user.getSecurityIdentity());
38+
RouteHandlers.fireSecurityIdentity(user.getSecurityIdentity());
3939
}
4040
invoke(context);
4141
} finally {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.quarkus.vertx.web.runtime;
2+
3+
import javax.enterprise.event.Event;
4+
5+
import io.quarkus.arc.Arc;
6+
import io.quarkus.arc.impl.LazyValue;
7+
import io.quarkus.security.identity.SecurityIdentity;
8+
9+
final class RouteHandlers {
10+
11+
private static final LazyValue<Event<SecurityIdentity>> SECURITY_IDENTITY_EVENT = new LazyValue<>(
12+
RouteHandlers::createEvent);
13+
14+
static void fireSecurityIdentity(SecurityIdentity identity) {
15+
SECURITY_IDENTITY_EVENT.get().fire(identity);
16+
}
17+
18+
static void clear() {
19+
SECURITY_IDENTITY_EVENT.clear();
20+
}
21+
22+
private static Event<SecurityIdentity> createEvent() {
23+
return Arc.container().beanManager().getEvent().select(SecurityIdentity.class);
24+
}
25+
26+
}

extensions/vertx-web/runtime/src/main/java/io/quarkus/vertx/web/runtime/VertxWebRecorder.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.lang.reflect.InvocationTargetException;
44
import java.util.function.Function;
55

6+
import io.quarkus.runtime.ShutdownContext;
67
import io.quarkus.runtime.annotations.Recorder;
78
import io.quarkus.vertx.http.runtime.RouterProducer;
89
import io.vertx.core.Handler;
@@ -69,4 +70,13 @@ public io.vertx.ext.web.Route apply(Router router) {
6970
};
7071
}
7172

73+
public void clearCacheOnShutdown(ShutdownContext shutdown) {
74+
shutdown.addShutdownTask(new Runnable() {
75+
@Override
76+
public void run() {
77+
RouteHandlers.clear();
78+
}
79+
});
80+
}
81+
7282
}

independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ public void validate(InjectionPoint injectionPoint) {
121121

122122
@Override
123123
public void fireEvent(Object event, Annotation... qualifiers) {
124-
getEvent().select(qualifiers).fire(event);
124+
Set<Annotation> eventQualifiers = new HashSet<>();
125+
Collections.addAll(eventQualifiers, qualifiers);
126+
new EventImpl<Object>(event.getClass(), eventQualifiers).fire(event);
125127
}
126128

127129
@Override

0 commit comments

Comments
 (0)