Skip to content

Commit

Permalink
Fix upgrade plugin eccube-api for ec-cube 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TPS-NghiaLe committed Jun 21, 2022
1 parent cb0da34 commit a9f60ba
Show file tree
Hide file tree
Showing 63 changed files with 232 additions and 200 deletions.
2 changes: 1 addition & 1 deletion ApiNav.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api;
namespace Plugin\Api42;

use Eccube\Common\EccubeNav;

Expand Down
6 changes: 3 additions & 3 deletions Bundle/ApiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\Bundle;
namespace Plugin\Api42\Bundle;

use Plugin\Api\DependencyInjection\ApiExtension;
use Plugin\Api\DependencyInjection\Compiler\ApiCompilerPass;
use Plugin\Api42\DependencyInjection\ApiExtension;
use Plugin\Api42\DependencyInjection\Compiler\ApiCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

Expand Down
4 changes: 2 additions & 2 deletions Command/DumpSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\Command;
namespace Plugin\Api42\Command;

use GraphQL\Utils\SchemaPrinter;
use Plugin\Api\GraphQL\Schema;
use Plugin\Api42\GraphQL\Schema;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
6 changes: 3 additions & 3 deletions Controller/Admin/GraphiQLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\Controller\Admin;
namespace Plugin\Api42\Controller\Admin;

