Class AbstractBaseStep<M extends BaseStepData,R>

java.lang.Object
io.getlime.security.powerauth.lib.cmd.steps.AbstractBaseStep<M,R>
Type Parameters:
M - Model data type
R - Response type
All Implemented Interfaces:
BaseStep
Direct Known Subclasses:
AbstractActivationStep, CommitUpgradeStep, ComputeOfflineSignatureStep, ConfirmRecoveryCodeStep, CreateTokenStep, EncryptStep, GetStatusStep, RemoveStep, RemoveTokenStep, SignAndEncryptStep, StartUpgradeStep, TokenAndEncryptStep, VaultUnlockStep, VerifySignatureStep, VerifyTokenStep

public abstract class AbstractBaseStep<M extends BaseStepData,R> extends Object implements BaseStep
Abstract step with common execution patterns and methods
Author:
Lukas Lukovsky, lukas.lukovsky@wultra.com
  • Field Details

    • resultStatusService

      protected final ResultStatusService resultStatusService
      Result status service
    • stepLoggerFactory

      protected final StepLoggerFactory stepLoggerFactory
      Step logger
  • Constructor Details

    • AbstractBaseStep

      public AbstractBaseStep(PowerAuthStep step, List<PowerAuthVersion> supportedVersions, ResultStatusService resultStatusService, StepLoggerFactory stepLoggerFactory)
      Constructor
      Parameters:
      step - Corresponding PowerAuth step
      supportedVersions - Supported versions of PowerAuth
      resultStatusService - Result status service
      stepLoggerFactory - Step logger factory
  • Method Details

    • prepareStepContext

      public abstract StepContext<M,R> prepareStepContext(StepLogger stepLogger, Map<String,Object> context) throws Exception
      Prepares a context for this step execution
      Parameters:
      stepLogger - Step logger
      context - Context data
      Returns:
      Step context
      Throws:
      Exception - when an error during context preparation occurred.
    • getResponseTypeReference

      protected abstract org.springframework.core.ParameterizedTypeReference<R> getResponseTypeReference()
      Returns:
      Type reference of the response object
    • execute

      public final ResultStatusObject execute(StepLogger stepLogger, Map<String,Object> context) throws Exception
      Execute this step with given logger and context objects.

      Keeps backward compatibility with former approaches of step instantiation and execution

      Specified by:
      execute in interface BaseStep
      Parameters:
      stepLogger - Step logger.
      context - Context objects.
      Returns:
      Result status object (with current activation status), null in case of failure.
      Throws:
      Exception - In case of a failure.
    • addEncryptedRequest

      public void addEncryptedRequest(StepContext<M,R> stepContext, String applicationKey, String applicationSecret, io.getlime.security.powerauth.crypto.lib.encryptor.model.EncryptorId encryptorId, byte[] data, io.getlime.security.powerauth.crypto.lib.encryptor.model.EncryptorScope scope) throws Exception
      Prepares encryptor and encrypts request data with given encryptor. The encrypted request is then added to the request context of this step.
      Parameters:
      stepContext - Context of this step
      applicationKey - Application key.
      applicationSecret - Application secret
      encryptorId - Encryptor identifier
      data - Request data for the encryption
      scope - Encryptor scope
      Throws:
      Exception - when an error during encryption of the request data occurred
    • addEncryptedRequest

      public void addEncryptedRequest(StepContext<M,R> stepContext, io.getlime.security.powerauth.crypto.lib.encryptor.ClientEncryptor encryptor, byte[] data) throws Exception
      Encrypts request data with given encryptor. The encrypted request is then added to the request context of this step.
      Parameters:
      stepContext - Context of this step
      encryptor - Encryptor to use
      data - Request data for the encryption
      Throws:
      Exception - when an error during encryption of the request data occurred
    • fetchTemporaryKey

      public void fetchTemporaryKey(StepContext<M,R> stepContext, io.getlime.security.powerauth.crypto.lib.encryptor.model.EncryptorScope scope) throws Exception
      Fetch temporary key for current request, if applicable.
      Parameters:
      stepContext - Step context.
      scope - ECIES scope.
      Throws:
      Exception - In case request fails.
    • decryptResponse

      public <T> T decryptResponse(StepContext<?,io.getlime.security.powerauth.rest.api.model.response.EciesEncryptedResponse> stepContext, Class<T> cls)
      Decrypts an object from a response
      Type Parameters:
      T - Class of the decrypted object
      Parameters:
      stepContext - Step context
      cls - Class type of the decrypted object
      Returns:
      Decrypted object from the provided response
    • processResponse

      public void processResponse(StepContext<M,R> stepContext) throws Exception
      Optional processing of the response data
      Parameters:
      stepContext - Step context
      Throws:
      Exception - when an error during response processing occurred
    • processResponse

      public final void processResponse(StepContext<M,R> stepContext, byte[] responseBody, Class<R> responseObjectClass) throws Exception
      Processing of the response data bytes
      Parameters:
      stepContext - Step context
      responseBody - Response body bytes
      responseObjectClass - Response object class
      Throws:
      Exception - when an error during response processing occurred
    • buildStepContext

      protected final StepContext<M,R> buildStepContext(StepLogger stepLogger, M model, RequestContext requestContext)
      Builds a step context instance from a model and a request context
      Parameters:
      stepLogger - Step logger
      model - Data model
      requestContext - Request context
      Returns:
      Step context instance
    • incrementCounter

      protected <RS extends ResultStatusChangeable> void incrementCounter(RS model) throws Exception
      Increments the counter (the signature already used hash based counter)
      Type Parameters:
      RS - Type of the model with result status
      Parameters:
      model - Model
      Throws:
      Exception - when an error during saving the model occurred
    • logDryRun

      protected void logDryRun(StepLogger stepLogger)
      Optional way to log special messages when in a dry run (no real service call)
      Parameters:
      stepLogger - Step logger