Skip to content

Commit fd81abb

Browse files
committed
Merge pull request #89 from SURFnet/feature/sf-toggle
Allow enabling of second factors by configuration
2 parents b32c47e + d82649a commit fd81abb

File tree

13 files changed

+264
-27
lines changed

13 files changed

+264
-27
lines changed

app/config/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,6 @@ jms_translation:
162162
excluded_names: ['*TestCase.php', '*Test.php']
163163
excluded_dirs: [cache, data, logs, Tests]
164164
extractors: []
165+
166+
surfnet_stepup_self_service_self_service:
167+
enabled_second_factors: %enabled_second_factors%

app/config/parameters.yml.dist

+4
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ parameters:
4444
stepup_loa_loa3: https://gateway.tld/authentication/loa3
4545

4646
logout_redirect_url: https://www.surf.nl/over-surf/werkmaatschappijen/surfnet
47+
48+
enabled_second_factors:
49+
- sms
50+
- yubikey

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"symfony/swiftmailer-bundle": "~2.3"
3131
},
3232
"require-dev": {
33+
"matthiasnoback/symfony-config-test": "^1.2.0",
3334
"mockery/mockery": "~0.9.0",
3435
"sensio/generator-bundle": "~2.3",
3536
"ibuildings/qa-tools": "~1.1,>=1.1.27",

composer.lock

+57-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/Controller.php

+12
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,16 @@ protected function getIdentity()
4848

4949
return $user;
5050
}
51+
52+
/**
53+
* @param string $type
54+
*/
55+
protected function assertSecondFactorEnabled($type)
56+
{
57+
if (!in_array($type, $this->getParameter('ss.enabled_second_factors'))) {
58+
$this->get('logger')->warning('A controller action was called for a disabled second factor');
59+
60+
throw $this->createNotFoundException();
61+
}
62+
}
5163
}

src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/Registration/GssfController.php

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ final class GssfController extends Controller
3838
*/
3939
public function initiateAction($provider)
4040
{
41+
$this->assertSecondFactorEnabled($provider);
42+
4143
return $this->renderInitiateForm($provider);
4244
}
4345

