Class SessionToken
- java.lang.Object
-
- net.webpdf.wsclient.session.auth.material.token.SessionToken
-
- All Implemented Interfaces:
Serializable,AuthMaterial,JWTToken
public class SessionToken extends Object implements Serializable, JWTToken
An instance of
SessionTokenwraps the access and refresh tokens provided by the webPDF server.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SessionToken()Creates a new, emptySessionToken.SessionToken(@NotNull String accessToken, @NotNull String refreshToken, long expiresIn)Creates a newSessionTokenfrom preexisting token values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull InstantgetExpiration()Returns theInstanttheSessionTokenwill expire at.@NotNull StringgetToken()Returns the access tokenStringvalue.booleanisExpired(int skewTime)voidrefresh()Replaces the access token with the refresh token.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.webpdf.wsclient.session.auth.material.AuthMaterial
getAuthHeader
-
Methods inherited from interface net.webpdf.wsclient.session.auth.material.token.JWTToken
getCredentials, getRawAuthHeader
-
-
-
-
Constructor Detail
-
SessionToken
public SessionToken(@NotNull @NotNull String accessToken, @NotNull @NotNull String refreshToken, long expiresIn)Creates a newSessionTokenfrom preexisting token values.- Parameters:
accessToken- The access tokenStringvalue.refreshToken- The refresh tokenStringvalue.expiresIn- The token expiry time in seconds.
-
SessionToken
public SessionToken()
Creates a new, emptySessionToken.
-
-
Method Detail
-
getToken
@NotNull public @NotNull String getToken()
Returns the access tokenStringvalue. Shall return an empty String for an uninitialized session.- Specified by:
getTokenin interfaceAuthMaterial- Specified by:
getTokenin interfaceJWTToken- Returns:
- The access token
Stringvalue.
-
refresh
public void refresh()
Replaces the access token with the refresh token.
Be aware: Using the refresh token as auth material is only valid and advisable while refreshing the webPDF access token - other calls to the server will fail until a new access token is provided.
Synchronization of webservice calls is absolutely necessary during a token refresh and it is recommended to delay other calls until a fresh and valid access token is available.
ThisSessionTokenshould be discarded after refreshing the token has finished.
-
getExpiration
@NotNull public @NotNull Instant getExpiration()
Returns theInstanttheSessionTokenwill expire at.- Returns:
- The
InstanttheSessionTokenwill expire at.
-
isExpired
public boolean isExpired(int skewTime)
Returnstrue, if the current access token is expired andrefresh()should be called to request a new access token for theSession.- Parameters:
skewTime- An additional skew time, in seconds, that is added during expiry evaluation. (Adding a skew time helps in avoiding to use expired access tokens because of transfer delays.)- Returns:
true, if the current access token is expired.
-
-