Skip to content

Commit

Permalink
Automatically use beforeEnterListener AccessControls if available.
Browse files Browse the repository at this point in the history
  • Loading branch information
caalador committed May 14, 2024
1 parent 51f6b94 commit 324171b
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.util.Optional;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.internal.CurrentInstance;
import com.vaadin.flow.router.internal.AbstractRouteRegistry;
import com.vaadin.flow.router.internal.BeforeEnterHandler;
import com.vaadin.flow.router.internal.HasUrlParameterFormat;
import com.vaadin.flow.router.internal.PathUtil;
import com.vaadin.flow.router.internal.RouteUtil;
Expand Down Expand Up @@ -537,10 +539,21 @@ private final boolean isAnnotatedParameter(
* Get the {@link RouteData} for all accessible registered navigation
* targets with a menu information. Access checking depends on the active
* {@link VaadinService} and {@link VaadinRequest}.
* <p>
* Automatically adds access controls from UI if available.
*
* @return list of accessible menu routes available for handled registry
*/
public List<RouteData> getRegisteredAccessibleMenuRoutes() {
UI ui = UI.getCurrent();
if (ui != null) {
List<BeforeEnterListener> accessControls = ui.getInternals()
.getListeners(BeforeEnterHandler.class).stream()
.filter(BeforeEnterListener.class::isInstance)
.map(BeforeEnterListener.class::cast).toList();
return getRegisteredAccessibleMenuRoutes(accessControls);
}

return getRegisteredAccessibleMenuRoutes(Collections.emptyList());
}

Expand Down

0 comments on commit 324171b

Please sign in to comment.