44use Jose \Component \KeyManagement \JWKFactory ;
55use CyberSource \Authentication \Util \GlobalParameter as GlobalParameter ;
66use CyberSource \Authentication \Core \AuthException as AuthException ;
7+ use CyberSource \Logging \LogFactory as LogFactory ;
78
89class Cache
910{
1011 private static $ file_cache = array ();
12+ private static $ logger = null ;
13+
1114
1215 public function __construct ()
1316 {
14-
17+ if (self ::$ logger === null ) {
18+ self ::$ logger = (new LogFactory ())->getLogger (\CyberSource \Utilities \Helpers \ClassHelper::getClassName (get_class ($ this )), new \CyberSource \Logging \LogConfiguration ());
19+ }
1520 }
1621
1722 public function updateCache ($ filePath , $ merchantConfig )
@@ -20,8 +25,15 @@ public function updateCache($filePath, $merchantConfig)
2025 $ fileModTime = filemtime ($ filePath );
2126 $ keyPass = $ merchantConfig ->getKeyPassword ();
2227 $ cacheKey = $ fileName . '_ ' . "jwt " ;
28+ $ certStore = null ;
29+ if (file_exists ($ filePath )) {
30+ $ certStore = file_get_contents ($ filePath );
31+ } else {
32+ $ exception = new AuthException (GlobalParameter::KEY_FILE_INCORRECT , 0 );
33+ self ::$ logger ->error ("AuthException : " . GlobalParameter::KEY_FILE_INCORRECT );
34+ throw $ exception ;
35+ }
2336
24- $ certStore = file_get_contents ($ filePath );
2537 $ privateKey = null ;
2638 $ publicKey = null ;
2739 $ mleCert = null ;
@@ -34,6 +46,10 @@ public function updateCache($filePath, $merchantConfig)
3446 }
3547 $ publicKey = Utility::findCertByAlias ($ certs , $ keyAlias );
3648 $ publicKey = $ this ->PemToDer ($ publicKey );
49+ } else {
50+ $ exception = new AuthException (GlobalParameter::INCORRECT_KEY_PASSWORD , 0 );
51+ self ::$ logger ->error ("AuthException : " . GlobalParameter::INCORRECT_KEY_PASSWORD );
52+ throw $ exception ;
3753 }
3854
3955 $ mleCert = Utility::findCertByAlias ($ certs , $ merchantConfig ->getMleKeyAlias ());
@@ -110,4 +126,4 @@ private function PemToDer($Pem)
110126 unset($ lines [0 ]);
111127 return implode ("\n" , $ lines );
112128 }
113- }
129+ }
0 commit comments