Class AbstractBaseStep<M extends BaseStepData,R>
java.lang.Object
io.getlime.security.powerauth.lib.cmd.steps.AbstractBaseStep<M,R>
- Type Parameters:
M- Model data typeR- Response type
- All Implemented Interfaces:
BaseStep
- Direct Known Subclasses:
AbstractActivationStep,CommitUpgradeStep,ConfirmRecoveryCodeStep,CreateTokenStep,EncryptStep,GetStatusStep,RemoveStep,RemoveTokenStep,SignAndEncryptStep,StartUpgradeStep,VaultUnlockStep,VerifySignatureStep,VerifyTokenStep
public abstract class AbstractBaseStep<M extends BaseStepData,R> extends java.lang.Object implements BaseStep
Abstract step with common execution patterns and methods
- Author:
- Lukas Lukovsky, lukas.lukovsky@wultra.com
-
Field Summary
Fields Modifier and Type Field Description protected ResultStatusServiceresultStatusServiceResult status serviceprotected StepLoggerFactorystepLoggerFactoryStep logger -
Constructor Summary
Constructors Constructor Description AbstractBaseStep(PowerAuthStep step, java.util.List<PowerAuthVersion> supportedVersions, ResultStatusService resultStatusService, StepLoggerFactory stepLoggerFactory)Constructor -
Method Summary
Modifier and Type Method Description voidaddEncryptedRequest(StepContext<M,R> stepContext, java.lang.String applicationSecret, io.getlime.security.powerauth.crypto.lib.encryptor.ecies.model.EciesSharedInfo1 eciesSharedInfo, byte[] data)Prepares ECIES encryptor and encrypts request data with sharedInfo1.protected StepContext<M,R>buildStepContext(StepLogger stepLogger, M model, RequestContext requestContext)Builds a step context instance from a model and a request context<T> TdecryptResponse(StepContext<?,io.getlime.security.powerauth.rest.api.model.response.v3.EciesEncryptedResponse> stepContext, java.lang.Class<T> cls)Decrypts an object from a responseorg.json.simple.JSONObjectexecute(StepLogger stepLogger, java.util.Map<java.lang.String,java.lang.Object> context)Execute this step with given logger and context objects.ResultStatusObjectexecute(java.util.Map<java.lang.String,java.lang.Object> context)Executes this step with a given contextprotected abstract org.springframework.core.ParameterizedTypeReference<R>getResponseTypeReference()protected <RS extends ResultStatusChangeable>
voidincrementCounter(RS model)Increments the counter (the signature already used hash based counter)protected voidlogDryRun(StepLogger stepLogger)Optional way to log special messages when in a dry run (no real service call)abstract StepContext<M,R>prepareStepContext(StepLogger stepLogger, java.util.Map<java.lang.String,java.lang.Object> context)Prepares a context for this step executionvoidprocessResponse(StepContext<M,R> stepContext)Optional processing of the response datavoidprocessResponse(StepContext<M,R> stepContext, byte[] responseBody, java.lang.Class<R> responseObjectClass)Processing of the response data bytesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.getlime.security.powerauth.lib.cmd.steps.BaseStep
getStep, getSupportedVersions
-
Field Details
-
resultStatusService
Result status service -
stepLoggerFactory
Step logger
-
-
Constructor Details
-
AbstractBaseStep
public AbstractBaseStep(PowerAuthStep step, java.util.List<PowerAuthVersion> supportedVersions, ResultStatusService resultStatusService, StepLoggerFactory stepLoggerFactory)Constructor- Parameters:
step- Corresponding PowerAuth stepsupportedVersions- Supported versions of PowerAuthresultStatusService- Result status servicestepLoggerFactory- Step logger factory
-
-
Method Details
-
prepareStepContext
public abstract StepContext<M,R> prepareStepContext(StepLogger stepLogger, java.util.Map<java.lang.String,java.lang.Object> context) throws java.lang.ExceptionPrepares a context for this step execution- Parameters:
stepLogger- Step loggercontext- Context data- Returns:
- Step context
- Throws:
java.lang.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(java.util.Map<java.lang.String,java.lang.Object> context) throws java.lang.ExceptionExecutes this step with a given context -
execute
public final org.json.simple.JSONObject execute(StepLogger stepLogger, java.util.Map<java.lang.String,java.lang.Object> context) throws java.lang.ExceptionExecute 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:
java.lang.Exception- In case of a failure.
-
decryptResponse
public <T> T decryptResponse(StepContext<?,io.getlime.security.powerauth.rest.api.model.response.v3.EciesEncryptedResponse> stepContext, java.lang.Class<T> cls) throws java.lang.ExceptionDecrypts an object from a response- Type Parameters:
T- Class of the decrypted object- Parameters:
stepContext- Step contextcls- Class type of the decrypted object- Returns:
- Decrypted object from the provided response
- Throws:
java.lang.Exception- when an error during object decryption occurred
-
processResponse
Optional processing of the response data- Parameters:
stepContext- Step context- Throws:
java.lang.Exception- when an error during response processing occurred
-
processResponse
public final void processResponse(StepContext<M,R> stepContext, byte[] responseBody, java.lang.Class<R> responseObjectClass) throws java.lang.ExceptionProcessing of the response data bytes- Parameters:
stepContext- Step contextresponseBody- Response body bytesresponseObjectClass- Response object class- Throws:
java.lang.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 loggermodel- Data modelrequestContext- Request context- Returns:
- Step context instance
-
incrementCounter
protected <RS extends ResultStatusChangeable> void incrementCounter(RS model) throws java.lang.ExceptionIncrements the counter (the signature already used hash based counter)- Type Parameters:
RS- Type of the model with result status- Parameters:
model- Model- Throws:
java.lang.Exception- when an error during saving the model occurred
-
logDryRun
Optional way to log special messages when in a dry run (no real service call)- Parameters:
stepLogger- Step logger
-