java.lang.Object
es.kukenan.smartfi.microservice.security.gateway.utils.OtpUtilities

@Service public class OtpUtilities extends Object
Service utilities class for OTP operations.
  • Field Details

    • codeLength

      @Value("${opt.generated.code.length}") private int codeLength
      length for otp.
    • restTemplate

      @Autowired @Qualifier("internalRestTemplate") private org.springframework.web.client.RestTemplate restTemplate
      Rest template instance for internal request.
    • otpCacheOperation

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

      @Autowired(required=false) private es.kukenan.smartfi.common.utils.otp.TotpGenerator totpGenerator
      TOTP generator, if one is configured.
  • Constructor Details

    • OtpUtilities

      public OtpUtilities()
  • Method Details

    • generateOtp

      public String generateOtp() throws NoSuchAlgorithmException
      Generates a random OTP. NativePRNG is used as algorithm for generating a secure random. Read all about the algorithms here: http://www.moi.vonos .net/java/securerandom/ and http
      Returns:
      the generated OTP
      Throws:
      NoSuchAlgorithmException - exception.
    • manageOtpCacheForProcessId

      public void manageOtpCacheForProcessId(String processId, SessionCacheOperationEnum sessionCacheOperationEnum, OtpCache otpCache)
      Manage specific operation otp cache process.
      Parameters:
      processId - unique otp process identifier.
      sessionCacheOperationEnum - Type of operation in cache.
      otpCache - Otp cache object for operation.
    • doRequestToInternalServices

      public org.springframework.http.ResponseEntity<byte[]> doRequestToInternalServices(String method, String path, byte[] body, String otpHeaderValue, String jwtToken, Map<String,String> headers)
      Generate rest template for correct checked otp.
      Parameters:
      method - method of correct otp request.
      path - path of correct otp request.
      body - body of correct otp request.
      otpHeaderValue - otp header value of otp.
      jwtToken - Jwt token in session cache.
      headers - http headers for internal request.
      Returns:
      ResponseEntity with response data.
    • addHeadersForInternalRequest

      private org.springframework.http.HttpHeaders addHeadersForInternalRequest(String otpHeaderValue, String jwtToken, Map<String,String> headersMap)
      Add headers needed to do internal request.
      Parameters:
      otpHeaderValue - value for OtpFilter.
      jwtToken - Token for private type internal services.
      headersMap - Map with request header for endpoint saves in otp.
      Returns:
      headers needed for internal request.