Package com.vaadin.flow.spring.security
Class AuthenticationContext
- java.lang.Object
-
- com.vaadin.flow.spring.security.AuthenticationContext
-
- All Implemented Interfaces:
Serializable
public class AuthenticationContext extends Object implements Serializable
The authentication context of the application.An instance of this class is available for injection as bean in view and layout classes. It allows to access authenticated user information and to initiate the logout process.
- Since:
- 23.3
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AuthenticationContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <U> Optional<U>getAuthenticatedUser(Class<U> userType)Gets anOptionalwith an instance of the current user if it has been authenticated, or empty if the user is not authenticated.booleanisAuthenticated()Indicates whether a user is currently authenticated.voidlogout()Initiates the logout process of the current authenticated user by invalidating the local session and then notifyingLogoutHandler.
-
-
-
Method Detail
-
getAuthenticatedUser
public <U> Optional<U> getAuthenticatedUser(Class<U> userType)
Gets anOptionalwith an instance of the current user if it has been authenticated, or empty if the user is not authenticated. Anonymous users are considered not authenticated.- Type Parameters:
U- the type parameter of the expected user instance- Parameters:
userType- the type of the expected user instance- Returns:
- an
Optionalwith the current authenticated user, or empty if none available - Throws:
ClassCastException- if the current user instance does not match the givenuserType.
-
isAuthenticated
public boolean isAuthenticated()
Indicates whether a user is currently authenticated. Anonymous users are considered not authenticated.- Returns:
- true if a user is currently authenticated, otherwise false
-
logout
public void logout()
Initiates the logout process of the current authenticated user by invalidating the local session and then notifyingLogoutHandler.
-
-