Class RouteAccessConfiguration

  • All Implemented Interfaces:
    Serializable

    public class RouteAccessConfiguration
    extends Object
    implements Serializable
    Allows to dynamically set the access rules for certain routes, navigation targets and parent layouts. This will override rules defined on navigation targets and parent layouts directly via SecuredRoute.

    This is essentially the security counterpart for RouteConfiguration. As such, there's an application and a session scope, where the session scope can also see rules from the application scope. Both scopes consider SecuredRoute annotations on navigation targets and parent layouts when they have not been overriden.

    See Also:
    Serialized Form
    • Method Detail

      • forApplicationScope

        public static RouteAccessConfiguration forApplicationScope()
        Returns a configurator for application scoped access rules. This requires that VaadinServlet.getCurrent() is populated.
        Returns:
        configurator for application scoped access rules
      • forSessionScope

        public static RouteAccessConfiguration forSessionScope()
        Returns a configurator for session scoped access rules. This requires that VaadinSession.getCurrent() is populated.

        The session scope also returns access rules from the application scope.

        Returns:
        configurator for session scoped routes
      • setAccessRule

        public void setAccessRule​(Class<? extends com.vaadin.flow.component.Component> targetOrLayout,
                                  AccessRule accessRule)
        Sets the access rule for the given navigation target or parent layout.

        Setting an access rule for a path will take precedence over access rules set for the target class.

        Parameters:
        targetOrLayout - the navigation target or parent layout
        accessRule - the access rule
      • removeAccessRule

        public void removeAccessRule​(Class<? extends com.vaadin.flow.component.Component> targetOrLayout)
        Removes the access rule for the given navigation target or parent layout.
        Parameters:
        targetOrLayout - the navigation target or parent layout
      • getAccessRule

        public Optional<AccessRule> getAccessRule​(Class<?> targetOrLayout)
        Returns the effective access rule for the given navigation target or parent layout.
        Parameters:
        targetOrLayout - the navigation target or parent layout
        Returns:
        the effective access rule for the navigation target or parent layout
      • getRegisteredAccessRulesForTargetsAndLayouts

        public HashMap<String,​AccessRule> getRegisteredAccessRulesForTargetsAndLayouts()
        Returns all access rules registered for navigation targets or parent layouts.
        Returns:
        all access rules registered for navigation targets or parent layouts
      • setAccessRule

        public void setAccessRule​(String routePath,
                                  AccessRule accessRule)
        Sets the access rule for the given route path.

        Setting an access rule for a path will take precedence over access rules set for the target class. Whether access rules for parent layouts are considered is still determined by AccessRule.checkLayout().

        Parameters:
        routePath - the route path
        accessRule - the access rule
      • removeAccessRule

        public void removeAccessRule​(String routePath)
        Removes the access rule for the given route path.
        Parameters:
        routePath - the route path
      • getAccessRule

        public Optional<AccessRule> getAccessRule​(String routePath)
        Returns the effective access rule for the given route path.
        Parameters:
        routePath - the route path
        Returns:
        the effective access rule for the given route path
      • getRegisteredAccessRulesForPaths

        public HashMap<String,​AccessRule> getRegisteredAccessRulesForPaths()
        Returns all access rules registered route paths.
        Returns:
        all access rules registered route paths