vendor/symfony/security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php line 38

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Security\Http\Firewall;
  11. use Psr\Log\LoggerInterface;
  12. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  15. use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
  16. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  17. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  18. use Symfony\Component\Security\Core\Exception\BadCredentialsException;
  19. use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
  20. use Symfony\Component\Security\Core\Security;
  21. use Symfony\Component\Security\Csrf\CsrfToken;
  22. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  23. use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
  24. use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
  25. use Symfony\Component\Security\Http\HttpUtils;
  26. use Symfony\Component\Security\Http\ParameterBagUtils;
  27. use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface;
  28. /**
  29.  * UsernamePasswordFormAuthenticationListener is the default implementation of
  30.  * an authentication via a simple form composed of a username and a password.
  31.  *
  32.  * @author Fabien Potencier <fabien@symfony.com>
  33.  */
  34. class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationListener
  35. {
  36.     private $csrfTokenManager;
  37.     
  38.        public function __construct(TokenStorageInterface $tokenStorageAuthenticationManagerInterface $authenticationManagerSessionAuthenticationStrategyInterface $sessionStrategyHttpUtils $httpUtils$providerKeyAuthenticationSuccessHandlerInterface $successHandlerAuthenticationFailureHandlerInterface $failureHandler, array $options = [], LoggerInterface $logger nullEventDispatcherInterface $dispatcher nullCsrfTokenManagerInterface $csrfTokenManager null)
  39.     {
  40.         parent::__construct($tokenStorage$authenticationManager$sessionStrategy$httpUtils$providerKey$successHandler$failureHandlerarray_merge([
  41.             'username_parameter' => '_username',
  42.             'password_parameter' => '_password',
  43.             'csrf_parameter' => '_csrf_token',
  44.             'csrf_token_id' => 'authenticate',
  45.             'post_only' => true,
  46.         ], $options), $logger$dispatcher);
  47.         
  48.         $this->csrfTokenManager $csrfTokenManager;
  49.     }
  50.     /**
  51.      * {@inheritdoc}
  52.      */
  53.     protected function requiresAuthentication(Request $request)
  54.     {
  55.         if ($this->options['post_only'] && !$request->isMethod('POST')) {
  56.             return false;
  57.         }
  58.         return parent::requiresAuthentication($request);
  59.     }
  60.     /**
  61.      * {@inheritdoc}
  62.      */
  63.     protected function attemptAuthentication(Request $request)
  64.     {
  65.         if (null !== $this->csrfTokenManager) {
  66.             $csrfToken ParameterBagUtils::getRequestParameterValue($request$this->options['csrf_parameter']);
  67.             if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
  68.                 throw new InvalidCsrfTokenException('Invalid CSRF token.');
  69.             }
  70.         }
  71.         if ($this->options['post_only']) {
  72.             $username ParameterBagUtils::getParameterBagValue($request->request$this->options['username_parameter']);
  73.             $password ParameterBagUtils::getParameterBagValue($request->request$this->options['password_parameter']);
  74.         } else {
  75.             $username ParameterBagUtils::getRequestParameterValue($request$this->options['username_parameter']);
  76.             $password ParameterBagUtils::getRequestParameterValue($request$this->options['password_parameter']);
  77.         }
  78.         if (!\is_string($username) && (!\is_object($username) || !method_exists($username'__toString'))) {
  79.             throw new BadRequestHttpException(sprintf('The key "%s" must be a string, "%s" given.'$this->options['username_parameter'], \gettype($username)));
  80.         }
  81.         $username trim($username);
  82.         if (\strlen($username) > Security::MAX_USERNAME_LENGTH) {
  83.             throw new BadCredentialsException('Invalid username.');
  84.         }
  85.         $request->getSession()->set(Security::LAST_USERNAME$username);
  86.         
  87.         /// コスモピア独自カスタマイズ START ////////////////////////////////////////////////////////////////////
  88.         
  89.         // 設定ファイルの読み込み
  90.         require_once($_SERVER['DOCUMENT_ROOT'] . "/app/config/cosmopier/config.php");
  91.         
  92.         $mcDebug 0;
  93.         
  94.         // 管理者用ログインでない場合
  95.         if (strpos($_SERVER["REQUEST_URI"], $_SERVER["ECCUBE_ADMIN_ROUTE"]) == false)
  96.         {
  97.             // .envファイルに記載されているマジック
  98.             $authMagic CPSHOP_AUTH_MAGIC// "PK9RJcbRpZYKHSSsM1hpCeeATklcwktq";
  99.             // パスワードのハッシュアルゴリズム app/config/eccube/packages/eccube.yaml
  100.             $passwordHashAlgos CPSHOP_PASSWORD_HASH_ALGOS// "SHA256";
  101.             
  102.             // 連携に必要なパラメータ
  103.             $estKidsApiUrl CPSHOP_ESTKIDS_API_URL// "https://test-e-st.kids-ebc.com/onlineshop/";
  104.             $estKidsApiKeyBase64 CPSHOP_ESTKIDS_API_KEY_BASE64// "ZmdlQFV2O0dldzM6aWRdYA=="; // "fge@Uv;Gew3:id]`";
  105.             $estKidsApiIvBase64 CPSHOP_ESTKIDS_API_IV_BASE64// "cGMpLUw4XAl9LYaCcvAuhw==";
  106.             $estKidsApiCryptType CPSHOP_ESTKIDS_API_CRYPT_TYPE// "AES-128-CBC";
  107.             //if ($mcDebug) echo "estkids_api_url=" . $estKidsApiUrl . "<br>";
  108.             //if ($mcDebug) echo "key_base64=" . $estKidsApiKeyBase64 . "<br>";
  109.             //if ($mcDebug) echo "iv_base64=" . $estKidsApiIvBase64 . "<br>";
  110.             //if ($mcDebug) echo "crypt_type=" . $estKidsApiCryptType . "<br>";
  111.               
  112.             $ECCUBE_DBSERVER   CPSHOP_DBSERVER// "mysql57.cosmopier.sakura.ne.jp"; // "localhost";
  113.             $ECCUBE_DBNAME     CPSHOP_DBNAME// "cosmopier_shop_test_db"; // "cpshop_db";
  114.             $ECCUBE_DBUSER     CPSHOP_DBUSER// "cosmopier"; // "root";
  115.             $ECCUBE_DBPASSWORD CPSHOP_DBPASSWORD// "FyKDaZ8613"; // "";
  116.               
  117.             $ecCubeDBCn;
  118.             $ecCubeDBCn mysqli_connect($ECCUBE_DBSERVER$ECCUBE_DBUSER$ECCUBE_DBPASSWORD$ECCUBE_DBNAME);
  119.             if (!$ecCubeDBCn) die('Connect Error: ' mysqli_connect_error());
  120.             $ecCubeDBCn->set_charset("utf8mb4");
  121.             
  122.             // DBからユーザー情報を取得する(ZENCART移行対象かどうか)
  123.             $isMigrateUser false;
  124.             $zenCartCheckSql  "SELECT id, migrate_status, migrate_date, customers_id, customers_firstname, customers_lastname, customers_password, customers_email_address ";
  125.               $zenCartCheckSql .= "FROM dtb_customer_zencart WHERE customers_email_address = ?";
  126.             
  127.             $zenCartDBQuery $ecCubeDBCn->prepare($zenCartCheckSql);
  128.             $zenCartDBQuery->bind_param("s"$username);
  129.             $zenCartDBQuery->execute();
  130.             
  131.             $zenCartDBQuery->bind_result($zenCartId$zenCartMigrateStatus$zenCartMigrateDate$zenCartCustomerId$zenCartCustomerFirstname$zenCartCustomerLastname$zenCartCustomerPassword$zenCartCustomerEmailAddress);
  132.             while ($zenCartDBQuery->fetch()) {
  133.                 //printf("%s, %s, %s, %s, %s, %s, %s, %s<br>", $zenCartId,$zenCartMigrateStatus,$zenCartMigrateDate,$zenCartCustomerId,$zenCartCustomerFirstname,$zenCartCustomerLastname,$zenCartCustomerPassword,$zenCartCustomerEmailAddress);
  134.                 $isMigrateUser true;
  135.             }
  136.             $zenCartDBQuery->close();
  137.             
  138.             // DBからユーザー情報を取得する(eステKidsユーザーがいるかどうか)
  139.             $isEstKidsUser false;
  140.             if (!$isMigrateUser//⋰移行対象ユーザーはチェックが不要なので
  141.             {
  142.                 $estKidsCheckSql  "SELECT id, estkids_user_id, estkids_firstname, estkids_lastname, estkids_email, dummy_password, first_login_date, last_login_date ";
  143.                   $estKidsCheckSql .= "FROM dtb_customer_estkids WHERE estkids_email = ?";
  144.                 
  145.                 $estKidsDBQuery $ecCubeDBCn->prepare($estKidsCheckSql);
  146.                 $estKidsDBQuery->bind_param("s"$username);
  147.                 $estKidsDBQuery->execute();
  148.                 
  149.                 $estKidsDBQuery->bind_result($estKidsId$estKidsUserId$estKidsFirstName$estKidsLastName$estKidsEmail$estKidsDummyPassword$estKidsFirstLoginDate$estKidsLastLoginDate);
  150.                 while ($estKidsDBQuery->fetch()) {
  151.                     $isEstKidsUser true;
  152.                 }
  153.                 $estKidsDBQuery->close();
  154.             }
  155.             
  156.             // 移行対象のユーザーの場合で初回の場合は入力されたZENCARTのパスワードをEC-CUBEに移行する
  157.             if ($isMigrateUser)
  158.             {
  159.                 if ($zenCartMigrateStatus == 0)
  160.                 {
  161.                     // 移行する必要がある
  162.                     log_info('*** ZENCART-ECCUBE 移行処理 開始 ***');
  163.                     log_info('対象:' $zenCartCustomerEmailAddress '(' $zenCartId ',' $zenCartCustomerId ')');
  164.                     if ($mcDebug) echo '*** ZENCART-ECCUBE 移行処理 開始 ***<br>';
  165.                     if ($mcDebug) echo '対象:' $zenCartCustomerEmailAddress '(' $zenCartId ',' $zenCartCustomerId ')<br>';
  166.                     
  167.                     $zenCartCryptPass explode(':'$zenCartCustomerPassword);
  168.                     if ($mcDebug) echo md5($zenCartCryptPass[1].  $password) . " == " $zenCartCryptPass[0] . "<br>";
  169.                     
  170.                     if (md5($zenCartCryptPass[1].  $password) == $zenCartCryptPass[0]) 
  171.                     {
  172.                         // 新しいパスワードをセットし移行済みフラグを立てる
  173.                         // EC-CUBEのパスワードが上書きされるのでこれ以降はZENCARTへのアクセスが不要
  174.                         
  175.                         // 実装元: src/Eccube/Controller/EntryController.php
  176.                         // SALTの用意
  177.                         $salt bin2hex(openssl_random_pseudo_bytes(5));
  178.                         // 暗号化パスワードの用意
  179.                         $cryptPassword hash_hmac($passwordHashAlgos$password.':'.$authMagic$salt);
  180.                         // シークレットキー(全ユーザーでユニークかどうかを本体ではチェックしている)StringUtilの中で処理
  181.                         $secretKey substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'32)), 032);
  182.                         
  183.                         if ($mcDebug) echo "salt:"$salt "<br>";
  184.                         if ($mcDebug) echo "password:"$cryptPassword "<br>";
  185.                         if ($mcDebug) echo "secretKey:"$secretKey "<br>";
  186.                         
  187.                         $createAndUpdateDate date("Y-m-d H:i:s");
  188.                         
  189.                         // EC-CUBEのアカウントを更新する
  190.                         $ecCubeUserUpdateSql  "UPDATE dtb_customer SET password=?, salt=?, secret_key=? ";
  191.                         $ecCubeUserUpdateSql .= "WHERE email=? ";
  192.                             
  193.                         $ecCubeUserUpdateDBQuery $ecCubeDBCn->prepare($ecCubeUserUpdateSql);
  194.                         $ecCubeUserUpdateDBQuery->bind_param("ssss"$cryptPassword$salt$secretKey$username);
  195.                         $ecCubeUserUpdateDBQuery->execute();
  196.                         $ecCubeUserUpdateDBQuery->close();
  197.                         
  198.                         $zenCartMigrateSql  "UPDATE dtb_customer_zencart SET migrate_status=1, migrate_date='" .date("Y-m-d H:i:s") . "' ";
  199.                         $zenCartMigrateSql .= "WHERE id = ? AND customers_email_address = ?";
  200.                         
  201.                         $zenCartDBQuery $ecCubeDBCn->prepare($zenCartMigrateSql);
  202.                         $zenCartDBQuery->bind_param("is"$zenCartId$username);
  203.                         $zenCartDBQuery->execute();
  204.                         $zenCartDBQuery->close();
  205.                         
  206.                         log_info('移行処理が完了しました。');
  207.                         if ($mcDebug) echo '移行処理が完了しました。<br>';
  208.                     }
  209.                     else
  210.                     {
  211.                         log_info('パスワードが一致しないため移行を中止しました。');
  212.                         if ($mcDebug) echo 'パスワードが一致しないため移行を中止しました。<br>';
  213.                     }
  214.                     
  215.                     log_info('*** ZENCART-ECCUBE 移行処理 終了 ***');
  216.                     if ($mcDebug) echo '*** ZENCART-ECCUBE 移行処理 終了 ***<br>';
  217.                     //exit;
  218.                 }
  219.                 else
  220.                 {
  221.                     // 移行完了済みなので何もしない
  222.                     if ($mcDebug) echo "移行完了済みなので何もしない";
  223.                     //exit;
  224.                 }
  225.             }
  226.             // eステKidsのユーザーの場合はEC-CUBEの認証を使わない
  227.             else if ($isEstKidsUser)
  228.             {
  229.                 // eステKidsのアカウントを調べ、アカウントが存在する場合はパスワードをチェック
  230.                 // パスワードが一致(ハッシュが一致)した場合は、
  231.                 //  EC-CUBEのDBからダミーのパスワード(自動設定のパスワード)を取得しセットする
  232.                 
  233.                 // 送信するデータを生成
  234.                 $key base64_decode($estKidsApiKeyBase64);
  235.                 $iv_size openssl_cipher_iv_length($estKidsApiCryptType);
  236.                 $iv base64_decode($estKidsApiIvBase64);
  237.                 $data openssl_encrypt($username ":" $password$estKidsApiCryptType$keyOPENSSL_RAW_DATA$iv);
  238.                 $data_base64 base64_encode($data);
  239.                 if ($mcDebug) echo "key=" $key "<br>";
  240.                 if ($mcDebug) echo "iv_size=" $iv_size "<br>";
  241.                 if ($mcDebug) echo "iv_base64=" $estKidsApiIvBase64 "<br>";
  242.                 if ($mcDebug) echo "data_base64=" $data_base64 "<br>";
  243.                 
  244.                 // cURLを使ってeステKidsからデータを受け取る
  245.                 $estKidsApi curl_init();
  246.                 $estKidsSendData = array("data" => $data_base64"iv" => $estKidsApiIvBase64);
  247.                 curl_setopt($estKidsApiCURLOPT_URL$estKidsApiUrl);
  248.                 curl_setopt($estKidsApiCURLOPT_POSTtrue);
  249.                 curl_setopt($estKidsApiCURLOPT_POSTFIELDS$estKidsSendData);
  250.                 curl_setopt($estKidsApiCURLOPT_RETURNTRANSFERtrue);
  251.                 $estKidsResponse curl_exec($estKidsApi);
  252.                 $estKidsResult json_decode($estKidsResponse);
  253.                 curl_close($estKidsApi);
  254.                 
  255.                 if ($mcDebug
  256.                 {
  257.                     echo "estKidsResult<pre>";
  258.                     var_dump($estKidsResult);
  259.                     echo "</pre>";
  260.                 }
  261.                 
  262.                 // 結果を見て処理をおこなう
  263.                 if ($estKidsResult->result == "ok")
  264.                 {
  265.                     // 入力したパスワードでOKだったのでこの情報でログインできるようにDBを更新する
  266.                     $estKidsUserId $estKidsResult->userid;
  267.                     $estKidsFirstName $estKidsResult->firstname;
  268.                     $estKidsLastName $estKidsResult->lastname;
  269.                     $estKidsEmail $username;
  270.                     $estKidsSesskey $estKidsResult->sesskey;
  271.                     
  272.                     if ($mcDebug) echo "estKidsUserId:"$estKidsUserId "<br>";
  273.                     if ($mcDebug) echo "estKidsFirstName:"$estKidsFirstName "<br>";
  274.                     if ($mcDebug) echo "estKidsLastName:"$estKidsLastName "<br>";
  275.                     if ($mcDebug) echo "estKidsEmail:"$estKidsEmail "<br>";
  276.                     if ($mcDebug) echo "estKidsSesskey:"$estKidsSesskey "<br>";
  277.                     
  278.                     // 実装元: src/Eccube/Controller/EntryController.php
  279.                     // SALTの用意
  280.                     $salt bin2hex(openssl_random_pseudo_bytes(5));
  281.                     // 暗号化パスワードの用意
  282.                     $cryptPassword hash_hmac($passwordHashAlgos$password.':'.$authMagic$salt);
  283.                     // シークレットキー(全ユーザーでユニークかどうかを本体ではチェックしている)StringUtilの中で処理
  284.                     $secretKey substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'32)), 032);
  285.                     
  286.                     if ($mcDebug) echo "salt:"$salt "<br>";
  287.                     if ($mcDebug) echo "password:"$cryptPassword "<br>";
  288.                     if ($mcDebug) echo "secretKey:"$secretKey "<br>";
  289.                     
  290.                     $createAndUpdateDate date("Y-m-d H:i:s");
  291.                     
  292.                     // EC-CUBEのアカウントを更新する
  293.                     $ecCubeUserUpdateSql  "UPDATE dtb_customer SET password=?, salt=?, secret_key=? ";
  294.                     $ecCubeUserUpdateSql .= "WHERE email=? ";
  295.                         
  296.                     $ecCubeUserUpdateDBQuery $ecCubeDBCn->prepare($ecCubeUserUpdateSql);
  297.                     $ecCubeUserUpdateDBQuery->bind_param("ssss"$cryptPassword$salt$secretKey$username);
  298.                     $ecCubeUserUpdateDBQuery->execute();
  299.                     $ecCubeUserUpdateDBQuery->close();
  300.                         
  301.                     // EC-CUBEのeステKidsテーブルの情報を更新する
  302.                     $estKidsUserUpdateSql  "UPDATE dtb_customer_estkids SET dummy_password=?, last_login_date=? ";
  303.                       $estKidsUserUpdateSql .= "WHERE estkids_user_id=? ";
  304.                     
  305.                     $estKidsUserUpdateDBQuery $ecCubeDBCn->prepare($estKidsUserUpdateSql);
  306.                     $estKidsUserUpdateDBQuery->bind_param("ssi"$cryptPassword$createAndUpdateDate$estKidsUserId);
  307.                     $estKidsUserUpdateDBQuery->execute();
  308.                 }
  309.                 else // if ($estKidsResult->result == "error")
  310.                 {
  311.                     // $estKidsResult->message == "ERROR01" // ユーザーが見つからない
  312.                     // $estKidsResult->message == "ERROR02" // パスワードが正しくない
  313.                     // 何もしない
  314.                 }
  315.             }
  316.             // 通常のEC-CUBEのユーザーまたはeステKidsの新規ユーザー
  317.             else
  318.             {
  319.                 // EC-CUBEにユーザーがいるか調べる
  320.                 // DBからユーザー情報を取得する(eステKidsユーザーがいるかどうか)
  321.                 $isUserExist false;
  322.                 $ecCubeUserCheckSql  "SELECT id, customer_status_id, name01, name02, email ";
  323.                   $ecCubeUserCheckSql .= "FROM dtb_customer WHERE email = ?";
  324.                   
  325.                 $ecCubeUserDBQuery $ecCubeDBCn->prepare($ecCubeUserCheckSql);
  326.                 $ecCubeUserDBQuery->bind_param("s"$username);
  327.                 $ecCubeUserDBQuery->execute();
  328.                 
  329.                 $ecCubeUserDBQuery->bind_result($ecCubeCustomerId$ecCubeCustomerStatusId$ecCubeCustomerName01$ecCubeCustomerName02$estKidsEmail);
  330.                 while ($ecCubeUserDBQuery->fetch()) {
  331.                     $isUserExist true;
  332.                 }
  333.                 $ecCubeUserDBQuery->close();
  334.                 
  335.                 if ($mcDebug) echo '通常のEC-CUBEのユーザーまたはeステKidsの新規ユーザーの処理<br>';
  336.                 if ($mcDebug) echo 'isUserExist:' $isUserExist '<br>';
  337.                 
  338.                 // ユーザーがいないのでeステKidsのアカウントを調べ認証が通ればアカウントを生成する
  339.                 if (!$isUserExist)
  340.                 {
  341.                     // eステKidsのアカウントを調べ、アカウントが存在する場合はパスワードをチェック
  342.                     // パスワードが一致(ハッシュが一致)した場合は、アカウントを作成する
  343.                     
  344.                     // 送信するデータを生成
  345.                     $key base64_decode($estKidsApiKeyBase64);
  346.                     $iv_size openssl_cipher_iv_length($estKidsApiCryptType);
  347.                     $iv base64_decode($estKidsApiIvBase64);
  348.                     $data openssl_encrypt($username ":" $password$estKidsApiCryptType$keyOPENSSL_RAW_DATA$iv);
  349.                     $data_base64 base64_encode($data);
  350.                     if ($mcDebug) echo "key=" $key "<br>";
  351.                     if ($mcDebug) echo "iv_size=" $iv_size "<br>";
  352.                     if ($mcDebug) echo "iv_base64=" $estKidsApiIvBase64 "<br>";
  353.                     if ($mcDebug) echo "data_base64=" $data_base64 "<br>";
  354.                     
  355.                     // cURLを使ってeステKidsからデータを受け取る
  356.                     $estKidsApi curl_init();
  357.                     $estKidsSendData = array("data" => $data_base64"iv" => $estKidsApiIvBase64);
  358.                     curl_setopt($estKidsApiCURLOPT_URL$estKidsApiUrl);
  359.                     curl_setopt($estKidsApiCURLOPT_POSTtrue);
  360.                     curl_setopt($estKidsApiCURLOPT_POSTFIELDS$estKidsSendData);
  361.                     curl_setopt($estKidsApiCURLOPT_RETURNTRANSFERtrue);
  362.                     $estKidsResponse curl_exec($estKidsApi);
  363.                     $estKidsResult json_decode($estKidsResponse);
  364.                     curl_close($estKidsApi);
  365.                     
  366.                     if ($mcDebug
  367.                     {
  368.                         echo "estKidsResponse<pre>";
  369.                         var_dump($estKidsResponse);
  370.                         echo "</pre>";
  371.                         
  372.                         echo "estKidsResult<pre>";
  373.                         var_dump($estKidsResult);
  374.                         echo "</pre>";
  375.                     }
  376.                     
  377.                     /*
  378.                     object(stdClass)#1461 (5) {
  379.                       ["result"]=>
  380.                       string(2) "ok"
  381.                       ["message"]=>
  382.                       string(27) "ログインしました。"
  383.                       ["fullname"]=>
  384.                       string(31) "みらいこ メンテナンス"
  385.                       ["email"]=>
  386.                       string(21) "support@miraico.co.jp"
  387.                       ["sesskey"]=>
  388.                       string(10) "Xb1J1LRSLr"
  389.                     }
  390.                     */
  391.                     
  392.                     // 結果を見て処理をおこなう
  393.                     if ($estKidsResult->result == "ok")
  394.                     {
  395.                         log_info('*** ESTKIDS-ECCUBE 連携ユーザー作成処理 開始 ***');
  396.                         log_info('対象:' $estKidsResult->fullname '(' $username ',' $estKidsResult->userid ')');
  397.                         if ($mcDebug) echo '*** ESTKIDS-ECCUBE 連携ユーザー作成処理 開始 ***<br>';
  398.                         if ($mcDebug) echo '対象:' $estKidsResult->fullname '(' $username ',' $estKidsResult->userid ')<br>';
  399.                         
  400.                         $estKidsUserId $estKidsResult->userid;
  401.                         $estKidsFirstName $estKidsResult->firstname;
  402.                         $estKidsLastName $estKidsResult->lastname;
  403.                         $estKidsEmail $username;
  404.                         $estKidsSesskey $estKidsResult->sesskey;
  405.                         
  406.                         if ($mcDebug) echo "estKidsUserId:"$estKidsUserId "<br>";
  407.                         if ($mcDebug) echo "estKidsFirstName:"$estKidsFirstName "<br>";
  408.                         if ($mcDebug) echo "estKidsLastName:"$estKidsLastName "<br>";
  409.                         if ($mcDebug) echo "estKidsEmail:"$estKidsEmail "<br>";
  410.                         if ($mcDebug) echo "estKidsSesskey:"$estKidsSesskey "<br>";
  411.                         
  412.                         // 実装元: src/Eccube/Controller/EntryController.php
  413.                         // SALTの用意
  414.                         $salt bin2hex(openssl_random_pseudo_bytes(5));
  415.                         // 暗号化パスワードの用意
  416.                         $cryptPassword hash_hmac($passwordHashAlgos$password.':'.$authMagic$salt);
  417.                         // シークレットキー(全ユーザーでユニークかどうかを本体ではチェックしている)StringUtilの中で処理
  418.                         $secretKey substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'32)), 032);
  419.                         
  420.                         if ($mcDebug) echo "salt:"$salt "<br>";
  421.                         if ($mcDebug) echo "password:"$cryptPassword "<br>";
  422.                         if ($mcDebug) echo "secretKey:"$secretKey "<br>";
  423.                         
  424.                         $createAndUpdateDate date("Y-m-d H:i:s");
  425.                         $note "eステKidsアカウント連携(eステKidsユーザーID:" $estKidsUserId "、登録日:" $createAndUpdateDate "、登録元:" $_SERVER["REMOTE_ADDR"] . ", " $_SERVER["HTTP_USER_AGENT"];
  426.                         $note2 $_SERVER["REMOTE_ADDR"] . ", " $_SERVER["HTTP_USER_AGENT"];
  427.                         
  428.                         // EC-CUBEにアカウントを生成する
  429.                         $ecCubeUserCreateSql  "INSERT INTO dtb_customer(customer_status_id, name01, name02, email, password, salt, secret_key, note, create_date, update_date, discriminator_type, customer_rank_id) ";
  430.                         $ecCubeUserCreateSql .= "VALUES(2, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'customer', 3) ";
  431.                         
  432.                         if ($mcDebug) echo "ecCubeUserCreateSql:"$ecCubeUserCreateSql "<br>";
  433.                         
  434.                         $ecCubeUserCreateDBQuery $ecCubeDBCn->prepare($ecCubeUserCreateSql);
  435.                         $ecCubeUserCreateDBQuery->bind_param("sssssssss"$estKidsFirstName$estKidsLastName$estKidsEmail$cryptPassword$salt$secretKey$note$createAndUpdateDate$createAndUpdateDate);
  436.                         $ecCubeUserCreateDBQuery->execute();
  437.                         $ecCubeUserCreateDBQuery->close();
  438.                         
  439.                         // EC-CUBEのeステKidsテーブルにアカウントを作成する
  440.                         $estKidsUserCreateSql  "INSERT INTO dtb_customer_estkids(id, estkids_user_id, estkids_firstname, estkids_lastname, estkids_email, dummy_password, first_login_date, last_login_date, note) ";
  441.                           $estKidsUserCreateSql .= "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ";
  442.                         
  443.                         $estKidsUserCreateDBQuery $ecCubeDBCn->prepare($estKidsUserCreateSql);
  444.                         $estKidsUserCreateDBQuery->bind_param("iisssssss"$estKidsUserId$estKidsUserId$estKidsFirstName$estKidsLastName$estKidsEmail$cryptPassword$createAndUpdateDate$createAndUpdateDate$note2);
  445.                         $estKidsUserCreateDBQuery->execute();
  446.                         
  447.                         $estKidsUserCreateDBQuery->close();
  448.                         
  449.                         log_info('*** ESTKIDS-ECCUBE 連携ユーザー作成処理 終了 ***');
  450.                         if ($mcDebug) echo '*** ESTKIDS-ECCUBE 連携ユーザー作成処理 終了 ***<br>';
  451.                     }
  452.                     else // if ($estKidsResult->result == "error")
  453.                     {
  454.                         // $estKidsResult->message == "ERROR01" // ユーザーが見つからない
  455.                         // $estKidsResult->message == "ERROR02" // パスワードが正しくない
  456.                         // 何もしない
  457.                     }
  458.                 }
  459.             }
  460.             
  461.             $ecCubeDBCn->close();
  462.         }
  463.         
  464.         /// コスモピア独自カスタマイズ END ////////////////////////////////////////////////////////////////////
  465.         
  466.         return $this->authenticationManager->authenticate(new UsernamePasswordToken($username$password$this->providerKey));
  467.     }
  468. }