Class: Merchantconfig

Inherits:
Object
  • Object
show all
Defined in:
lib/AuthenticationSDK/core/MerchantConfig.rb

Overview

This fuction has all the merchantConfig properties getters and setters methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cybsPropertyObj, responseMlePrivateKeyValue = nil, responseMlePrivateKeyPasswordValue = nil) ⇒ Merchantconfig

Returns a new instance of Merchantconfig.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 10

def initialize(cybsPropertyObj, responseMlePrivateKeyValue = nil, responseMlePrivateKeyPasswordValue = nil)
  # Common Parameters
  @merchantId = cybsPropertyObj['merchantID']
  @runEnvironment = cybsPropertyObj['runEnvironment']
  @intermediateHost = cybsPropertyObj['intermediateHost']
  @defaultDeveloperId = cybsPropertyObj['defaultDeveloperId']
  @authenticationType = cybsPropertyObj['authenticationType']
  @proxyAddress = cybsPropertyObj['proxyAddress']
  @proxyPort = cybsPropertyObj['proxyPort']
  @getId = ''
  @requestHost = ''
  @requestTarget = ''
  @requestJsonData = ''
  # HTTP Parameters
  @merchantSecretKey = cybsPropertyObj['merchantsecretKey']
  @merchantKeyId = cybsPropertyObj['merchantKeyId']
  # JWT Parameters
  @keysDirectory = cybsPropertyObj['keysDirectory']
  @keyAlias = cybsPropertyObj['keyAlias']
  @keyPass = cybsPropertyObj['keyPass']
  @keyFilename = cybsPropertyObj['keyFilename']
  @jwtKeyType = cybsPropertyObj['jwtKeyType'] ? cybsPropertyObj['jwtKeyType'].to_s.upcase : Constants::JWT_KEY_TYPE_P12
  @useMetaKey = cybsPropertyObj['useMetaKey']
  @portfolioID = cybsPropertyObj['portfolioID']
  @solutionId = cybsPropertyObj['solutionId']
  @isSDK = cybsPropertyObj['isSDK'] == true || cybsPropertyObj['isSDK'].to_s.strip.casecmp?('true')
  @p12KeyFilePath = nil
  # MutualAuth & OAuth Parameters
  @enableClientCert = cybsPropertyObj['enableClientCert']
  @clientCertDirectory = cybsPropertyObj['clientCertDirectory']
  @sslClientCert = cybsPropertyObj['sslClientCert']
  @privateKey = cybsPropertyObj['privateKey']
  @sslKeyPassword = cybsPropertyObj['sslKeyPassword']
  @clientId = cybsPropertyObj['clientId']
  @clientSecret = cybsPropertyObj['clientSecret']
  @accessToken = cybsPropertyObj['accessToken']
  @refreshToken = cybsPropertyObj['refreshToken']
  # LogConfiguration
  @log_config = LogConfiguration.new(cybsPropertyObj['logConfiguration'])
  # Custom Default Headers
  @defaultCustomHeaders = cybsPropertyObj['defaultCustomHeaders']
  # Keep Alive Time for Connection Pooling
  @keepAliveTime = cybsPropertyObj['keepAliveTime'] || 118 # Default to 118 seconds as same as default of libcurl
  # Path to client JWE pem file directory
  @pemFileDirectory = cybsPropertyObj['pemFileDirectory']

  # Optional parameter. User can pass a custom requestMleKeyAlias to fetch from the certificate.
  # Older flag "mleKeyAlias" is deprecated and will be used as alias/another name for requestMleKeyAlias.
  if cybsPropertyObj.has_key?('mleKeyAlias')
    @requestMleKeyAlias = cybsPropertyObj['mleKeyAlias']
  elsif cybsPropertyObj.has_key?('requestMleKeyAlias')
    @requestMleKeyAlias = cybsPropertyObj['requestMleKeyAlias']
  end

  # Deprecated flag to enable MLE for request. This flag is now known as "enableRequestMLEForOptionalApisGlobally"
  @useMLEGlobally = cybsPropertyObj['useMLEGlobally']

  # Flag to enable MLE (Message Level Encryption) for request body to all APIs in SDK which have optional support for MLE.
  # This means the API can send both non-encrypted and encrypted requests.
  # Older flag "useMLEGlobally" is deprecated and will be used as alias/another name for enableRequestMLEForOptionalApisGlobally.
  @enableRequestMLEForOptionalApisGlobally = !!(cybsPropertyObj['enableRequestMLEForOptionalApisGlobally'] || cybsPropertyObj['useMLEGlobally'])
  # Flag to disable MLE (Message Level Encryption) for request body to APIs in SDK which have mandatory MLE requirement when sending calls.
  @disableRequestMLEForMandatoryApisGlobally = cybsPropertyObj['disableRequestMLEForMandatoryApisGlobally']

  # Parameter to pass the request MLE public certificate path.
  if !cybsPropertyObj['mleForRequestPublicCertPath'].nil? && !cybsPropertyObj['mleForRequestPublicCertPath'].to_s.strip.empty?
      @mleForRequestPublicCertPath = cybsPropertyObj['mleForRequestPublicCertPath'].to_s.strip
  end

  # Map to control MLE (Message Level Encryption) settings for individual API functions. This overrides global MLE configuration for specific APIs.
  # The key is the function name of the API in the SDK, and the value is a String in the format "requestMLE::responseMLE" separated by "::",
  # where the first boolean value controls MLE for the request and the second boolean value controls MLE for the response.
  # Use "true" to enable or "false" to disable MLE for that specific component.

  # Valid Examples:
  # mapToControlMLEonAPI.put("apiFunctionName1", "true::true") - enables MLE for both request and response for apiFunctionName1
  # mapToControlMLEonAPI.put("apiFunctionName2", "false::false") - disables MLE for both request and response for apiFunctionName2
  # mapToControlMLEonAPI.put("apiFunctionName3", "true::false") - enables request MLE only, disables response MLE for apiFunctionName3
  # mapToControlMLEonAPI.put("apiFunctionName4", "false::true") - disables request MLE, enables response MLE only for apiFunctionName4
  # mapToControlMLEonAPI.put("apiFunctionName5", "false") - disables request MLE only. Since the "::" separator is not included, mleForResponse will use the default value set by the global flag
  # mapToControlMLEonAPI.put("apiFunctionName6", "true") - enables request MLE only. Since the "::" separator is not included, mleForResponse will use the default value set by the global flag
  # mapToControlMLEonAPI.put("apiFunctionName7", "::true") - enables response MLE only. Because the value before "::" is missing, the SDK will use the default request MLE value from the global flag
  # mapToControlMLEonAPI.put("apiFunctionName8", "true::") - enables request MLE only. Since the value after the "::" separator is missing, mleForResponse will use the default value

  # Invalid Examples (will be ignored or cause errors):
  # mapToControlMLEonAPI.put("apiFunctionName9", "::") - both values empty, will use global defaults
  # mapToControlMLEonAPI.put("apiFunctionName10", "invalid::true") - invalid first value, may cause parsing error
  # mapToControlMLEonAPI.put("apiFunctionName11", "true::invalid") - invalid second value, may cause parsing error
  # mapToControlMLEonAPI.put("apiFunctionName12", "true::true::false") - multiple separators not allowed
  # mapToControlMLEonAPI.put("apiFunctionName13", "") - empty string not allowed
  @mapToControlMLEonAPI = cybsPropertyObj['mapToControlMLEonAPI']

  # Initialize internal maps before validation
  # Both fields used for internal purpose only not exposed for merchants to set
  @internalMapToControlRequestMLEonAPI = {}
  @internalMapToControlResponseMLEonAPI = {}

  # Set up MLE configuration first since validation depends on it
  if @mapToControlMLEonAPI
    begin
      @mapToControlMLEonAPI = convertBooleanToStringMapType(@mapToControlMLEonAPI)
      setMapToControlMLEOnAPI(@mapToControlMLEonAPI)
    rescue => err
      error = StandardError.new(Constants::WARNING_PREFIX + "Unable to initialise MLE control Map from config: #{err.message}")
      raise error
    end
  end

  if responseMlePrivateKeyPasswordValue.nil?
    responseMlePrivateKeyPasswordValue = cybsPropertyObj['responseMlePrivateKeyPassword']
  end

  responseMlePrivateKeyPassword = responseMlePrivateKeyPasswordValue

  if !responseMlePrivateKeyValue.nil? && !cybsPropertyObj['responseMlePrivateKey'].nil?
    raise StandardError.new(Constants::ERROR_PREFIX + "The value for `responseMlePrivateKey` is provided in both the configuration object and the constructor for MerchantConfig. Please provide only one of them for response mle private key.")
  end

  if responseMlePrivateKeyValue.nil?
    responseMlePrivateKeyValue = cybsPropertyObj['responseMlePrivateKey']
  end

  responseMlePrivateKeyValue = CertificateUtility.convert_key_to_JWK(responseMlePrivateKeyValue, responseMlePrivateKeyPassword)

  @responseMlePrivateKey = responseMlePrivateKeyValue

  @enableResponseMleGlobally = false
  if !cybsPropertyObj['enableResponseMleGlobally'].nil?
    @enableResponseMleGlobally = cybsPropertyObj['enableResponseMleGlobally']
  end

  @responseMleKID = cybsPropertyObj['responseMleKID']
  @responseMlePrivateKeyFilePath = cybsPropertyObj['responseMlePrivateKeyFilePath']
  @responseMlePrivateKeyFilePassword = cybsPropertyObj['responseMlePrivateKeyFilePassword']

  validateMerchantDetails()
  validateMLEConfiguration(cybsPropertyObj)
  if !@keysDirectory.nil? && !@keysDirectory.to_s.empty? && !@keyFilename.nil? && !@keyFilename.to_s.empty?
    @p12KeyFilePath = File.join(@keysDirectory, @keyFilename + ".p12")
  end
  logAllProperties(cybsPropertyObj)
