Class SpringAccessPathChecker

java.lang.Object
com.vaadin.flow.spring.security.SpringAccessPathChecker
All Implemented Interfaces:
com.vaadin.flow.server.auth.AccessPathChecker, Serializable

public class SpringAccessPathChecker extends Object implements com.vaadin.flow.server.auth.AccessPathChecker
A Spring specific route path access checker that delegates the check to Spring Security.

It is used in combination with RoutePathAccessChecker to provide path-based security to Flow NavigationAccessControl.

To enable it, define a NavigationAccessControlConfigurer bean, configured using NavigationAccessControlConfigurer.withRoutePathAccessChecker() method.

The current authentication is read from a SecurityContextHolderStrategy. When the principal passed to hasAccess(String, Principal, Predicate) is null, the check is done for an anonymous user: an anonymous authentication from the strategy is kept, any other authentication is replaced by a default ROLE_ANONYMOUS one.

 
 @Bean
 NavigationAccessControlConfigurer navigationAccessControlConfigurer() {
     return new NavigationAccessControlConfigurer()
             .withRoutePathAccessChecker().withLoginView(LoginView.class);
 }
 
 
Since:
24.3
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    SpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator)
    Creates a new instance that uses the given WebInvocationPrivilegeEvaluator to check path permissions.
    SpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator, String urlMapping)
    Creates a new instance that uses the given WebInvocationPrivilegeEvaluator to check path permissions.
    SpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator, String urlMapping, org.springframework.security.core.context.SecurityContextHolderStrategy securityContextHolderStrategy)
    Creates a new instance that uses the given WebInvocationPrivilegeEvaluator to check path permissions.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    hasAccess(String path, Principal principal, Predicate<String> roleChecker)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpringAccessPathChecker

      public SpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator)
      Creates a new instance that uses the given WebInvocationPrivilegeEvaluator to check path permissions.

      The current authentication is read from the strategy installed in SecurityContextHolder.

      Parameters:
      evaluator - evaluator to check path permissions.
    • SpringAccessPathChecker

      public SpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator, String urlMapping)
      Creates a new instance that uses the given WebInvocationPrivilegeEvaluator to check path permissions. It applies the given Vaadin servlet url mapping to the input path before delegating the check to the evaluator. The current authentication is read from the strategy installed in SecurityContextHolder.
      Parameters:
      evaluator - evaluator to check path permissions.
      urlMapping - Vaadin servlet url mapping
    • SpringAccessPathChecker

      public SpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator, String urlMapping, org.springframework.security.core.context.SecurityContextHolderStrategy securityContextHolderStrategy)
      Creates a new instance that uses the given WebInvocationPrivilegeEvaluator to check path permissions. It applies the given Vaadin servlet url mapping to the input path before delegating the check to the evaluator. The current authentication is read from the given SecurityContextHolderStrategy instead of the one installed in SecurityContextHolder.
      Parameters:
      evaluator - evaluator to check path permissions.
      urlMapping - Vaadin servlet url mapping
      securityContextHolderStrategy - the strategy to read the current authentication from, not null
      Since:
      25.4
  • Method Details

    • hasAccess

      public boolean hasAccess(String path, Principal principal, Predicate<String> roleChecker)
      Specified by:
      hasAccess in interface com.vaadin.flow.server.auth.AccessPathChecker