use Eccube\Controller\AbstractController;
use GraphQL\Error\DebugFlag;
use GraphQL\GraphQL;
use Plugin\Api\GraphQL\Schema;
use Plugin\Api42\GraphQL\Schema;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
Expand Down Expand Up @@ -46,7 +46,7 @@ public function __construct(

/**
* @Route("/%eccube_admin_route%/graphiql", name="admin_api_graphiql", methods={"GET"})
* @Template("@Api/admin/OAuth/graphiql.twig")
* @Template("@Api42/admin/OAuth/graphiql.twig")
*
* @return array
*/
Expand Down
32 changes: 17 additions & 15 deletions Controller/Admin/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\Controller\Admin;
namespace Plugin\Api42\Controller\Admin;

use Eccube\Controller\AbstractController;
use Exception;
use Plugin\Api\Form\Type\Admin\ClientType;
use Plugin\Api42\Form\Type\Admin\ClientType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Trikoder\Bundle\OAuth2Bundle\Manager\AccessTokenManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Manager\ClientFilter;
use Trikoder\Bundle\OAuth2Bundle\Manager\ClientManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Manager\RefreshTokenManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Model\AuthorizationCode;
use Trikoder\Bundle\OAuth2Bundle\Model\Client;
use Trikoder\Bundle\OAuth2Bundle\Model\Grant;
use Trikoder\Bundle\OAuth2Bundle\Model\RedirectUri;
use Trikoder\Bundle\OAuth2Bundle\Model\Scope;
use Trikoder\Bundle\OAuth2Bundle\OAuth2Grants;
use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface;
use League\Bundle\OAuth2ServerBundle\Manager\ClientFilter;
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
use League\Bundle\OAuth2ServerBundle\Manager\RefreshTokenManagerInterface;
use League\Bundle\OAuth2ServerBundle\Model\AuthorizationCode;
use League\Bundle\OAuth2ServerBundle\Model\Client;
use League\Bundle\OAuth2ServerBundle\Model\Grant;
use League\Bundle\OAuth2ServerBundle\Model\RedirectUri;
use League\Bundle\OAuth2ServerBundle\Model\Scope;
use League\Bundle\OAuth2ServerBundle\OAuth2Grants;

class OAuthController extends AbstractController
{
Expand Down Expand Up @@ -67,7 +67,7 @@ public function __construct(
/**
* @Route("/%eccube_admin_route%/api/config", name="admin_api_config", methods={"GET"})
* @Route("/%eccube_admin_route%/api/oauth", name="admin_api_oauth", methods={"GET"})
* @Template("@Api/admin/OAuth/index.twig")
* @Template("@Api42/admin/OAuth/index.twig")
*
* @param Request $request
*
Expand All @@ -85,7 +85,7 @@ public function index(Request $request)

/**
* @Route("/%eccube_admin_route%/api/oauth/new", name="admin_api_oauth_new", methods={"GET", "POST"})
* @Template("@Api/admin/OAuth/edit.twig")
* @Template("@Api42/admin/OAuth/edit.twig")
*
* @param Request $request
*
Expand All @@ -95,6 +95,8 @@ public function index(Request $request)
*/
public function create(Request $request)
{
$name = '';

$builder = $this->formFactory
->createBuilder(ClientType::class);

Expand All @@ -106,7 +108,7 @@ public function create(Request $request)
$secret = $form->get('secret')->getData();

try {
$client = new Client($identifier, $secret);
$client = new Client($name, $identifier, $secret);
$client = $this->updateClientFromForm($client, $form);

$this->clientManager->save($client);
Expand Down
12 changes: 6 additions & 6 deletions Controller/Admin/WebHookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\Controller\Admin;
namespace Plugin\Api42\Controller\Admin;

use Eccube\Controller\AbstractController;
use Exception;
use Plugin\Api\Entity\WebHook;
use Plugin\Api\Form\Type\Admin\WebHookType;
use Plugin\Api\Repository\WebHookRepository;
use Plugin\Api42\Entity\WebHook;
use Plugin\Api42\Form\Type\Admin\WebHookType;
use Plugin\Api42\Repository\WebHookRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -41,7 +41,7 @@ public function __construct(WebHookRepository $webHookRepository)

/**
* @Route("/%eccube_admin_route%/api/webhook", name="admin_api_webhook", methods={"GET"})
* @Template("@Api/admin/WebHook/index.twig")
* @Template("@Api42/admin/WebHook/index.twig")
*/
public function index()
{
Expand All @@ -55,7 +55,7 @@ public function index()
/**
* @Route("/%eccube_admin_route%/api/webhook/new", name="admin_api_webhook_new", methods={"GET", "POST"})
* @Route("/%eccube_admin_route%/api/webhook/edit/{id}", requirements={"id" = "\d+"}, name="admin_api_webhook_edit", methods={"GET", "POST"})
* @Template("@Api/admin/WebHook/edit.twig")
* @Template("@Api42/admin/WebHook/edit.twig")
*
* @param Request $request
* @param WebHook|null $WebHook
Expand Down
12 changes: 7 additions & 5 deletions Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\Controller;
namespace Plugin\Api42\Controller;

use Eccube\Controller\AbstractController;
use GraphQL\Error\DebugFlag;
use GraphQL\GraphQL;
use GraphQL\Validator\DocumentValidator;
use Plugin\Api\GraphQL\Schema;
use Plugin\Api\GraphQL\ScopeValidationRule;
use Plugin\Api\GraphQL\Types;
use Plugin\Api42\GraphQL\Schema;
use Plugin\Api42\GraphQL\ScopeValidationRule;
use Plugin\Api42\GraphQL\Types;
use RuntimeException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;

class ApiController extends AbstractController
{
Expand Down Expand Up @@ -62,8 +63,9 @@ public function __construct(

/**
* @Route("/api", name="api", methods={"GET", "POST"})
* @Security("has_role('ROLE_OAUTH2_READ') or has_role('ROLE_OAUTH2_WRITE')")
* @IsGranted("ROLE_OAUTH2_READ", "ROLE_OAUTH2_WRITE")
*/

public function index(Request $request)
{
switch ($request->getMethod()) {
Expand Down
9 changes: 8 additions & 1 deletion DependencyInjection/ApiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\DependencyInjection;
namespace Plugin\Api42\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand Down Expand Up @@ -39,6 +39,13 @@ public function prepend(ContainerBuilder $container)
'oauth2' => true,
'provider' => 'member_provider'
];
unset($security["firewalls"]["admin"]["form_login"]["csrf_token_generator"]);
unset($security["firewalls"]["admin"]["anonymous"]);
}

if ($name === 'customer') {
unset($security["firewalls"]["customer"]["form_login"]["csrf_token_generator"]);
unset($security["firewalls"]["customer"]["anonymous"]);
}
$replaced[$name] = $security["firewalls"][$name];
}
Expand Down
22 changes: 11 additions & 11 deletions DependencyInjection/Compiler/ApiCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\DependencyInjection\Compiler;
namespace Plugin\Api42\DependencyInjection\Compiler;

use League\OAuth2\Server\CryptKey;
use Plugin\Api\GraphQL\AllowList;
use Plugin\Api\GraphQL\Mutation;
use Plugin\Api\GraphQL\Query;
use Plugin\Api\GraphQL\Types;
use Plugin\Api\Service\WebHookEvents;
use Plugin\Api\Service\WebHookTrigger;
use Plugin\Api42\GraphQL\AllowList;
use Plugin\Api42\GraphQL\Mutation;
use Plugin\Api42\GraphQL\Query;
use Plugin\Api42\GraphQL\Types;
use Plugin\Api42\Service\WebHookEvents;
use Plugin\Api42\Service\WebHookTrigger;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -34,9 +34,9 @@ public function process(ContainerBuilder $container)
$this->configureSchema($container);

$plugins = $container->getParameter('eccube.plugins.enabled');
if (!in_array('Api', $plugins)) {
if ($container->hasDefinition('Trikoder\Bundle\OAuth2Bundle\EventListener\ConvertExceptionToResponseListener')) {
$def = $container->getDefinition('Trikoder\Bundle\OAuth2Bundle\EventListener\ConvertExceptionToResponseListener');
if (!in_array('Api42', $plugins)) {
if ($container->hasDefinition('League\Bundle\OAuth2ServerBundle\EventListener\AddClientDefaultScopesListener')) {
$def = $container->getDefinition('League\Bundle\OAuth2ServerBundle\EventListener\AddClientDefaultScopesListener');
$def->clearTags();
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ private function configureAllowList(ContainerBuilder $container)
private function configureKeyPair(ContainerBuilder $container)
{
$projectDir = $container->getParameter('kernel.project_dir');
$oauthConfig = $container->getExtensionConfig('trikoder_oauth2');
$oauthConfig = $container->getExtensionConfig('league_oauth2_server');
$oauthConfig = $container->resolveEnvPlaceholders($oauthConfig, true);
$privateKey = str_replace('%%kernel.project_dir%%', $projectDir, $oauthConfig[0]['authorization_server']['private_key']);
$publicKey = str_replace('%%kernel.project_dir%%', $projectDir, $oauthConfig[0]['resource_server']['public_key']);
Expand Down
6 changes: 3 additions & 3 deletions Doctrine/EventSubscriber/EntityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\Doctrine\EventSubscriber;
namespace Plugin\Api42\Doctrine\EventSubscriber;

use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\Events;
use Plugin\Api\Service\WebHookEvents;
use Plugin\Api42\Service\WebHookEvents;

class EntityListener implements EventSubscriber
{
Expand Down
4 changes: 2 additions & 2 deletions Entity/WebHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\Entity;
namespace Plugin\Api42\Entity;

use DateTime;
use Doctrine\ORM\Mapping as ORM;
Expand All @@ -23,7 +23,7 @@
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity(repositoryClass="Plugin\Api\Repository\WebHookRepository")
* @ORM\Entity(repositoryClass="Plugin\Api42\Repository\WebHookRepository")
*/
class WebHook
{
Expand Down
19 changes: 6 additions & 13 deletions EventListener/AuthorizationRequestResolveListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,25 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\EventListener;
namespace Plugin\Api42\EventListener;

use Eccube\Entity\Master\Authority;
use Eccube\Entity\Member;
use League\OAuth2\Server\Exception\OAuthServerException;
use Plugin\Api\Form\Type\Admin\OAuth2AuthorizationType;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
use Plugin\Api42\Form\Type\Admin\OAuth2AuthorizationType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Trikoder\Bundle\OAuth2Bundle\Event\AuthorizationRequestResolveEvent;
use Trikoder\Bundle\OAuth2Bundle\OAuth2Events;
use League\Bundle\OAuth2ServerBundle\Event\AuthorizationRequestResolveEvent;
use League\Bundle\OAuth2ServerBundle\OAuth2Events;
use Twig\Environment as Twig;

final class AuthorizationRequestResolveListener implements EventSubscriberInterface
{
/** @var Twig */
protected $twig;

/** @var PsrHttpFactory */
protected $psr7Factory;

/** @var FormFactoryInterface */
protected $formFactory;

Expand All @@ -42,12 +38,10 @@ final class AuthorizationRequestResolveListener implements EventSubscriberInterf

public function __construct(
Twig $twig,
PsrHttpFactory $psr7Factory,
FormFactoryInterface $formFactory,
RequestStack $requestStack
) {
$this->twig = $twig;
$this->psr7Factory = $psr7Factory;
$this->formFactory = $formFactory;
$this->requestStack = $requestStack;
}
Expand Down Expand Up @@ -87,7 +81,7 @@ public function onAuthorizationRequestResolve(AuthorizationRequestResolveEvent $
$form['state']->setData($event->getState());
$form['scope']->setData(join(' ', $event->getScopes()));
$content = $this->twig->render(
'@Api/admin/OAuth/authorization.twig',
'@Api42/admin/OAuth/authorization.twig',
[
'scopes' => $event->getScopes(),
'form' => $form->createView(),
Expand All @@ -104,8 +98,7 @@ public function onAuthorizationRequestResolve(AuthorizationRequestResolveEvent $
$event->resolveAuthorization(AuthorizationRequestResolveEvent::AUTHORIZATION_DENIED);
}
} else {
$Response = $this->psr7Factory->createResponse(Response::create($content));
$event->setResponse($Response);
$event->setResponse(Response::create($content));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions EventListener/UserResolveListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\EventListener;
namespace Plugin\Api42\EventListener;

use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Trikoder\Bundle\OAuth2Bundle\Event\UserResolveEvent;
use League\Bundle\OAuth2ServerBundle\Event\UserResolveEvent;

final class UserResolveListener
{
Expand Down
Loading

0 comments on commit a9f60ba

Please sign in to comment.