end

Instance Attribute Details

#accessTokenObject

Returns the value of attribute accessToken.



675
676
677
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 675

def accessToken
  @accessToken
end

#authenticationTypeObject

Returns the value of attribute authenticationType.



656
657
658
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 656

def authenticationType
  @authenticationType
end

#clientCertDirectoryObject

Returns the value of attribute clientCertDirectory.



669
670
671
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 669

def clientCertDirectory
  @clientCertDirectory
end

#clientIdObject

Returns the value of attribute clientId.



673
674
675
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 673

def clientId
  @clientId
end

#clientSecretObject

Returns the value of attribute clientSecret.



674
675
676
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 674

def clientSecret
  @clientSecret
end

#defaultCustomHeadersObject

Returns the value of attribute defaultCustomHeaders.



689
690
691
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 689

def defaultCustomHeaders
  @defaultCustomHeaders
end

#defaultDeveloperIdObject

Returns the value of attribute defaultDeveloperId.



660
661
662
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 660

def defaultDeveloperId
  @defaultDeveloperId
end

#disableRequestMLEForMandatoryApisGloballyObject

Returns the value of attribute disableRequestMLEForMandatoryApisGlobally.



693
694
695
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 693

def disableRequestMLEForMandatoryApisGlobally
  @disableRequestMLEForMandatoryApisGlobally
