com.vaadin.flow.server.auth.
Class NavigationContext
Context information for a navigation request.
The navigation context is responsible for providing details about the current
navigation, such as the navigation target, the location and the current user,
and to allow NavigationAccessChecker
to create a representation of
their decisions.
A NavigationAccessChecker
should use allow()
,
neutral()
, deny(String)
and reject(String)
methods
to create a result in
NavigationAccessChecker.check(NavigationContext)
implementation.
allow()
created a result whose meaning is that the access to a view is granted.neutral()
means that the access checker is not able to determine if the current navigation should be allowed or not.deny(String)
is used to create a response that will prevent the navigation to the target view. The given reason should provide details that will help to debug access control issues.reject(String)
denies the access to the target view, but should be used to indicate mistakes in security configuration that do not allow the navigation checker to take a decision; for example, a configuration where the path /my/view is public, but /my/* is protected.
-
Constructor Summary
ConstructorsConstructorDescriptionNavigationContext
(BeforeEnterEvent event, Principal principal, Predicate<String> roleChecker) Create a new navigation context instance based on a
BeforeEnterEvent
.NavigationContext
(Router router, Class<?> navigationTarget, Location location, RouteParameters parameters, Principal principal, Predicate<String> roleChecker, boolean errorHandling) Creates a new navigation context instance.
-
Method Summary
Modifier and TypeMethodDescriptionallow()
Create a result instance informing that the navigation to the target view is allowed for the current user.
Create a result instance informing that the navigation to the target view is denied for the current user.
Gets the requested location.
Class<?>
Gets the navigation target.
Gets the route parameters associated with this event.
Gets the principal for the currently logged in user.
Gets the router that triggered the navigation change.
boolean
Gets if the current user belongs the specified logical role.
boolean
Gets if current navigation change is related to error handling or if it is a regular navigation to a target view.
neutral()
Create a result instance informing that the checker cannot take a decision based on the given navigation information.
Create a result instance informing that the navigation to the target view is denied for the current user because of a misconfiguration or a critical development time error.
-
Constructor Details
-
NavigationContext
public NavigationContext(Router router, Class<?> navigationTarget, Location location, RouteParameters parameters, Principal principal, Predicate<String> roleChecker, boolean errorHandling) Creates a new navigation context instance.
Parameters:
router
- the router that triggered the change, not nullnavigationTarget
- navigation target class, not nulllocation
- the requested location, not nullparameters
- route parameters, not nullprincipal
- the principal of the userroleChecker
- a function that can answer if a user has a given roleerrorHandling
- true if the current navigation is related to an error handling phase, false for a regular navigation to a target view -
NavigationContext
public NavigationContext(BeforeEnterEvent event, Principal principal, Predicate<String> roleChecker) Create a new navigation context instance based on a
BeforeEnterEvent
.Parameters:
event
- the event created before ongoing navigation happens.principal
- the principal of the userroleChecker
- a function that can answer if a user has a given role
-
-
Method Details
-
getRouter
Gets the router that triggered the navigation change.
Returns:
router that triggered the navigation change, not
null
-
getLocation
Gets the requested location.
Note that in case of error handling the location still references the initial request.
Returns:
the requested location, not
null
See Also:
-
getParameters
Gets the route parameters associated with this event.
Returns:
route parameters retrieved from the navigation url, not
null
-
getPrincipal
Gets the principal for the currently logged in user.
Returns:
a representation of the currently logged in user or
null
if no user is currently logged in -
isErrorHandling
public boolean isErrorHandling()Gets if current navigation change is related to error handling or if it is a regular navigation to a target view.
Returns:
true if the current navigation is related to an error handling phase, false for a regular navigation to a target view
-
hasRole
Gets if the current user belongs the specified logical role.
Parameters:
role
- a String specifying the name of the roleReturns:
true if the current user belongs to the given role, false otherwise
-
allow
Create a result instance informing that the navigation to the target view is allowed for the current user.
Returns:
a
AccessCheckDecision.ALLOW
result instance. -
neutral
Create a result instance informing that the checker cannot take a decision based on the given navigation information.
Returns:
a
AccessCheckDecision.NEUTRAL
result instance. -
deny
Create a result instance informing that the navigation to the target view is denied for the current user.
Parameters:
reason
- a message explaining why the navigation has been denied. Useful for debugging purposes.Returns:
a
AccessCheckDecision.DENY
result instance. -
reject
Create a result instance informing that the navigation to the target view is denied for the current user because of a misconfiguration or a critical development time error.
Parameters:
reason
- a message explaining why the navigation has been denied and the critical issue encountered. Useful for debugging purposes.Returns:
a
AccessCheckDecision.REJECT
result instance.
-