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, 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

  • 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 ResultStatusObject execute​(Map<String,​Object> context) throws Exception
      Executes this step with a given context
      Specified by:
      execute in interface BaseStep
      Parameters:
      context - Provided context
      Returns:
      Result status object, null in case of failure.
      Throws:
      Exception - In case of any error.
    • execute

      public final org.json.simple.JSONObject 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

      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 applicationSecret, io.getlime.security.powerauth.crypto.lib.encryptor.ecies.model.EciesSharedInfo1 eciesSharedInfo, byte[] data) throws Exception
      Prepares ECIES encryptor and encrypts request data with sharedInfo1. The encrypted request is then added to the request context of this step.
      Parameters:
      stepContext - Context of this step
      applicationSecret - Application secret
      eciesSharedInfo - Parameter sharedInfo1
      data - Request data for the encryption
      Throws:
      Exception - when an error during encryption of the request data occurred
    • decryptResponse

      public <T> T decryptResponse​(StepContext<?,​io.getlime.security.powerauth.rest.api.model.response.v3.EciesEncryptedResponse> stepContext, Class<T> cls) throws Exception
      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
      Throws:
      Exception - when an error during object decryption occurred
    • 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