end

#enableClientCertObject

Returns the value of attribute enableClientCert.



668
669
670
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 668

def enableClientCert
  @enableClientCert
end

#enableRequestMLEForOptionalApisGloballyObject

Returns the value of attribute enableRequestMLEForOptionalApisGlobally.



692
693
694
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 692

def enableRequestMLEForOptionalApisGlobally
  @enableRequestMLEForOptionalApisGlobally
end

#enableResponseMleGloballyObject

Returns the value of attribute enableResponseMleGlobally.



700
701
702
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 700

def enableResponseMleGlobally
  @enableResponseMleGlobally
end

#getIdObject

Returns the value of attribute getId.



680
681
682
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 680

def getId
  @getId
end

#intermediateHostObject

Returns the value of attribute intermediateHost.



659
660
661
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 659

def intermediateHost
  @intermediateHost
end

#internalMapToControlRequestMLEonAPIObject

Returns the value of attribute internalMapToControlRequestMLEonAPI.



706
707
708
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 706

def internalMapToControlRequestMLEonAPI
  @internalMapToControlRequestMLEonAPI
end

#internalMapToControlResponseMLEonAPIObject

Returns the value of attribute internalMapToControlResponseMLEonAPI.



707
708
709
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 707

def internalMapToControlResponseMLEonAPI
  @internalMapToControlResponseMLEonAPI
end

#isSDKObject

Returns the value of attribute isSDK.



688
689
690
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 688

def isSDK
  @isSDK
end

#jwtKeyTypeObject

Returns the value of attribute jwtKeyType.



664
665
666
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 664

def jwtKeyType
  @jwtKeyType
end

#keepAliveTimeObject

Returns the value of attribute keepAliveTime.



667
668
669
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 667

def keepAliveTime
  @keepAliveTime
end

#keyAliasObject

Returns the value of attribute keyAlias.



661
662
663
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 661

def keyAlias
  @keyAlias
end

#keyFilenameObject

Returns the value of attribute keyFilename.



663
664
665
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 663

def keyFilename
  @keyFilename
end

#keyPassObject

Returns the value of attribute keyPass.



662
663
664
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 662

def keyPass
  @keyPass
end

#keysDirectoryObject

Returns the value of attribute keysDirectory.



657
658
659
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 657

def keysDirectory
  @keysDirectory
end

#log_configObject

Returns the value of attribute log_config.



682
683
684
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 682

def log_config
  @log_config
end

#log_objObject

Returns the value of attribute log_obj.



686
687
688
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 686

def log_obj
  @log_obj
end

#loggerObject

Returns the value of attribute logger.



681
682
683
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 681

def logger
  @logger
end

#mapToControlMLEonAPIObject

Returns the value of attribute mapToControlMLEonAPI.



695
696
697
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 695

def mapToControlMLEonAPI
  @mapToControlMLEonAPI
end

#merchantIdObject

getter and setter methods



653
654
655
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 653

def merchantId
  @merchantId
end

#merchantKeyIdObject

Returns the value of attribute merchantKeyId.



655
656
657
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 655

def merchantKeyId
  @merchantKeyId
end

#merchantSecretKeyObject

Returns the value of attribute merchantSecretKey.



654
655
656
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 654

def merchantSecretKey
  @merchantSecretKey
end

#mleForRequestPublicCertPathObject

Returns the value of attribute mleForRequestPublicCertPath.



694
695
696
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 694

def mleForRequestPublicCertPath
  @mleForRequestPublicCertPath
end

#mleKeyAliasObject

Returns the value of attribute mleKeyAlias.



696
697
698
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 696

def mleKeyAlias
  @mleKeyAlias
end

#p12KeyFilePathObject

Returns the value of attribute p12KeyFilePath.



