|
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
|
|
|
/** @var SamlToken $token */ |
|
34
|
|
|
$token = $this->get('security.token_storage')->getToken(); |
|
35
|
|
|
$logger = $this->get('logger'); |
|
36
|
|
|
|
|
37
|
|
|
/** @var Identity $identity */ |
|
38
|
|
|
$identity = $token->getUser(); |
|
39
|
|
|
|
|
40
|
|
|
$logger->notice(sprintf('Select Institution for SRAA "%s"', $identity->id)); |
|
41
|
|
|
|
|
42
|
|
|
$command = new SelectInstitutionCommand(); |
|
43
|
|
|
$command->institution = $identity->institution; |
|
44
|
|
|
|
|
45
|
|
|
$form = $this->createForm('sraa_institution_select', $command); |
|
46
|
|
|
$form->handleRequest($request); |
|
47
|
|
|
|
|
48
|
|
|
if ($form->isValid()) { |
|
49
|
|
|
$institutionConfigurationOptions = $this->get('ra.service.institution_configuration_options') |
|
|
|
|
|
|
50
|
|
|
->getInstitutionConfigurationOptionsFor($command->institution); |
|
51
|
|
|
$token->changeInstitutionScope($command->institution, $institutionConfigurationOptions); |
|
52
|
|
|
|
|
53
|
|
|
$flashMessage = $this->get('translator') |
|
54
|
|
|
->trans('ra.sraa.changed_institution', ['%institution%' => $command->institution]); |
|
55
|
|
|
$this->get('session')->getFlashBag()->add('success', $flashMessage); |
|
56
|
|
|
|
|
57
|
|
|
$logger->notice(sprintf( |
|
58
|
|
|
'SRAA "%s" successfully switched to institution "%s"', |
|
59
|
|
|
$identity->id, |
|
60
|
|
|
$command->institution |
|
61
|
|
|
)); |
|
62
|
|
|
|
|
63
|
|
|
return $this->redirect($this->generateUrl('ra_vetting_search')); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$logger->notice(sprintf('Showing select institution form for SRAA "%s"', $identity->id)); |
|
67
|
|
|
|
|
68
|
|
|
return $this->render( |
|
69
|
|
|
'SurfnetStepupRaRaBundle:Sraa:selectInstitution.html.twig', |
|
70
|
|
|
['form' => $form->createView()] |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.