Skip to content

Commit

Permalink
Merge pull request #111 from SURFnet/feature/implement-locale-cookie
Browse files Browse the repository at this point in the history
Implement locale cookie listener from StepupBundle into SelfService
  • Loading branch information
Alex Rothuis authored Oct 14, 2016
2 parents 81ae4c8 + af44019 commit c390c14
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ services:
- "@security.token_storage"
- "@logger"

self_service.service.locale_provider:
class: Surfnet\StepupSelfService\SelfServiceBundle\Service\LocaleProviderService
arguments:
- "@security.token_storage"

self_service.service.ra:
class: Surfnet\StepupSelfService\SelfServiceBundle\Service\RaService
arguments:
Expand All @@ -120,6 +125,15 @@ services:
arguments: [ "@security.token_storage", "@translator" ]
tags: [{ name: kernel.event_subscriber }]

self_service.event_listener.locale_cookie:
class: Surfnet\StepupBundle\EventListener\LocaleCookieListener
arguments:
- "@surfnet_stepup.locale_cookie_helper"
- "@self_service.service.locale_provider"
- "@logger"
tags:
- { name: kernel.event_listener, event: kernel.response, method: onKernelResponse, priority: 6 }

self_service.locale.request_stack_locale_provider:
class: Surfnet\StepupSelfService\SelfServiceBundle\Locale\RequestStackLocaleProvider
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
use Symfony\Component\Security\Http\Logout\CookieClearingLogoutHandler;
use Symfony\Component\Security\Http\Logout\SessionLogoutHandler;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ExplicitSessionTimeoutHandler implements AuthenticationHandler
{
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* Copyright 2016 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Surfnet\StepupSelfService\SelfServiceBundle\Service;

use Surfnet\StepupBundle\Service\LocaleProviderService as StepupLocaleProviderService;
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

final class LocaleProviderService implements StepupLocaleProviderService
{
/**
* @var TokenStorageInterface
*/
private $tokenStorage;

public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}

public function determinePreferredLocale()
{
$token = $this->tokenStorage->getToken();

if (!$token) {
return;
}

/** @var Identity $identity */
$identity = $token->getUser();

if (!$identity instanceof Identity) {
return;
}

return $identity->preferredLocale;
}
}

0 comments on commit c390c14

Please sign in to comment.