Class SpringAccessPathChecker
- All Implemented Interfaces:
AccessPathChecker,Serializable,org.springframework.beans.factory.Aware,org.springframework.web.context.ServletContextAware
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, with the anonymous authentication
configured for the security filter chain that would handle a request to the
path. When the filter chain proxy is not given, or no chain matches the path,
an anonymous authentication from the strategy is kept and any other
authentication is replaced by a default ROLE_ANONYMOUS one.
The filter chain proxy is read on each check and the anonymous authentication
of a chain is computed on the first check it handles. The chains are matched
against a request bound to the ServletContext set with
setServletContext(ServletContext), which Spring calls when the
checker is a bean of a web application context. The proxy and the servlet
context are not serialized with the checker: after deserialization the
default anonymous authentication is used.
@Bean
NavigationAccessControlConfigurer navigationAccessControlConfigurer() {
return new NavigationAccessControlConfigurer()
.withRoutePathAccessChecker().withLoginView(LoginView.class);
}
- Since:
- 24.3
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator) Creates a new instance that uses the givenWebInvocationPrivilegeEvaluatorto check path permissions.SpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator, String urlMapping) Creates a new instance that uses the givenWebInvocationPrivilegeEvaluatorto 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 givenWebInvocationPrivilegeEvaluatorto check path permissions.SpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator, String urlMapping, org.springframework.security.core.context.SecurityContextHolderStrategy securityContextHolderStrategy, SerializableSupplier<org.springframework.security.web.FilterChainProxy> filterChainProxy, org.springframework.security.web.access.AuthorizationManagerWebInvocationPrivilegeEvaluator.HttpServletRequestTransformer requestTransformer) Creates a new instance that uses the givenWebInvocationPrivilegeEvaluatorto check path permissions. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if the user defined by the givenPrincipaland role checker has access to the given path.voidsetServletContext(jakarta.servlet.ServletContext servletContext) Sets the servlet context of the request built for the path, as the privilege evaluator does.
-
Constructor Details
-
SpringAccessPathChecker
public SpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator) Creates a new instance that uses the givenWebInvocationPrivilegeEvaluatorto 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 givenWebInvocationPrivilegeEvaluatorto 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 inSecurityContextHolder.- 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 givenWebInvocationPrivilegeEvaluatorto 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 givenSecurityContextHolderStrategyinstead of the one installed inSecurityContextHolder.- Parameters:
evaluator- evaluator to check path permissions.urlMapping- Vaadin servlet url mappingsecurityContextHolderStrategy- the strategy to read the current authentication from, not null- Since:
- 25.4
-
SpringAccessPathChecker
public SpringAccessPathChecker(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator evaluator, String urlMapping, org.springframework.security.core.context.SecurityContextHolderStrategy securityContextHolderStrategy, SerializableSupplier<org.springframework.security.web.FilterChainProxy> filterChainProxy, org.springframework.security.web.access.AuthorizationManagerWebInvocationPrivilegeEvaluator.HttpServletRequestTransformer requestTransformer) Creates a new instance that uses the givenWebInvocationPrivilegeEvaluatorto 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 givenSecurityContextHolderStrategyinstead of the one installed inSecurityContextHolder. A check with a null principal uses the anonymous authentication configured for the security filter chain that would handle a request to the path, so that anonymous authorities set withhttp.anonymous(...)are honoured also when a logged-in user is bound to the current thread.The filter chain proxy is taken from the supplier on the first check, so the checker can be created before the security filter chains are built. The request used to select the chain is transformed with the given transformer, which should be the one the evaluator uses.
- Parameters:
evaluator- evaluator to check path permissions.urlMapping- Vaadin servlet url mappingsecurityContextHolderStrategy- the strategy to read the current authentication from, not nullfilterChainProxy- supplies the filter chain proxy to read the configured anonymous authentication from, not nullrequestTransformer- transforms the request built for the path before matching the filter chains, not null- Since:
- 25.4
-
-
Method Details
-
setServletContext
public void setServletContext(jakarta.servlet.ServletContext servletContext) Sets the servlet context of the request built for the path, as the privilege evaluator does. Spring calls this method when the checker is a bean of a web application context. Set it when creating the checker by hand if a filter chain uses a request matcher that reads the servlet context, like Spring Boot'sEndpointRequestandPathRequestmatchers.- Specified by:
setServletContextin interfaceorg.springframework.web.context.ServletContextAware- Parameters:
servletContext- the servlet context- Since:
- 25.4
-
hasAccess
Description copied from interface:AccessPathCheckerChecks if the user defined by the givenPrincipaland role checker has access to the given path.The
pathis relative to the Vaadin application and does not contain any container specific details such as context or servlet path.The
pathis never null and never starts with a "/" character.- Specified by:
hasAccessin interfaceAccessPathChecker- Parameters:
path- the path to check access toprincipal- the principal of the user, or null if the check must be done for an anonymous user. A null value must be treated as anonymous even if an authenticated user is bound to the current thread, e.g. when checking whether a path is publicroleChecker- a function that can answer if a user has a given role- Returns:
trueif the user has access to the given path,falseotherwise.
-