Class TokenService
java.lang.Object
africa.absa.inception.oauth2.server.authorization.token.TokenService
- All Implemented Interfaces:
ITokenService
The TokenService class provides the Token Service implementation.
- Author:
- Marcus Portmann
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe access token validity in seconds.static final intThe period in seconds prior to expiry of the refresh token during which it will be automatically re-issued.static final intThe refresh token validity in seconds. -
Constructor Summary
ConstructorsConstructorDescriptionTokenService(ISecurityService securityService) Constructs a new TokenService. -
Method Summary
Modifier and TypeMethodDescriptionissueOAuth2AccessToken(String username, Set<String> scopes) Issue an OAuth2 access token for the specified user.issueOAuth2RefreshToken(String username, Set<String> scopes) Issue an OAuth2 refresh token for the specified user.refreshOAuth2Tokens(String encodedOAuth2RefreshToken) Refresh an OAuth2 access token and if required the OAuth2 refresh token.
-
Field Details
-
ACCESS_TOKEN_VALIDITY
public static final int ACCESS_TOKEN_VALIDITYThe access token validity in seconds.- See Also:
-
REFRESH_TOKEN_REISSUE_INTERVAL
public static final int REFRESH_TOKEN_REISSUE_INTERVALThe period in seconds prior to expiry of the refresh token during which it will be automatically re-issued.- See Also:
-
REFRESH_TOKEN_VALIDITY
public static final int REFRESH_TOKEN_VALIDITYThe refresh token validity in seconds.- See Also:
-
-
Constructor Details
-
TokenService
Constructs a new TokenService.- Parameters:
securityService- the Security Service
-
-
Method Details
-
issueOAuth2AccessToken
public OAuth2AccessToken issueOAuth2AccessToken(String username, Set<String> scopes) throws ServiceUnavailableException Issue an OAuth2 access token for the specified user.- Specified by:
issueOAuth2AccessTokenin interfaceITokenService- Parameters:
username- the username for the userscopes- the optional scope(s) for the access token- Returns:
- the OAuth2 access token
- Throws:
ServiceUnavailableException- if the OAuth2 access token could not be issued for the user
-
issueOAuth2RefreshToken
public OAuth2RefreshToken issueOAuth2RefreshToken(String username, Set<String> scopes) throws ServiceUnavailableException Issue an OAuth2 refresh token for the specified user.- Specified by:
issueOAuth2RefreshTokenin interfaceITokenService- Parameters:
username- the username for the userscopes- the optional scope(s) for the refresh token- Returns:
- the OAuth2 refresh token
- Throws:
ServiceUnavailableException- if the OAuth2 refresh token could not be issued for the user
-
refreshOAuth2Tokens
public RefreshedOAuth2Tokens refreshOAuth2Tokens(String encodedOAuth2RefreshToken) throws InvalidOAuth2RefreshTokenException, ServiceUnavailableException Refresh an OAuth2 access token and if required the OAuth2 refresh token.- Specified by:
refreshOAuth2Tokensin interfaceITokenService- Parameters:
encodedOAuth2RefreshToken- the encoded OAuth2 refresh token- Returns:
- the refreshed tokens
- Throws:
InvalidOAuth2RefreshTokenException- if the OAuth2 refresh token is invalidServiceUnavailableException- if the OAuth2 access token and refresh token could not be refreshed
-