Skip to content

Commit 2907dd7

Browse files
authored
fix: log access warning in dev mode (#23395)
Log layout denied by access rule as a warning when in development mode. fixes #23083
1 parent 0940ac1 commit 2907dd7

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

flow-server/src/main/java/com/vaadin/flow/server/auth/AnnotatedViewAccessChecker.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import com.vaadin.flow.router.RouterLayout;
3333
import com.vaadin.flow.router.internal.RouteUtil;
3434
import com.vaadin.flow.server.RouteRegistry;
35+
import com.vaadin.flow.server.VaadinContext;
36+
import com.vaadin.flow.server.startup.ApplicationConfiguration;
3537

3638
/**
3739
* Checks access to views using an {@link AccessAnnotationChecker}.
@@ -163,12 +165,16 @@ private void logDeniedByLayoutAccessRules(NavigationContext context,
163165

164166
private void logDeniedByLayoutAccessRules(NavigationContext context,
165167
Class<?> layoutClass, String msg) {
166-
if (context.isNavigating()) {
167-
LOGGER.warn(msg, context.getNavigationTarget().getSimpleName(),
168-
layoutClass.getSimpleName());
168+
if (context.isNavigating() || isDevelopmentMode(context)) {
169+
if (!context.isNavigating()) {
170+
msg = msg
171+
+ " This access check was probably triggered by the security framework.";
172+
}
173+
LOGGER.warn(msg, context.getNavigationTarget().getName(),
174+
layoutClass.getName());
169175
} else {
170-
LOGGER.trace(msg, context.getNavigationTarget().getSimpleName(),
171-
layoutClass.getSimpleName());
176+
LOGGER.debug(msg, context.getNavigationTarget().getName(),
177+
layoutClass.getName());
172178
}
173179
}
174180

@@ -178,4 +184,11 @@ private boolean isImplicitlyDenyAllAnnotated(Class<?> targetView) {
178184
|| targetView.isAnnotationPresent(RolesAllowed.class));
179185
}
180186

187+
private boolean isDevelopmentMode(NavigationContext context) {
188+
VaadinContext vaadinContext = context.getRouter().getRegistry()
189+
.getContext();
190+
ApplicationConfiguration appConfig = ApplicationConfiguration
191+
.get(vaadinContext);
192+
return !appConfig.isProductionMode();
193+
}
181194
}

0 commit comments

Comments
 (0)