Class TokenService
- java.lang.Object
-
- africa.absa.inception.oauth2.server.authorization.token.TokenService
-
- All Implemented Interfaces:
ITokenService
@Service public class TokenService extends Object implements ITokenService
The TokenService class provides the Token Service implementation.- Author:
- Marcus Portmann
-
-
Field Summary
Fields Modifier and Type Field Description static intACCESS_TOKEN_VALIDITYThe access token validity in seconds.static intREFRESH_TOKEN_REISSUE_INTERVALThe period in seconds prior to expiry of the refresh token during which it will be automatically re-issued.static intREFRESH_TOKEN_VALIDITYThe refresh token validity in seconds.
-
Constructor Summary
Constructors Constructor Description TokenService(ISecurityService securityService)Constructs a new TokenService.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OAuth2AccessTokenissueOAuth2AccessToken(String username, Set<String> scopes)Issue an OAuth2 access token for the specified user.OAuth2RefreshTokenissueOAuth2RefreshToken(String username, Set<String> scopes)Issue an OAuth2 refresh token for the specified user.RefreshedOAuth2TokensrefreshOAuth2Tokens(String encodedOAuth2RefreshToken)Refresh an OAuth2 access token and if required the OAuth2 refresh token.
-
-
-
Field Detail
-
ACCESS_TOKEN_VALIDITY
public static final int ACCESS_TOKEN_VALIDITY
The access token validity in seconds.- See Also:
- Constant Field Values
-
REFRESH_TOKEN_REISSUE_INTERVAL
public static final int REFRESH_TOKEN_REISSUE_INTERVAL
The period in seconds prior to expiry of the refresh token during which it will be automatically re-issued.- See Also:
- Constant Field Values
-
REFRESH_TOKEN_VALIDITY
public static final int REFRESH_TOKEN_VALIDITY
The refresh token validity in seconds.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TokenService
public TokenService(ISecurityService securityService)
Constructs a new TokenService.- Parameters:
securityService- the Security Service
-
-
Method Detail
-
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
-
-