698
699
700
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 698

def p12KeyFilePath
  @p12KeyFilePath
end

#pemFileDirectoryObject

Returns the value of attribute pemFileDirectory.



690
691
692
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 690

def pemFileDirectory
  @pemFileDirectory
end

#portfolioIDObject

Returns the value of attribute portfolioID.



666
667
668
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 666

def portfolioID
  @portfolioID
end

#privateKeyObject

Returns the value of attribute privateKey.



672
673
674
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 672

def privateKey
  @privateKey
end

#proxyAddressObject

Returns the value of attribute proxyAddress.



683
684
685
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 683

def proxyAddress
  @proxyAddress
end

#proxyPortObject

Returns the value of attribute proxyPort.



684
685
686
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 684

def proxyPort
  @proxyPort
end

#refreshTokenObject

Returns the value of attribute refreshToken.



676
677
678
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 676

def refreshToken
  @refreshToken
end

#requestHostObject

Returns the value of attribute requestHost.



658
659
660
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 658

def requestHost
  @requestHost
end

#requestJsonDataObject

Returns the value of attribute requestJsonData.



677
678
679
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 677

def requestJsonData
  @requestJsonData
end

#requestMleKeyAliasObject

Returns the value of attribute requestMleKeyAlias.



697
698
699
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 697

def requestMleKeyAlias
  @requestMleKeyAlias
end

#requestTargetObject

Returns the value of attribute requestTarget.



685
686
687
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 685

def requestTarget
  @requestTarget
end

#requestTypeObject

Returns the value of attribute requestType.



679
680
681
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 679

def requestType
  @requestType
end

#requestUrlObject

Returns the value of attribute requestUrl.



678
679
680
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 678

def requestUrl
  @requestUrl
end

#responseMleKIDObject

Returns the value of attribute responseMleKID.



701
702
703
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 701

def responseMleKID
  @responseMleKID
end

#responseMlePrivateKeyObject

Returns the value of attribute responseMlePrivateKey.



704
705
706
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 704

def responseMlePrivateKey
  @responseMlePrivateKey
end

#responseMlePrivateKeyFilePasswordObject

Returns the value of attribute responseMlePrivateKeyFilePassword.



703
704
705
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 703

def responseMlePrivateKeyFilePassword
  @responseMlePrivateKeyFilePassword
end

#responseMlePrivateKeyFilePathObject

Returns the value of attribute responseMlePrivateKeyFilePath.



702
703
704
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 702

def responseMlePrivateKeyFilePath
  @responseMlePrivateKeyFilePath
end

#responseMlePrivateKeyPasswordObject

Returns the value of attribute responseMlePrivateKeyPassword.



705
706
707
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 705

def responseMlePrivateKeyPassword
  @responseMlePrivateKeyPassword
end

#runEnvironmentObject (readonly)

Returns the value of attribute runEnvironment.



699
700
701
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 699

def runEnvironment
  @runEnvironment
end

#solutionIdObject

Returns the value of attribute solutionId.



687
688
689
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 687

def solutionId
  @solutionId
end

#sslClientCertObject

Returns the value of attribute sslClientCert.



670
671
672
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 670

def sslClientCert
  @sslClientCert
end

#sslKeyPasswordObject

Returns the value of attribute sslKeyPassword.



671
672
673
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 671

def sslKeyPassword
  @sslKeyPassword
end

#useMetaKeyObject

Returns the value of attribute useMetaKey.



665
666
667
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 665

def useMetaKey
  @useMetaKey
end

#useMLEGloballyObject

Returns the value of attribute useMLEGlobally.



691
692
693
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 691

def useMLEGlobally
  @useMLEGlobally
end

Instance Method Details

#check_jwt_key_typeObject

Validates that jwtKeyType is either P12 or SHARED_SECRET



615
616
617
618
619
620
621
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 615

def check_jwt_key_type
  unless @jwtKeyType.upcase == Constants::JWT_KEY_TYPE_P12 || @jwtKeyType.upcase == Constants::JWT_KEY_TYPE_SHARED_SECRET
    err = StandardError.new(Constants::ERROR_PREFIX + Constants::INVALID_JWT_KEY_TYPE)
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  end
end

#check_key_fileObject



623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 623

def check_key_file
  # Directory exists?
  unless Dir.exist?(@keysDirectory)
    @log_obj.logger.error("Keys Directory not found. Entered directory : #{@keysDirectory}")
    return false
  end

  key_file_pathname = File.join(@keysDirectory, @keyFilename + ".p12")

  # File exists?
  unless File.exist?(key_file_pathname)
    @log_obj.logger.error("Key File not found. Check path/filename entered. Entered path/filename : #{key_file_pathname}")
    return false
  end

  @log_obj.logger.info("Entered value for Key File Path : #{key_file_pathname}")

  # Can file be opened for reading?
  begin
    File.open(key_file_pathname, 'rb') do |f|
      # Just open and close
    end
    return true
  rescue => e
    @log_obj.logger.info("File cannot be accessed. Permission denied : #{key_file_pathname}")
    return false
  end
