1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupRa\RaBundle\Controller; |
20
|
|
|
|
21
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity; |
22
|
|
|
use Surfnet\StepupRa\RaBundle\Command\SelectInstitutionCommand; |
23
|
|
|
use Surfnet\StepupRa\RaBundle\Security\Authentication\Token\SamlToken; |
24
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
25
|
|
|
use Symfony\Component\HttpFoundation\Request; |
26
|
|
|
|
27
|
|
|
class SraaController extends Controller |
28
|
|
|
{ |
29
|
|
|
public function selectInstitutionAction(Request $request) |
30
|
|
|
{ |
31
|
|
|
$this->denyAccessUnlessGranted(['ROLE_SRAA']); |
32
|
|
|
|
33
|
|
|
$logger = $this->get('logger'); |
34
|
|
|
/** @var Identity $identity */ |
35
|
|
|
$identity = $this->get('security.token_storage')->getToken()->getUser(); |
36
|
|
|
|
37
|
|
|
$logger->notice(sprintf('Select Institution for SRAA "%s"', $identity->id)); |
38
|
|
|
|
39
|
|
|
$command = new SelectInstitutionCommand(); |
40
|
|
|
$command->institution = $identity->institution; |
41
|
|
|
|
42
|
|
|
$form = $this->createForm('sraa_institution_select', $command); |
43
|
|
|
$form->handleRequest($request); |
44
|
|
|
|
45
|
|
|
if ($form->isValid()) { |
46
|
|
|
$newInstitution = $command->institution; |
47
|
|
|
$identity->institution = $newInstitution; |
48
|
|
|
|
49
|
|
|
/** @var SamlToken $token */ |
50
|
|
|
$tokenStorage = $this->get('security.token_storage'); |
51
|
|
|
$token = $tokenStorage->getToken(); |
52
|
|
|
|
53
|
|
|
$institutionConfigurationOptionsService = $this->get('ra.service.institution_configuration_options'); |
|
|
|
|
54
|
|
|
$institutionConfigurationOptions = $institutionConfigurationOptionsService |
|
|
|
|
55
|
|
|
->getInstitutionConfigurationOptionsFor($newInstitution); |
56
|
|
|
|
57
|
|
|
// The institution configuration options need to be updated to correctly acquire the context of the |
58
|
|
|
// selected institution |
59
|
|
|
$token->setInstitutionConfigurationOptions($institutionConfigurationOptions); |
60
|
|
|
$tokenStorage->setToken($token); |
61
|
|
|
|
62
|
|
|
$flashMessage = $this->get('translator') |
63
|
|
|
->trans('ra.sraa.changed_institution', ['%institution%' => $newInstitution]); |
64
|
|
|
|
65
|
|
|
$this->get('session')->getFlashBag()->add('success', $flashMessage); |
66
|
|
|
|
67
|
|
|
$logger->notice(sprintf( |
68
|
|
|
'SRAA "%s successfully switched to institution "%s"', |
69
|
|
|
$identity->id, |
70
|
|
|
$newInstitution |
71
|
|
|
)); |
72
|
|
|
|
73
|
|
|
return $this->redirect($this->generateUrl('ra_vetting_search')); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$logger->notice(sprintf('Showing select institution form for SRAA "%s"', $identity->id)); |
77
|
|
|
|
78
|
|
|
return $this->render( |
79
|
|
|
'SurfnetStepupRaRaBundle:Sraa:selectInstitution.html.twig', |
80
|
|
|
['form' => $form->createView()] |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.