Search in sources :

Example 1 with ActivationStatus

use of io.getlime.security.powerauth.rest.api.spring.model.ActivationStatus in project powerauth-restful-integration by lime-company.

the class PowerAuthAuthenticationProvider method validateTokenAuthentication.

/**
 * Validate basic token-based authentication.
 *
 * @param authentication Token based authentication object.
 * @return API authentication object in case of successful authentication, null otherwise.
 */
private PowerAuthApiAuthenticationImpl validateTokenAuthentication(PowerAuthTokenAuthenticationImpl authentication) {
    try {
        final ValidateTokenRequest request = new ValidateTokenRequest();
        request.setTokenId(authentication.getTokenId());
        request.setTokenDigest(authentication.getTokenDigest());
        request.setNonce(authentication.getNonce());
        request.setTimestamp(Long.parseLong(authentication.getTimestamp()));
        final ValidateTokenResponse response = powerAuthClient.validateToken(request);
        final ActivationStatus activationStatus;
        if (response.isTokenValid()) {
            activationStatus = ActivationStatus.ACTIVE;
        } else {
            // Detailed activation status in case of token authentication failure needs to be obtained from PA server
            activationStatus = null;
        }
        final AuthenticationContext authenticationContext = new AuthenticationContext();
        authenticationContext.setValid(response.isTokenValid());
        authenticationContext.setRemainingAttempts(null);
        authenticationContext.setSignatureType(response.getSignatureType() != null ? PowerAuthSignatureTypes.getEnumFromString(response.getSignatureType().value()) : null);
        final PowerAuthActivation activationContext = copyActivationAttributes(response.getActivationId(), response.getUserId(), activationStatus, null, response.getActivationFlags(), authenticationContext, authentication.getVersion());
        return copyAuthenticationAttributes(response.getActivationId(), response.getUserId(), response.getApplicationId(), response.getApplicationRoles(), response.getActivationFlags(), authenticationContext, authentication.getVersion(), authentication.getHttpHeader(), activationContext);
    } catch (NumberFormatException ex) {
        logger.warn("Invalid timestamp format, error: {}", ex.getMessage());
        logger.debug("Error details", ex);
        return null;
    } catch (Exception ex) {
        logger.warn("Token validation failed, error: {}", ex.getMessage());
        logger.debug("Error details", ex);
        return null;
    }
}
Also used : AuthenticationContext(io.getlime.security.powerauth.rest.api.spring.model.AuthenticationContext) ActivationStatus(io.getlime.security.powerauth.rest.api.spring.model.ActivationStatus) PowerAuthActivation(io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthActivation) PowerAuthTokenInvalidException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthTokenInvalidException) InvalidPowerAuthHttpHeaderException(io.getlime.security.powerauth.http.validator.InvalidPowerAuthHttpHeaderException) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthAuthenticationException) PowerAuthSignatureTypeInvalidException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureTypeInvalidException) PowerAuthSignatureInvalidException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureInvalidException) AuthenticationException(org.springframework.security.core.AuthenticationException) PowerAuthHeaderMissingException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthHeaderMissingException) PowerAuthClientException(com.wultra.security.powerauth.client.model.error.PowerAuthClientException)

Aggregations

PowerAuthClientException (com.wultra.security.powerauth.client.model.error.PowerAuthClientException)1 InvalidPowerAuthHttpHeaderException (io.getlime.security.powerauth.http.validator.InvalidPowerAuthHttpHeaderException)1 PowerAuthActivation (io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthActivation)1 PowerAuthAuthenticationException (io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthAuthenticationException)1 PowerAuthHeaderMissingException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthHeaderMissingException)1 PowerAuthSignatureInvalidException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureInvalidException)1 PowerAuthSignatureTypeInvalidException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureTypeInvalidException)1 PowerAuthTokenInvalidException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthTokenInvalidException)1 ActivationStatus (io.getlime.security.powerauth.rest.api.spring.model.ActivationStatus)1 AuthenticationContext (io.getlime.security.powerauth.rest.api.spring.model.AuthenticationContext)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1