-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
142 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
; supervisor config file | ||
|
||
[unix_http_server] | ||
file=/var/run/supervisor.sock ; (the path to the socket file) | ||
chmod=0700 ; sockef file mode (default 0700) | ||
|
||
[supervisord] | ||
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) | ||
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) | ||
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP) | ||
nodaemon=true | ||
|
||
; the below section must remain in the config file for RPC | ||
; (supervisorctl/web interface) to work, additional interfaces may be | ||
; added by defining them in separate rpcinterface: sections | ||
[rpcinterface:supervisor] | ||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface | ||
|
||
[supervisorctl] | ||
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket | ||
|
||
; The [include] section can just contain the "files" setting. This | ||
; setting can list multiple files (separated by whitespace or | ||
; newlines). It can also contain wildcards. The filenames are | ||
; interpreted as relative to this file. Included files *cannot* | ||
; include files themselves. | ||
|
||
[program:cronjob] | ||
command =/usr/bin/php /semart/bin/console semart:cron:start --blocking | ||
autostart=true | ||
autorestart=true | ||
priority=5 | ||
stdout_logfile=/var/log/supervisor/cronjob.out.log | ||
stdout_logfile_maxbytes=0 | ||
stderr_logfile=/var/log/supervisor/cronjob.error.log | ||
stderr_logfile_maxbytes=0 | ||
|
||
[program:server] | ||
command =/semart/bin/rr serve -c /semart/.rr.dev.yaml | ||
autostart=true | ||
autorestart=true | ||
priority=5 | ||
stdout_logfile=/var/log/supervisor/server.out.log | ||
stdout_logfile_maxbytes=0 | ||
stderr_logfile=/var/log/supervisor/server.error.log | ||
stderr_logfile_maxbytes=0 | ||
|
||
[include] | ||
files = /etc/supervisor/conf.d/*.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
namespace KejawenLab\ApiSkeleton\EventSubscriber; | ||
|
||
use KejawenLab\ApiSkeleton\Admin\AdminContext; | ||
use KejawenLab\ApiSkeleton\Security\Model\UserInterface; | ||
use KejawenLab\ApiSkeleton\Security\Service\UserProviderFactory; | ||
use KejawenLab\ApiSkeleton\Security\Service\UserService; | ||
|
@@ -12,7 +13,10 @@ | |
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTDecodedEvent; | ||
use Lexik\Bundle\JWTAuthenticationBundle\Events; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
/** | ||
* @author Muhamad Surya Iksanudin<[email protected]> | ||
|
@@ -23,18 +27,45 @@ final class SingleLoginSubscriber implements EventSubscriberInterface | |
|
||
private RequestStack $requestStack; | ||
|
||
private UrlGeneratorInterface $urlGenerator; | ||
|
||
private UserService $service; | ||
|
||
private UserProviderFactory $userProviderFactory; | ||
|
||
public function __construct(RequestStack $requestStack, UserService $service, UserProviderFactory $userProviderFactory) | ||
public function __construct(RequestStack $requestStack, UrlGeneratorInterface $urlGenerator, UserService $service, UserProviderFactory $userProviderFactory) | ||
{ | ||
$this->requestStack = $requestStack; | ||
$this->urlGenerator = $urlGenerator; | ||
$this->service = $service; | ||
$this->userProviderFactory = $userProviderFactory; | ||
} | ||
|
||
public function validate(JWTDecodedEvent $event): void | ||
public function validate(RequestEvent $event): void | ||
{ | ||
if (!$event->isMasterRequest()) { | ||
return; | ||
} | ||
|
||
$request = $event->getRequest(); | ||
if (!AdminContext::isAdminContext($request)) { | ||
return; | ||
} | ||
|
||
$session = $request->getSession(); | ||
if (!$deviceId = $session->get(AdminContext::USER_DEVICE_ID)) { | ||
return; | ||
} | ||
|
||
$user = $this->service->getByDeviceId($deviceId); | ||
if ($user) { | ||
return; | ||
} | ||
|
||
$event->setResponse(new RedirectResponse($this->urlGenerator->generate('admin_logout'))); | ||
} | ||
|
||
public function decode(JWTDecodedEvent $event): void | ||
{ | ||
$payload = $event->getPayload(); | ||
if (!isset($payload['deviceId'])) { | ||
|
@@ -49,15 +80,15 @@ public function validate(JWTDecodedEvent $event): void | |
} | ||
|
||
$user = $this->service->getByDeviceId($payload['deviceId']); | ||
if (!$user) { | ||
$event->markAsInvalid(); | ||
$event->stopPropagation(); | ||
|
||
if ($user) { | ||
return; | ||
} | ||
|
||
$event->markAsInvalid(); | ||
$event->stopPropagation(); | ||
} | ||
|
||
public function sign(JWTCreatedEvent $event): void | ||
public function create(JWTCreatedEvent $event): void | ||
{ | ||
$user = $this->userProviderFactory->getRealUser($event->getUser()); | ||
$payload = $event->getData(); | ||
|
@@ -78,10 +109,11 @@ public function sign(JWTCreatedEvent $event): void | |
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
JWTCreatedEvent::class => 'sign', | ||
JWTDecodedEvent::class => 'validate', | ||
Events::JWT_CREATED => 'sign', | ||
Events::JWT_DECODED => 'validate', | ||
RequestEvent::class => [['validate', -255]], | ||
JWTCreatedEvent::class => 'create', | ||
JWTDecodedEvent::class => 'decode', | ||
Events::JWT_CREATED => 'create', | ||
Events::JWT_DECODED => 'decode', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters