Package com.mwdle.bitwarden.cli
Class BitwardenSessionManager
java.lang.Object
com.mwdle.bitwarden.cli.BitwardenSessionManager
A thread-safe singleton that manages and caches a single, global Bitwarden session token.
This class ensures that the slow, network-intensive login and unlock operations required for Bitwarden interactions are performed infrequently. It uses a high-performance, double-checked locking pattern to provide concurrent access to the session token.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BitwardenSessionManager
Provides global access to the single instance of this manager.Provides thread-safe, high-performance access to a valid Bitwarden session token.void
Invalidates the current session token.boolean
Performs a check to see if the cached session token is still valid by callingbw status
.
-
Method Details
-
getInstance
Provides global access to the single instance of this manager.- Returns:
- The singleton instance of
BitwardenSessionManager
.
-
getSessionToken
Provides thread-safe, high-performance access to a valid Bitwarden session token.This method uses a double-checked locking pattern. The "fast path" checks the validity of the token without acquiring a lock, handling the vast majority of calls. Only if the token is invalid will it enter a synchronized block to perform the expensive re-authentication.
- Returns:
- A valid session token.
- Throws:
IOException
- If the login/unlock process fails.InterruptedException
- If the CLI command is interrupted.
-
isSessionValid
public boolean isSessionValid()Performs a check to see if the cached session token is still valid by callingbw status
.- Returns:
true
if the token is present and the vault status isunlocked
.
-
invalidateSessionToken
public void invalidateSessionToken()Invalidates the current session token.The next call to
getSessionToken()
will be forced to perform a full re-authentication. This is typically called after the plugin's global configuration has been changed.
-