java.lang.Object
es.kukenan.smartfi.microservice.security.gateway.service.OtpService

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

    • 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.
    • sessionCacheUtilities

      @Autowired private SessionCacheUtilities sessionCacheUtilities
      Session cache utilities for management.
    • jwtTokenUtilities

      @Autowired private JwtTokenUtilities jwtTokenUtilities
      Utilities for access and update session jwt token.
    • requestContextManager

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

      @Autowired private KafkaController kafkaController
      Kafka Controller.
    • otpCacheOperation

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

      @Autowired private com.fasterxml.jackson.databind.ObjectMapper objectMapper
      Custom object mapper.
  • Constructor Details

    • OtpService

      public OtpService()
  • Method Details

    • validateOtpProcess

      public org.springframework.http.ResponseEntity<byte[]> validateOtpProcess(String uuid, String processId, String otpValue, String userAgent, String userIp) throws NoSuchAlgorithmException
      Define if otp required is for SCA or OTP Generic Process depends otp cache content.
      Parameters:
      uuid - unique session cache identifier.
      processId - otp cache unique identifier.
      otpValue - value of otp.
      userAgent - user Agent.
      userIp - user Ip.
      Returns:
      String With response of OTP process.
      Throws:
      NoSuchAlgorithmException - if algorithm not found..
    • gellAllOtp

      public org.springframework.http.ResponseEntity<List<OtpCache>> gellAllOtp()
      Get All Otp.
      Returns:
      List all otp.
    • validateOtpGenericProcess

      protected org.springframework.http.ResponseEntity<byte[]> validateOtpGenericProcess(String processId, OtpCache otpCache, es.kukenan.smartfi.microservice.security.gateway.cache.model.SessionCache sessionCache, String otpValue, boolean resumeTask, String sessionId, String userAgent, String userIp) throws NoSuchAlgorithmException
      Generic OTP management process validate.
      Parameters:
      processId - unique identifier of otp process.
      otpCache - cache with otp data.
      sessionCache - cache qith user session data.
      otpValue - random otp value for check.
      resumeTask - flag to fire stored task execution.
      sessionId - session Id.
      userAgent - user Agent.
      userIp - user Ip.
      Returns:
      Error if otp value checked is incorrect.
      Throws:
      NoSuchAlgorithmException - exception
    • 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, String userIp, String userAgent)
      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.
      userIp - user IP Address.
      userAgent - user-agent header.
      Returns:
      OtpGeneratedEvent otp notification event info.
    • mapUserDeviceScaUpdatedEvent

      protected es.kukenan.smartfi.microservice.security.gateway.events.sca.UserDeviceScaUpdatedEvent mapUserDeviceScaUpdatedEvent(String userId, String deviceId)
      Process response messages sca updated event..
      Parameters:
      userId - user identification.
      deviceId - device unique identifier.
      Returns:
      UserDeviceScaUpdatedEvent UserDevice 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, String userIp, String userAgent) throws NoSuchAlgorithmException
      Throws:
      NoSuchAlgorithmException
    • updateCounterOtpCacheForProcessId

      private void updateCounterOtpCacheForProcessId(String processId, OtpCache otpCache)
      Update otp counter for specific processId.
      Parameters:
      processId - unique otp process identifier.
      otpCache - otp cache information.
    • 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, String userIp, String userAgent) throws NoSuchAlgorithmException
      Regenerate otp value in resend cases.
      Parameters:
      processId - unique process identifier for otp.
      otpCache - otp cache data.
      userIp - user Ip.
      userAgent - user Agent.
      Throws:
      NoSuchAlgorithmException - exception.
    • updateToScaSecurityLevel

      private void updateToScaSecurityLevel(es.kukenan.smartfi.microservice.security.gateway.cache.model.SessionCache sessionCache)
      Update security level to SCA for session jwt token.
      Parameters:
      sessionCache - session cache data.