@@ -47,6 +49,8 @@ public function initiateAction($provider)
4749
*/
4850
public function authenticateAction($provider)
4951
{
52+
$this->assertSecondFactorEnabled($provider);
53+
5054
$provider = $this->getProvider($provider);
5155

5256
$authnRequest = AuthnRequestFactory::createNewRequest(
@@ -77,6 +81,8 @@ public function authenticateAction($provider)
7781
*/
7882
public function consumeAssertionAction(Request $httpRequest, $provider)
7983
{
84+
$this->assertSecondFactorEnabled($provider);
85+
8086
$provider = $this->getProvider($provider);
8187

8288
$this->get('logger')->notice(
@@ -145,6 +151,8 @@ public function consumeAssertionAction(Request $httpRequest, $provider)
145151
*/
146152
public function metadataAction($provider)
147153
{
154+
$this->assertSecondFactorEnabled($provider);
155+
148156
$provider = $this->getProvider($provider);
149157

150158
/** @var \Surfnet\SamlBundle\Metadata\MetadataFactory $factory */

src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/Registration/SmsController.php

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class SmsController extends Controller
3333
*/
3434
public function sendChallengeAction(Request $request)
3535
{
36+
$this->assertSecondFactorEnabled('sms');
37+
3638
$identity = $this->getIdentity();
3739

3840
$command = new SendSmsChallengeCommand();
@@ -71,6 +73,8 @@ public function sendChallengeAction(Request $request)
7173
*/
7274
public function provePossessionAction(Request $request)
7375
{
76+
$this->assertSecondFactorEnabled('sms');
77+
7478
/** @var SmsSecondFactorService $service */
7579
$service = $this->get('surfnet_stepup_self_service_self_service.service.sms_second_factor');
7680

src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/Registration/YubikeyController.php

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class YubikeyController extends Controller
3232
*/
3333
public function provePossessionAction(Request $request)
3434
{
35+
$this->assertSecondFactorEnabled('yubikey');
36+
3537
$identity = $this->getIdentity();
3638

3739
$command = new VerifyYubikeyOtpCommand();

src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/RegistrationController.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ class RegistrationController extends Controller
3131
*/
3232
public function displaySecondFactorTypesAction()
3333
{
34-
return ['commonName' => $this->getIdentity()->commonName];
34+
$enabledSecondFactors = $this->getParameter('ss.enabled_second_factors');
35+
36+
return [
37+
'commonName' => $this->getIdentity()->commonName,
38+
'enabledSecondFactors' => array_combine($enabledSecondFactors, $enabledSecondFactors),
39+
];
3540
}
3641

3742
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2015 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\StepupSelfService\SelfServiceBundle\DependencyInjection;
20+
21+
use Surfnet\StepupBundle\Exception\DomainException;
22+
use Surfnet\StepupBundle\Exception\InvalidArgumentException;
23+
use Surfnet\StepupBundle\Value\SecondFactorType;
24+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
25+
use Symfony\Component\Config\Definition\ConfigurationInterface;
26+
27+
class Configuration implements ConfigurationInterface
28+
{
29+
public function getConfigTreeBuilder()
30+
{
31+
$treeBuilder = new TreeBuilder();
32+
33+
$treeBuilder
34+
->root('surfnet_stepup_self_service_self_service')
35+
->children()
36+
->arrayNode('enabled_second_factors')
37+
->isRequired()
38+
->prototype('scalar')
39+
->validate()
40+
->ifTrue(function ($type) {
41+
try {
42+
new SecondFactorType($type);
43+
} catch (InvalidArgumentException $e) {
44+
return true;
45+
} catch (DomainException $e) {
46+
return true;
47+
}
48+
})
49+
->thenInvalid(
50+
'Enabled second factor type "%s" is not one of the valid types. See SecondFactorType'
51+
)
52+
->end()
53+
->end()
54+
->end()
55+
->end();
56+
57+
return $treeBuilder;
58+
}
59+
}

src/Surfnet/StepupSelfService/SelfServiceBundle/DependencyInjection/SurfnetStepupSelfServiceSelfServiceExtension.php

+5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ class SurfnetStepupSelfServiceSelfServiceExtension extends Extension
3535
*/
3636
public function load(array $configs, ContainerBuilder $container)
3737
{
38+
$configuration = new Configuration();
39+
$config = $this->processConfiguration($configuration, $configs);
40+
3841
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
3942
$loader->load('services.yml');
4043

4144
$container->getDefinition('self_service.locale.request_stack_locale_provider')
4245
->replaceArgument(1, $container->getParameter('default_locale'))
4346
->replaceArgument(2, $container->getParameter('locales'));
47+
48+
$container->setParameter('ss.enabled_second_factors', $config['enabled_second_factors']);
4449
}
4550
}

src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/displaySecondFactorTypes.html.twig

+21-17
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,26 @@
1212
<h2>{{ block('page_title') }}</h2>
1313

1414
<div class="row">
15-
{% include 'SurfnetStepupSelfServiceSelfServiceBundle::Registration/partial/secondFactor.html.twig' with {
16-
'type': 'sms',
17-
'security': 2,
18-
'url': path('ss_registration_sms_send_challenge')
19-
} only %}
20-
{#
21-
{% include 'SurfnetStepupSelfServiceSelfServiceBundle::Registration/partial/secondFactor.html.twig' with {
22-
'type': 'tiqr',
23-
'security': 2,
24-
'url': path('ss_registration_gssf_initiate', {'provider': 'tiqr'})
25-
} only %}
26-
#}
27-
{% include 'SurfnetStepupSelfServiceSelfServiceBundle::Registration/partial/secondFactor.html.twig' with {
28-
'type': 'yubikey',
29-
'security': 3,
30-
'url': path('ss_registration_yubikey_prove_possession')
31-
} only %}
15+
{% if enabledSecondFactors.sms is defined %}
16+
{% include 'SurfnetStepupSelfServiceSelfServiceBundle::Registration/partial/secondFactor.html.twig' with {
17+
'type': 'sms',
18+
'security': 2,
19+
'url': path('ss_registration_sms_send_challenge')
20+
} only %}
21+
{% endif %}
22+
{% if enabledSecondFactors.tiqr is defined %}
23+
{% include 'SurfnetStepupSelfServiceSelfServiceBundle::Registration/partial/secondFactor.html.twig' with {
24+
'type': 'tiqr',
25+
'security': 2,
26+
'url': path('ss_registration_gssf_initiate', {'provider': 'tiqr'})
27+
} only %}
28+
{% endif %}
29+
{% if enabledSecondFactors.yubikey is defined %}
30+
{% include 'SurfnetStepupSelfServiceSelfServiceBundle::Registration/partial/secondFactor.html.twig' with {
31+
'type': 'yubikey',
32+
'security': 3,
33+
'url': path('ss_registration_yubikey_prove_possession')
34+
} only %}
35+
{% endif %}
3236
</div>
3337
{% endblock %}

0 commit comments

Comments
 (0)