end

#convertBooleanToStringMapType(inputMap) ⇒ Object



565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 565

def convertBooleanToStringMapType(inputMap)
  if inputMap.nil? || inputMap.empty?
    raise StandardError.new(Constants::ERROR_PREFIX + "Unsupported null value to mapToControlMLEonAPI in merchantConfig. Expected Map<String, String> which corresponds to <'apiFunctionName','flagForRequestMLE::flagForResponseMLE'> as dataType for field.")
  end

  unless inputMap.is_a?(Hash)
    raise TypeError.new(Constants::ERROR_PREFIX + "Unsupported datatype for field mapToControlMLEonAPI. Expected Hash<String, String> which corresponds to <'apiFunctionName','flagForRequestMLE::flagForResponseMLE'> as dataType for field but got: #{inputMap.class}")
  end

  keys_all_strings   = inputMap.keys.all? { |k| k.is_a?(String) }
  values_all_strings = inputMap.values.all? { |v| v.is_a?(String) }
  values_all_bools   = inputMap.values.all? { |v| v.is_a?(TrueClass) || v.is_a?(FalseClass) }

  if keys_all_strings && values_all_strings
    # Already Hash<String, String>
    inputMap
  elsif keys_all_strings && values_all_bools
    # Convert Hash<String, Boolean> -> Hash<String, String>
    inputMap.transform_values { |v| v.to_s }
  else
    err = StandardError.new("Unsupported map type combination for mapToControlMLEonAPI in merchantConfig. Expected Hash<String, String> which corresponds to <'apiFunctionName','flagForRequestMLE::flagForResponseMLE'> as dataType for field.")
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  end
end

#is_shared_secret_key_type?Boolean

Returns true when jwtKeyType is SHARED_SECRET

Returns:

  • (Boolean)


610
611
612
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 610

def is_shared_secret_key_type?
  !@jwtKeyType.nil? && @jwtKeyType.upcase == Constants::JWT_KEY_TYPE_SHARED_SECRET
end

#isValidBooleanString?(s) ⇒ Boolean

Returns:

  • (Boolean)


561
562
563
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 561

def isValidBooleanString?(s)
  s.casecmp?("true") || s.casecmp?("false")
end

#logAllProperties(merchantPropertyObj) ⇒ Object



591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 591

def logAllProperties(merchantPropertyObj)
  propertyObj = Marshal.load(Marshal.dump(merchantPropertyObj))
  merchantConfig = ''
  hiddenProperties = (Constants::HIDDEN_MERCHANT_PROPERTIES).split(',')
  hiddenPropArray = Array.new
  hiddenProperties.each do |value|
    hiddenPropArray << value.strip
  end
  hiddenPropArray.each do |prop|
    propertyObj.each do |key, value|
      if key == prop
        propertyObj.delete(key)
      end
    end
  end
  @log_obj.logger.info('Merchant Configuration :\n' + propertyObj.to_s)
end

#setMapToControlMLEOnAPI(inputMap) ⇒ Object



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 481

def setMapToControlMLEOnAPI(inputMap)
  # validate the map value format
  validateMapToControlMLEonAPIValues(inputMap) if inputMap

  # @mapToControlMLEonAPI = inputMap

  if inputMap
    internalRequest = {}
    internalResponse = {}

    inputMap.each do |apiName, rawValue|
      value = rawValue.to_s

      if value.include?("::")
        # Format: "requestMLE::responseMLE"
        requestMLE, responseMLE = value.split("::", 2)

        # Set request MLE value when present
        unless requestMLE.nil? || requestMLE.empty?
          internalRequest[apiName] = requestMLE.to_s.strip.casecmp?("true")
        end

        # Set response MLE value when present
        unless responseMLE.nil? || responseMLE.empty?
          internalResponse[apiName] = responseMLE.to_s.strip.casecmp?("true")
        end
      else
        # Format: "true" or "false" - applies to request MLE only
        internalRequest[apiName] = value.to_s.strip.casecmp?("true")
      end
    end

    @internalMapToControlRequestMLEonAPI = internalRequest
    @internalMapToControlResponseMLEonAPI = internalResponse
  end
end

#validateMapToControlMLEonAPIValues(inputMap) ⇒ Object

Validates the map values for MLE control API configuration. Allowed formats: “true::true”, “false::false”, “::true”, “true::”, “::false”, “false::”, “true”, “false”



520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 520

