Class TokenManagerOpenIDConnect
java.lang.Object
de.fraunhofer.iosb.ilt.frostclient.utils.TokenManagerOpenIDConnect
- All Implemented Interfaces:
TokenManager<TokenManagerOpenIDConnect>
public class TokenManagerOpenIDConnect
extends Object
implements TokenManager<TokenManagerOpenIDConnect>
A TokenManager for JsonWebTokens used in OpenID Connect authentication.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAuthHeader(org.apache.http.HttpRequest request) Add any headers to the request that are required Authentication and Authorisation.org.apache.http.impl.client.CloseableHttpClientGet the HTTP client this TokenManager uses to fetch tokens.getToken()booleansetAutoRefresh(boolean autoRefresh) Turns autoRefresh on or off.setClientId(String clientId) The clientId to use for fetching tokens.setHttpClient(org.apache.http.impl.client.CloseableHttpClient client) Set the HTTP client this TokenManager uses to fetch tokens.setKeyType(String keyType) The type of public key (RSA or DSA).setPassword(String password) Set the password to use for getting Tokens.setRefreshExpireDuration(int refreshExpireDuration) Set the expire duration of the refresh token.setRefreshToken(String refreshToken) Set a refreshToken.setSigningKey(String signingKey) The public key to use for validating the token signature.setTokenServerUrl(String tokenServerUrl) Set the URL to fetch tokens from.setUserName(String userName) Set the username to use for getting Tokens.booleanvalidateToken(String token)
-
Constructor Details
-
TokenManagerOpenIDConnect
public TokenManagerOpenIDConnect()
-
-
Method Details
-
addAuthHeader
public void addAuthHeader(org.apache.http.HttpRequest request) Description copied from interface:TokenManagerAdd any headers to the request that are required Authentication and Authorisation.- Specified by:
addAuthHeaderin interfaceTokenManager<TokenManagerOpenIDConnect>- Parameters:
request- The request to modify.
-
isExpired
public boolean isExpired() -
getToken
-
validateToken
-
setHttpClient
public TokenManagerOpenIDConnect setHttpClient(org.apache.http.impl.client.CloseableHttpClient client) Set the HTTP client this TokenManager uses to fetch tokens.- Specified by:
setHttpClientin interfaceTokenManager<TokenManagerOpenIDConnect>- Parameters:
client- The CloseableHttpClient to use for fetching Tokens.- Returns:
- this TokenManager
-
getHttpClient
public org.apache.http.impl.client.CloseableHttpClient getHttpClient()Get the HTTP client this TokenManager uses to fetch tokens.- Specified by:
getHttpClientin interfaceTokenManager<TokenManagerOpenIDConnect>- Returns:
- The HTTP client this TokenManager uses to fetch tokens.
-
setTokenServerUrl
Set the URL to fetch tokens from. Usually in the form of http://example.com/auth/realms/{realm}/protocol/openid-connect/token- Parameters:
tokenServerUrl- The URL to fetch tokens from.- Returns:
- this TokenManager
-
setClientId
The clientId to use for fetching tokens. This client has to be able to use Direct Access Grants on the Authentication server.- Parameters:
clientId- The clientId on the Auth Server.- Returns:
- this TokenManager
-
setUserName
Set the username to use for getting Tokens.- Parameters:
userName- The username to use for getting Tokens.- Returns:
- this TokenManager
-
setPassword
Set the password to use for getting Tokens.- Parameters:
password- The password to use for getting Tokens.- Returns:
- this TokenManager
-
setSigningKey
The public key to use for validating the token signature.- Parameters:
signingKey- The Base64 encoded public key.- Returns:
- this TokenManager
-
setKeyType
The type of public key (RSA or DSA).- Parameters:
keyType- The type of public key (RSA or DSA).- Returns:
- this TokenManager
-
setRefreshToken
Set a refreshToken. If you do not want to pass a username and password, you can instead fetch a token yourself, and pass the refresh token to the TokenManager. The TokenManager will then use this refreshToken to fetch an actual token.- Parameters:
refreshToken- The refreshToken to use instead of username/password.- Returns:
- this TokenManager
-
setRefreshExpireDuration
Set the expire duration of the refresh token. If autoRefresh is true, and no activity has occurred long enough for the refresh token to (almost) expire, an automatic refresh of the token will be done. If you set this you probably also want to set autoRefresh to true.- Parameters:
refreshExpireDuration- The expire duration of the refresh token.- Returns:
- this TokenManager
-
setAutoRefresh
Turns autoRefresh on or off. If autoRefresh is true, and no activity has occurred long enough for the refresh token to (almost) expire, an automatic refresh of the token will be done. If the auth server does not specify the refresh token lifetime, you will have to set it withsetRefreshExpireDuration(int)- Parameters:
autoRefresh- Should autoRefresh happen or not.- Returns:
- this TokenManager
-