java.lang.Object
es.kukenan.smartfi.microservice.onboarding.service.OtpService

@Service public class OtpService extends Object
Otp Service for check otps and otp management access.
  • Field Details

    • ADVANCE_PRODUCT

      private static final String ADVANCE_PRODUCT
      Advance constant.
      See Also:
    • RESEND_TO_CHANGE_OTP

      private static final int RESEND_TO_CHANGE_OTP
      Number of resend to ignore primary channel.
      See Also:
    • log

      private final es.kukenan.smartfi.logger.WalletLogger log
      Instance logger.
    • internalIpUsers

      @Value("${security.gateway.service.users.uri}") private String internalIpUsers
      Ip for internal services.
    • otpTimeToLive

      @Value("${otp.expired.timetolive}") private int otpTimeToLive
      Time to live.
    • otpResendLimit

      @Value("${otp.resend.limit}") private int otpResendLimit
      OTP resend limit.
    • otpFailureLimit

      @Value("${otp.failure.limit}") private int otpFailureLimit
      OTP failure limit.
    • microserviceJwt

      @Value("${client.jwt}") private String microserviceJwt
      Microservice JWT token, used to perform internal inter-microservice calls.
    • otpUtilities

      @Autowired private OtpUtilities otpUtilities
      utilities for otp.
    • requestContextManager

      @Autowired private es.kukenan.smartfi.common.context.RequestContextManager requestContextManager
      RequestContextManager context manager.
    • amqpController

      @Autowired private AmqpController amqpController
      AmqpController controller.
    • kafkaController

      @Autowired private KafkaController kafkaController
      Kafka Controller.
    • otpCacheOperation

      @Autowired private OtpCacheOperation otpCacheOperation
      OtpCacheOperation otp cache operations.
    • userRepository

      @Autowired UserRepository userRepository
      Users repository.
    • userBackofficeRepository

      @Autowired UserBackofficeRepository userBackofficeRepository
      User Backoffice repository.
    • addressRepository

      @Autowired AddressRepository addressRepository
      Address repository.
    • userDocumentRepository

      @Autowired UserDocumentRepository userDocumentRepository
      UserDocument repository.
    • onboardingUpdateEventMapper

      @Autowired OnboardingUpdateEventMapper onboardingUpdateEventMapper
      User updated Event mapper.
    • internalProductsApiClient

      @Autowired private InternalProductsApiClient internalProductsApiClient
      Core api client.
    • backofficeService

      @Autowired private BackofficeService backofficeService
      Backoffice service.
  • Constructor Details

    • OtpService

      public OtpService()
  • Method Details

    • validateOnboardingOtpProcess

      public org.springframework.http.ResponseEntity<es.kukenan.smartfi.dto.ResponseDTO<Object>> validateOnboardingOtpProcess(String userId, String processId, es.kukenan.smartfi.dto.onboarding.OtpRequestDto otpRequestDto, String userAgent, String userIp, String product) throws NoSuchAlgorithmException
      Define if otp required is for SCA or OTP Generic Process depends otp cache content.
      Parameters:
      userId - unique user identifier.
      processId - otp cache unique identifier.
      otpRequestDto - data with otp.
      userAgent - user Agent.
      userIp - user Ip.
      product - Application product type.
      Returns:
      String With response of OTP process.
      Throws:
      NoSuchAlgorithmException - if algorithm not found..
    • validateOtpGenericProcess

      protected org.springframework.http.ResponseEntity<es.kukenan.smartfi.dto.ResponseDTO<Object>> validateOtpGenericProcess(String processId, OtpCache otpCache, es.kukenan.smartfi.dto.onboarding.OtpRequestDto otpRequestDto, boolean resumeTask, String userId, String userAgent, String userIp, String product) throws NoSuchAlgorithmException
      Generic OTP management process validate.
      Parameters:
      processId - unique identifier of otp process.
      otpCache - cache with otp data.
      otpRequestDto - otp data for check.
      resumeTask - flag to fire stored task execution.
      userId - user Id.
      userAgent - user Agent.
      userIp - user Ip.
      product - Application product type.
      Returns:
      Error if otp value checked is incorrect.
      Throws:
      NoSuchAlgorithmException - exception
    • setActiveUser

      public User setActiveUser(User user)
      Update State and Type to Active and Client for User.
      Parameters:
      user - User entity to change State and Type.
      Returns:
      updated User.
    • getOtpSessionCache

      public OtpCache getOtpSessionCache(String userId, String endpointVerb, String endpointPath, byte[] endpointBody, String generatedOtpValue, String deviceId, OtpConfiguration otpConfiguration, Map<String,String> headers)
      Get Otp session cache.
      Parameters:
      userId - unique user identifier.
      endpointVerb - verb of endpoint otp required.
      endpointPath - path of endpoint.
      endpointBody - body of endpoint otp required.
      generatedOtpValue - otp value for check.
      deviceId - device unique identifier.
      otpConfiguration - requested OTP additional configuration.
      headers - otp request headers.
      Returns:
      OtpCache for new otp
    • mapOtpGeneratedEvent

      public es.kukenan.smartfi.microservice.security.gateway.events.otp.OtpGeneratedEvent mapOtpGeneratedEvent(String userId, String otpValue, String deviceId, String operationType, Boolean ignorePrimaryChannel)
      Process response messages otp generated.
      Parameters:
      userId - user identification.
      otpValue - otp generated.
      deviceId - device unique identifier.
      operationType - Event operation type Otp generated.
      ignorePrimaryChannel - indicates if the primary channel should be ignored.
      Returns:
      OtpGeneratedEvent otp notification event info.
    • publishEvent

      public void publishEvent(es.kukenan.smartfi.microservice.security.gateway.events.AbstractSecurityGatewayEvent event)
      Process response messages.
      Parameters:
      event - AbstractSecurityGatewayEvent
    • blockUser

      protected void blockUser(OtpCache otpCache)
    • isOtpValid

      private boolean isOtpValid(OtpCache otpCache, String otpValue)
    • manageInvalidOtp

      private void manageInvalidOtp(String processId, OtpCache otpCache, String otpValue, es.kukenan.smartfi.dto.ResponseDTO<Object> responseDto, es.kukenan.smartfi.dto.BasicApiResponse result) throws NoSuchAlgorithmException
      Throws:
      NoSuchAlgorithmException
    • updateCounterOtpCacheForProcessId

      private void updateCounterOtpCacheForProcessId(String processId, OtpCache otpCache, es.kukenan.smartfi.dto.ResponseDTO<Object> responseDto, es.kukenan.smartfi.dto.BasicApiResponse result)
      Update otp counter for specific processId.
      Parameters:
      processId - unique otp process identifier.
      otpCache - otp cache information.
      responseDto - response object.
      result - basic response object.
    • checkOtpTimeToLiveExpired

      private boolean checkOtpTimeToLiveExpired(Timestamp ttlOtp)
      Check otp time to live is expired then return exception.
      Parameters:
      ttlOtp - time to live otp
      Returns:
      boolean false if time to live is not expired and exception if time to live is expired
    • regenerateOtpValueForProcessId

      private void regenerateOtpValueForProcessId(String processId, OtpCache otpCache, es.kukenan.smartfi.dto.ResponseDTO<Object> responseDto, es.kukenan.smartfi.dto.BasicApiResponse result) throws NoSuchAlgorithmException
      Regenerate otp value in resend cases.
      Parameters:
      processId - unique process identifier for otp.
      otpCache - otp cache data.
      responseDto - response object.
      result - basic response object.
      Throws:
      NoSuchAlgorithmException - exception.