def validateMapToControlMLEonAPIValues(inputMap)
  inputMap.each do |key, value|
    if value.nil? || value == ""
      err = StandardError.new(Constants::ERROR_PREFIX + "Invalid MLE control map value for key '#{key}'. Value cannot be null or empty.")
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    end

    str = value.to_s
    if str.include?("::")
      parts = str.split("::", -1)

      unless parts.length == 2
        err = StandardError.new(Constants::ERROR_PREFIX + "Invalid MLE control map value format for key '#{key}'. Expected format: true/false for 'requestMLE::responseMLE' but got: '#{str}'")
        @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
        raise err
      end

      requestMLE, responseMLE = parts

      if !requestMLE.empty? && !isValidBooleanString?(requestMLE)
        err = StandardError.new(Constants::ERROR_PREFIX + "Invalid request MLE value for key '#{key}'. Expected 'true', 'false', or empty but got: '#{requestMLE}'")
        @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
        raise err
      end

      if !responseMLE.empty? && !isValidBooleanString?(responseMLE)
        err = StandardError.new(Constants::ERROR_PREFIX + "Invalid response MLE value for key '#{key}'. Expected 'true', 'false', or empty but got: '#{responseMLE}'")
        @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
        raise err
      end
    else
      unless isValidBooleanString?(str)
        err = StandardError.new(Constants::ERROR_PREFIX + "Invalid MLE control map value for key '#{key}'. Expected 'true' or 'false' for requestMLE but got: '#{str}'")
        @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
        raise err
      end
    end
  end
end

#validateMerchantDetailsObject

fall back logic



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 154

def validateMerchantDetails()
  if !@keepAliveTime.is_a?(Integer)
    err = StandardError.new(Constants::ERROR_PREFIX + "keepAliveTime must be an integer and in seconds")
    raise err
  end
  
  logmessage = ''
  @log_config.validate(logmessage)
  @log_obj = Log.new @log_config, "MerchantConfig"
  @log_obj.logger.info('START> =======================================')
  if !logmessage.to_s.empty?
    @log_obj.logger.warn(ExceptionHandler.new.new_api_warning logmessage)
  end
  if @authenticationType.to_s.empty?
    err = StandardError.new(Constants::ERROR_PREFIX + Constants::AUTH_TYPE_MANDATORY)
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  end
  if !@authenticationType.instance_of? String
    err = StandardError.new(Constants::ERROR_PREFIX+ Constants::AUTH_ERROR)
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  end
  if !@runEnvironment.to_s.empty?
    if !@runEnvironment.instance_of? String
      @requestHost = @runEnvironment.to_s
    end

    if Constants::OLD_RUN_ENVIRONMENT_CONSTANTS.include?(@runEnvironment.upcase)
      err = StandardError.new(Constants::ERROR_PREFIX + Constants::DEPRECATED_ENVIRONMENT)
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    else
      @requestHost = @runEnvironment
    end
  elsif @runEnvironment.to_s.empty?
    err = StandardError.new(Constants::ERROR_PREFIX + Constants::RUN_ENVIRONMENT)
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  end

  if !@enableClientCert.nil? && @enableClientCert
    if @sslClientCert.to_s.empty?
      err = StandardError.new(Constants::ERROR_PREFIX + Constants::SSL_CLIENT_CERT_EMPTY)
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    elsif !@sslClientCert.instance_of? String
      @sslClientCert=@sslClientCert.to_s
    end
    if @privateKey.to_s.empty?
      err = StandardError.new(Constants::ERROR_PREFIX + Constants::PRIVATE_KEY_EMPTY)
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    elsif !@privateKey.instance_of? String
      @privateKey=@privateKey.to_s
    end
    if @sslKeyPassword.to_s.empty?
      err = Constants::WARNING_PREFIX + Constants::SSL_KEY_PASSWORD_EMPTY
      @log_obj.logger.warn(ExceptionHandler.new.new_api_warning err)
      raise err
    elsif !@sslKeyPassword.instance_of? String
      @sslKeyPassword=@sslKeyPassword.to_s
    end
    if @clientCertDirectory.to_s.empty?
      err = StandardError.new(Constants::ERROR_PREFIX + Constants::CLIENT_CERT_DIR_EMPTY)
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    elsif !@clientCertDirectory.instance_of? String
      @clientCertDirectory=@clientCertDirectory.to_s
    end
  end

  if @authenticationType.upcase == Constants::AUTH_TYPE_JWT
    if @merchantId.to_s.empty?
      err = StandardError.new(Constants::ERROR_PREFIX + Constants::MERCHANT_ID_NULL)
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    elsif !@merchantId.instance_of? String
      @merchantId=@merchantId.to_s
    end

    # Validate jwtKeyType
    check_jwt_key_type

    if is_shared_secret_key_type?
      # Shared Secret validation — same credentials as HTTP_SIGNATURE
      validateSharedSecretKeyCredentials()
    else
      # P12 validation (existing behavior)
      if @keyAlias.to_s.empty?
        @keyAlias = @merchantId
        @log_obj.logger.warn(ExceptionHandler.new.new_api_warning Constants::WARNING_PREFIX + Constants::KEY_ALIAS_NULL_EMPTY)
      elsif !@keyAlias.instance_of? String
        @keyAlias=@keyAlias.to_s
      end
      if !@useMetaKey && @keyAlias != @merchantId
        @keyAlias = @merchantId
        @log_obj.logger.warn(ExceptionHandler.new.new_api_warning Constants::WARNING_PREFIX + Constants::INCORRECT_KEY_ALIAS)
      end
      if @useMetaKey && @keyAlias != @portfolioID
        @keyAlias = @portfolioID
        @log_obj.logger.warn(ExceptionHandler.new.new_api_warning Constants::WARNING_PREFIX + Constants::INCORRECT_KEY_ALIAS_USE_METAKEY)
      end
      if @keyPass.to_s.empty?
        @keyPass = @merchantId
        @log_obj.logger.warn(ExceptionHandler.new.new_api_warning Constants::WARNING_PREFIX + Constants::KEY_PASS_NULL)
      elsif !@keyPass.instance_of? String
        @keyPass=@keyPass.to_s
      end
      if @keysDirectory.to_s.empty?
        @keysDirectory = Constants::DEFAULT_KEY_DIRECTORY
        @log_obj.logger.warn(ExceptionHandler.new.new_api_warning Constants::WARNING_PREFIX + Constants::KEY_DIRECTORY_EMPTY + @keysDirectory)
      elsif !@keysDirectory.instance_of? String
        @keysDirectory=@keysDirectory.to_s
      end
      if @keyFilename.to_s.empty?
        @keyFilename = @merchantId
        @log_obj.logger.warn(ExceptionHandler.new.new_api_warning Constants::WARNING_PREFIX + Constants::KEY_FILE_NAME_NULL_EMPTY)
      elsif !@keyFilename.instance_of? String
        @keyFilename=@keyFilename.to_s
      end
      if !check_key_file
        err = StandardError.new(Constants::ERROR_PREFIX + "Cannot find or access the Key Directory or Key File. Please review the values in the merchant configuration.")
        @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
        raise err
      end
    end
  end
  if @authenticationType.upcase == Constants::AUTH_TYPE_MUTUAL_AUTH
    if @clientId.to_s.empty?
      err = StandardError.new(Constants::ERROR_PREFIX + Constants::CLIENT_ID_EMPTY)
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    elsif !@clientId.instance_of? String
      @clientId=@clientId.to_s
    end
    if @clientSecret.to_s.empty?
      err = StandardError.new(Constants::ERROR_PREFIX + Constants::CLIENT_SECRET_EMPTY)
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    elsif !@clientSecret.instance_of? String
      @clientSecret=@clientSecret.to_s
    end
  end
  if @authenticationType.upcase == Constants::AUTH_TYPE_OAUTH
    if @accessToken.to_s.empty?
      err = StandardError.new(Constants::ERROR_PREFIX + Constants::ACCESS_TOKEN_EMPTY)
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    elsif !@accessToken.instance_of? String
      @accessToken=@accessToken.to_s
    end
    if @refreshToken.to_s.empty?
      err = StandardError.new(Constants::ERROR_PREFIX + Constants::REFRESH_TOKEN_EMPTY)
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    elsif !@refreshToken.instance_of? String
      @refreshToken=@refreshToken.to_s
    end
  end
  if @authenticationType.upcase == Constants::AUTH_TYPE_HTTP
    if @merchantId.to_s.empty?
      err = StandardError.new(Constants::ERROR_PREFIX + Constants::MERCHANT_ID_NULL)
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    elsif !@merchantId.instance_of? String
      @merchantId=@merchantId.to_s
    end
    validateSharedSecretKeyCredentials()
  end
  if @useMetaKey && @portfolioID.to_s.empty?
    err = StandardError.new(Constants::ERROR_PREFIX+ Constants::PORTFOLIO_ID_MANDATORY)
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  end

  if !@proxyAddress.instance_of? String
    @proxyAddress=@proxyAddress.to_s
  end
  if !@proxyPort.instance_of? String
    @proxyPort=@proxyPort.to_s
  end
  unless @pemFileDirectory.instance_of? String
    @pemFileDirectory = @pemFileDirectory.to_s
  end
