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;
}
}
Aggregations