Class OauthHelper


  • public class OauthHelper
    extends Object
    • Field Detail

      • STATUS_CLIENT_CREDENTIALS_TOKEN_NOT_AVAILABLE

        public static final String STATUS_CLIENT_CREDENTIALS_TOKEN_NOT_AVAILABLE
        See Also:
        Constant Field Values
    • Constructor Detail

      • OauthHelper

        public OauthHelper()
    • Method Detail

      • getTokenResult

        public static Result<TokenResponse> getTokenResult​(TokenRequest tokenRequest)
        Get an access token from the token service. A Result of TokenResponse will be returned if the invocation is successfully. Otherwise, a Result of Status will be returned.
        Parameters:
        tokenRequest - token request constructed from the client.yml token section.
        Returns:
        Result of TokenResponse or error Status.
      • getTokenResult

        public static Result<TokenResponse> getTokenResult​(TokenRequest tokenRequest,
                                                           String envTag)
        Get an access token from the token service. A Result of TokenResponse will be returned if the invocation is successfully. Otherwise, a Result of Status will be returned.
        Parameters:
        tokenRequest - token request constructed from the client.yml token section.
        envTag - the environment tag from the server.yml for service lookup.
        Returns:
        Result of TokenResponse or error Status.
      • getSignResult

        public static Result<TokenResponse> getSignResult​(SignRequest signRequest)
        Get a signed JWT token from token service to ensure that nobody can modify the payload when the token is passed from service to service. Unlike the access JWT token, this token is ensure the data integrity with signature.
        Parameters:
        signRequest - SignRequest that is constructed from the client.yml sign section
        Returns:
        Result that contains TokenResponse or error status when failed.
      • getSignResult

        public static Result<TokenResponse> getSignResult​(SignRequest signRequest,
                                                          String envTag)
        Get a signed JWT token from token service to ensure that nobody can modify the payload when the token is passed from service to service. Unlike the access JWT token, this token is ensure the data integrity with signature.
        Parameters:
        signRequest - SignRequest that is constructed from the client.yml sign section
        envTag - environment tag that is used for service lookup if serviceId is used.
        Returns:
        Result that contains TokenResponse or error status when failed.
      • getTokenFromSamlResult

        public static Result<TokenResponse> getTokenFromSamlResult​(SAMLBearerRequest tokenRequest)
        Get an access token from the token service based on a SAML token request. A Result of TokenResponse will be returned if the invocation is successfully. Otherwise, a Result of Status will be returned.
        Parameters:
        tokenRequest - token request constructed from the client.yml token section.
        Returns:
        Result of TokenResponse or error Status.
      • getTokenFromSamlResult

        public static Result<TokenResponse> getTokenFromSamlResult​(SAMLBearerRequest tokenRequest,
                                                                   String envTag)
        Get an access token from the token service based on a SAML token request. A Result of TokenResponse will be returned if the invocation is successfully. Otherwise, a Result of Status will be returned.
        Parameters:
        tokenRequest - token request constructed from the client.yml token section.
        envTag - environment tag for service lookup.
        Returns:
        Result of TokenResponse or error Status.
      • getKey

        public static String getKey​(KeyRequest keyRequest)
                             throws ClientException
        Get the certificate from key distribution service of OAuth 2.0 provider with the kid.
        Parameters:
        keyRequest - One of the sub classes to get the key for access token or sign token.
        Returns:
        String of the certificate
        Throws:
        ClientException - throw exception if communication with the service fails.
      • getKey

        public static String getKey​(KeyRequest keyRequest,
                                    String envTag)
                             throws ClientException
        Get the certificate from key distribution service of OAuth 2.0 provider with the kid.
        Parameters:
        keyRequest - One of the sub classes to get the key for access token or sign token.
        envTag - the environment tag from the server.yml for the cluster lookup.
        Returns:
        String of the certificate
        Throws:
        ClientException - throw exception if communication with the service fails.
      • derefToken

        public static String derefToken​(DerefRequest derefRequest)
                                 throws ClientException
        De-reference a simple web token to JWT token from OAuth 2.0 provider. This is normally called from the light-router.
        Parameters:
        derefRequest - a DerefRequest object that is constructed from the client.yml file.
        Returns:
        String of JWT token
        Throws:
        ClientException - when error occurs.
      • derefToken

        public static String derefToken​(DerefRequest derefRequest,
                                        String envTag)
                                 throws ClientException
        De-reference a simple web token to JWT token from OAuth 2.0 provider. This is normally called from the light-router.
        Parameters:
        derefRequest - a DerefRequest object that is constructed from the client.yml file.
        envTag - an environment tag from the server.yml for cluster service lookup.
        Returns:
        String of JWT token or a status json if there is an error.
        Throws:
        ClientException - when error occurs.
      • getBasicAuthHeader

        public static String getBasicAuthHeader​(String clientId,
                                                String clientSecret)
      • encodeCredentials

        public static String encodeCredentials​(String clientId,
                                               String clientSecret)
      • populateCCToken

        public static Result<Jwt> populateCCToken​(Jwt jwt)
        populate/renew jwt info to the give jwt object. based on the expire time of the jwt, to determine if need to renew jwt or not. to avoid modifying class member which will case thread-safe problem, move this method from Http2Client to this helper class.
        Parameters:
        jwt - the given jwt needs to renew or populate
        Returns:
        When success return Jwt; When fail return Status.