end

#validateMLEConfiguration(cybsPropertyObj) ⇒ Object



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 358

def validateMLEConfiguration(cybsPropertyObj)
  if !@useMLEGlobally.nil? && !cybsPropertyObj['enableRequestMLEForOptionalApisGlobally'].nil?
    if @useMLEGlobally != cybsPropertyObj['enableRequestMLEForOptionalApisGlobally']
      raise StandardError.new(Constants::ERROR_PREFIX + "useMLEGlobally and enableRequestMLEForOptionalApisGlobally must have the same value if both are set")
    end
  end

  if @disableRequestMLEForMandatoryApisGlobally.nil?
    @disableRequestMLEForMandatoryApisGlobally = false
  end

  unless [true, false].include?(@disableRequestMLEForMandatoryApisGlobally)
    err = StandardError.new(Constants::ERROR_PREFIX + "disableRequestMLEForMandatoryApisGlobally must be a boolean")
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  end

  unless [true, false].include?(@enableRequestMLEForOptionalApisGlobally)
    err = StandardError.new(Constants::ERROR_PREFIX + "enableRequestMLEForOptionalApisGlobally must be a boolean")
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  end

    # unless @mapToControlMLEonAPI.is_a?(Hash) && @mapToControlMLEonAPI.keys.all? {|k| k.is_a?(String)} && @mapToControlMLEonAPI.values.all? { |v| [true, false].include?(v) }
    #   err = StandardError.new(Constants::ERROR_PREFIX + "mapToControlMLEonAPI must be a map with boolean values")
    #   @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    #   raise err
    # end

  !@requestMleKeyAlias.nil? && unless @requestMleKeyAlias.instance_of? String
    err = StandardError.new(Constants::ERROR_PREFIX + "requestMleKeyAlias must be a string")
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  end
  if @requestMleKeyAlias.to_s.empty?
    @requestMleKeyAlias = Constants::DEFAULT_ALIAS_FOR_MLE_CERT
  end

  if @mleForRequestPublicCertPath && !@mleForRequestPublicCertPath.to_s.strip.empty?
    begin
      CertificateUtility.validatePathAndFile(@mleForRequestPublicCertPath, "mleForRequestPublicCertPath", @log_config)
    rescue => err
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    end
  end

  request_mle_configured = @enableRequestMLEForOptionalApisGlobally
  if !@internalMapToControlRequestMLEonAPI.nil? && !@internalMapToControlRequestMLEonAPI.empty?
    @internalMapToControlRequestMLEonAPI.each do |_, value|
      if value
        request_mle_configured = true
        break
      end
    end
  end

  if request_mle_configured && !Constants::AUTH_TYPE_JWT.eql?(@authenticationType.upcase)
    err = StandardError.new(Constants::ERROR_PREFIX + "Request MLE can only be used with JWT authentication")
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  end

  is_response_mle_configured = @enableResponseMleGlobally

  if !@internalMapToControlResponseMLEonAPI.nil? && !@internalMapToControlResponseMLEonAPI.empty?
    @internalMapToControlResponseMLEonAPI.values.each do |value|
      if value == true
        is_response_mle_configured = true
        break
      end
    end
  end

  if is_response_mle_configured
    # Validate for Auth type- Currently responseMLE feature will be enabled for JWT auth type only
    if !Constants::AUTH_TYPE_JWT.eql?(@authenticationType.upcase)
      err = StandardError.new(Constants::ERROR_PREFIX + "Response MLE can only be used with JWT authentication type")
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    end

    # Check if either private key object or private key file path is provided
    if @responseMlePrivateKey.nil? || @responseMlePrivateKey.to_s.strip.empty?
      if @responseMlePrivateKeyFilePath.nil? || @responseMlePrivateKeyFilePath.to_s.strip.empty?
        err = StandardError.new(Constants::ERROR_PREFIX + "Response MLE is enabled but no private key provided. Either set responseMlePrivateKey object or provide responseMlePrivateKeyFilePath.")
        @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
        raise err
      end
    end

    # Check that both private key object or private key file path should not be provided
    if !@responseMlePrivateKey.nil? && !@responseMlePrivateKey.to_s.strip.empty? && !@responseMlePrivateKeyFilePath.nil? && !@responseMlePrivateKeyFilePath.to_s.strip.empty?
        err = StandardError.new(Constants::ERROR_PREFIX + "Both responseMlePrivateKey object and responseMlePrivateKeyFilePath are provided. Please provide only one of them for response mle private key.")
        @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
        raise err
    end

    isP12 = false
    # If private key file path is provided, validate the file exists
    if !@responseMlePrivateKeyFilePath.nil? && !@responseMlePrivateKeyFilePath.to_s.strip.empty?
      begin
        CertificateUtility.validatePathAndFile(@responseMlePrivateKeyFilePath, "responseMlePrivateKeyFilePath", @log_config)
        ext = File.extname(@responseMlePrivateKeyFilePath).downcase
        if ext == '.p12' || ext == '.pfx'
          isP12 = true
        end
      rescue => err
        error = StandardError.new(Constants::ERROR_PREFIX + "Invalid responseMlePrivateKeyFilePath : #{err.message}")
        @log_obj.logger.error(ExceptionHandler.new.new_api_exception error)
        raise error
      end
    end

    # Validate responseMleKID is provided when response MLE is enabled
    if !isP12 && (@responseMleKID.nil? || @responseMleKID.to_s.strip.empty?)
      err = StandardError.new(Constants::ERROR_PREFIX + "responseMleKID is required when response MLE is enabled for non-P12/PFX files.")
      @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
      raise err
    end
  end
end

#validateSharedSecretKeyCredentialsObject



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/AuthenticationSDK/core/MerchantConfig.rb', line 341

def validateSharedSecretKeyCredentials()
  if @merchantKeyId.to_s.empty?
    err = StandardError.new(Constants::ERROR_PREFIX+ Constants::MERCHANT_KEY_ID_MANDATORY)
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  elsif !@merchantKeyId.instance_of? String
    @merchantKeyId=@merchantKeyId.to_s
  end
  if @merchantSecretKey.to_s.empty?
    err = StandardError.new(Constants::ERROR_PREFIX+ Constants::MERCHANT_SECRET_KEY_MANDATORY)
    @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
    raise err
  elsif !@merchantSecretKey.instance_of? String
    @merchantSecretKey=@merchantSecretKey.to_s
  end
end