EC-CUBE
4.3.0
サーバーOS
Linux .xserver.jp 5.4.0-189-generic #209-Ubuntu SMP Fri Jun 7 14:05:13 UTC 2024 x86_64
DBサーバー
MySQL 10.5.24-MariaDB-log
WEBサーバー
Apache
PHP
8.2.22 (Core, date, libxml, openssl, pcre, sqlite3, zlib, bz2, calendar, ctype, curl, hash, fileinfo, filter, ftp, gettext, gmp, json, iconv, SPL, session, standard, Phar, posix, pspell, random, Reflection, mbstring, shmop, SimpleXML, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, xml, zip, mysqlnd, cgi-fcgi, apcu, bcmath, dba, dom, gd, imagick, imap, intl, ldap, exif, mcrypt, mysqli, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, soap, xmlreader, xmlwriter, xsl, Zend OPcache)
表題の件につきまして デフォルトの会員マスタを利用せずに 販売管理から顧客データを取得 セッションに保持して ログインがしたいです。
セッションを代入するところまではできたのですが、認証システムのようなところで失敗します。
何が問題なのか分かりません。どなたか詳しい方がいらっしゃれば教えてください。
セッションに格納したデータ
{"customer":{"CODE":"10083940","SIMEI":"テスト","KANA":"テスト","DMKBN":"1","ZIP":"999-9999","ADR1":"東京都","ADR2":"東京都葛飾区葛飾","ADR3":"","ADR4":"","TEL":"0339393939","FAX":"","TEL2":"","AREA":"","CBAR":"","DADR":"0","GADR":"0","CODE2":"","TANKAKBN":"1","SEX":"3","BIRTHDAY":"","AGE":"","BLKBN":"0","BLDAY":"","BAITAI":"","BAITAI_NAME":"","BAIFILE":"","BAIFILE_NAME":"","FREE1":"","FREE2":"","FREE3":"","FDAY1":"","FDAY2":"","FDAY3":"","FMEMO1":"","FMEMO2":"","FMEMO3":"","FCODE1":"","FCODE2":"1","FCODE3":"1","FNAME1":"","FNAME2":"","FNAME3":"","UPCODE":"","UPCODE_SIMEI":"","MAIL":"","BIKOU1":"","BIKOU2":"","BIKOU3":"","MAIL1":"","PCKBN1":"","KEIKBN1":"","MELMAGA1":"","MAIL2":"","PCKBN2":"","KEIKBN2":"","MELMAGA2":"","MAIL3":"","PCKBN3":"","KEIKBN3":"","MELMAGA3":"","MAIL4":"","PCKBN4":"","KEIKBN4":"","MELMAGA4":"","MAIL5":"","PCKBN5":"","KEIKBN5":"","MELMAGA5":"","USERID":"[email protected]","TAIKAI":"0","TORIKBN":"0","SIME":"0","SITE":"0","INDAY":"0","ICODE":"10083940","RITU":"0","KHASUU":"0"}}
エラーの内容
Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\HttpException: "Full authentication is required to access this resource." at ExceptionListener.php line 232
request Hide context Show trace
[▼
"exception" =>
Symfony\Component\HttpKernel\Exception
\
HttpException {#898 ▼
#message: "Full authentication is required to access this resource."
#code: 0
#file: "
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/security-http/
Firewall/ExceptionListener.php"
#line: 232
-previous:
Symfony\Component\Security\Core\Exception
\
InsufficientAuthenticationException {#29 …}
-statusCode: 401
-headers: []
trace: {▼
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/security-http/
Firewall/ExceptionListener.php:232 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/security-http/
Firewall/ExceptionListener.php:189 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/security-http/
Firewall/ExceptionListener.php:148 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/security-http/
Firewall/ExceptionListener.php:103 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/event-dispatcher/
Debug/WrappedListener.php:116 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/event-dispatcher/
EventDispatcher.php:220 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/event-dispatcher/
EventDispatcher.php:56 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/event-dispatcher/
Debug/TraceableEventDispatcher.php:139 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/http-kernel/
HttpKernel.php:239 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/http-kernel/
HttpKernel.php:91 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env/vendor
/symfony/http-kernel/
Kernel.php:197 {▶}
/home/xs177621/bitsuhan.site/public_html/development-env
/
index.php:83 {▶}
}
}
]
変更した箇所
app/config/eccube/packages/security.yaml
Symfony Security-Bundle のログイン処理に関する定義をコメントアウト
- form_login:
- check_path: mypage_login
- login_path: mypage_login
- csrf_token_generator: security.csrf.token_manager
- default_target_path: homepage
- username_parameter: 'login_email'
- password_parameter: 'login_pass'
- use_forward: false
- success_handler: eccube.security.success_handler
- failure_handler: eccube.security.failure_handler
+ # form_login:
+ # check_path: mypage_login
+ # login_path: mypage_login
+ # csrf_token_generator: security.csrf.token_manager
+ # default_target_path: homepage
+ # username_parameter: 'login_email'
+ # password_parameter: 'login_pass'
+ # use_forward: false
+ # success_handler: eccube.security.success_handler
+ # failure_handler: eccube.security.failure_handler
src/Controller/Mypage/MypageController.php
ログインフォーム送信時のAPI処理を追記
/**
* ログイン画面.
*
* @Route("/mypage/login", name="mypage_login")
* @Template("Mypage/login.twig")
*/
public function login(Request $request, AuthenticationUtils $utils)
{
if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
log_info('認証済のためログイン処理をスキップ');
return $this->redirectToRoute('mypage');
}
/* @var $form \Symfony\Component\Form\FormInterface */
$builder = $this->formFactory
->createNamedBuilder('', CustomerLoginType::class);
$builder->get('login_memory')->setData((bool) $request->getSession()->get('_security.login_memory'));
if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$Customer = $this->getUser();
if ($Customer instanceof Customer) {
$builder->get('login_email')
->setData($Customer->getEmail());
}
}
$event = new EventArgs(
[
'builder' => $builder,
],
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE, $event);
$form = $builder->getForm();
+ $error = false;
+
+ if ($form->isSubmitted()) {
+ $username = $form['login_id']->getData();
+ $password = $form['login_pass']->getData();
+
+ try {
+ // API実行
+ $customerResponse = $this->customerApi->callApiAuthenticate($username, $password);
+ if(!empty($customerResponse)){
+ $customer = $customerResponse['LoginMember']['Member'];
+ // 他のページでも顧客データを扱えるよう、取得した情報をセッションに格納
+ $this->session->set('customer', $customer);
※ここでエラーとなる。
+
+ return $this->redirectToRoute('mypage');
+ } else {
+ $error = true;
+ }
+ } catch (ApiException $e) {
+ log_info($e->getMessage());
+ $error = true;
+ }
+ }
return [
- 'error' => $utils->getLastAuthenticationError(),
+ // error = true の場合、テンプレート側でエラー処理を行う
+ 'error' => $error,
'form' => $form->createView(),
];
}