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,ComputeOfflineSignatureStep,ConfirmRecoveryCodeStep,CreateTokenStep,EncryptStep,GetStatusStep,RemoveStep,RemoveTokenStep,SignAndEncryptStep,StartUpgradeStep,TokenAndEncryptStep,VaultUnlockStep,VerifySignatureStep,VerifyTokenStep
Abstract step with common execution patterns and methods
- Author:
- Lukas Lukovsky, lukas.lukovsky@wultra.com
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ResultStatusServiceResult status serviceprotected final StepLoggerFactoryStep logger -
Constructor Summary
ConstructorsConstructorDescriptionAbstractBaseStep(PowerAuthStep step, List<PowerAuthVersion> supportedVersions, ResultStatusService resultStatusService, StepLoggerFactory stepLoggerFactory) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEncryptedRequest(StepContext<M, R> stepContext, io.getlime.security.powerauth.crypto.lib.encryptor.ClientEncryptor encryptor, byte[] data) Encrypts request data with given encryptor.voidaddEncryptedRequest(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) Prepares encryptor and encrypts request data with given encryptor.protected final 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.EciesEncryptedResponse> stepContext, Class<T> cls) Decrypts an object from a responsefinal ResultStatusObjectexecute(StepLogger stepLogger, Map<String, Object> context) Execute this step with given logger and context objects.voidfetchTemporaryKey(StepContext<M, R> stepContext, io.getlime.security.powerauth.crypto.lib.encryptor.model.EncryptorScope scope) Fetch temporary key for current request, if applicable.protected abstract org.springframework.core.ParameterizedTypeReference<R> 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, Map<String, Object> context) Prepares a context for this step executionvoidprocessResponse(StepContext<M, R> stepContext) Optional processing of the response datafinal voidprocessResponse(StepContext<M, R> stepContext, byte[] responseBody, 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, 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, Map<String, Object> context) throws ExceptionPrepares a context for this step execution- Parameters:
stepLogger- Step loggercontext- 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 ExceptionExecute this step with given logger and context objects.Keeps backward compatibility with former approaches of step instantiation and execution
-
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 ExceptionPrepares 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 stepapplicationKey- Application key.applicationSecret- Application secretencryptorId- Encryptor identifierdata- Request data for the encryptionscope- 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 ExceptionEncrypts request data with given encryptor. The encrypted request is then added to the request context of this step.- Parameters:
stepContext- Context of this stepencryptor- Encryptor to usedata- 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 ExceptionFetch 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 contextcls- Class type of the decrypted object- Returns:
- Decrypted object from the provided response
-
processResponse
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 ExceptionProcessing of the response data bytes- Parameters:
stepContext- Step contextresponseBody- Response body bytesresponseObjectClass- 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 loggermodel- Data modelrequestContext- Request context- Returns:
- Step context instance
-
incrementCounter
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
Optional way to log special messages when in a dry run (no real service call)- Parameters:
stepLogger- Step logger
-