Skip to content

Commit ccf5d62

Browse files
committed
1 parent 9ff91d7 commit ccf5d62

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/DependencyInjection/Configuration.php

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public function getConfigTreeBuilder()
6868
->children()
6969
->scalarNode('server')->cannotBeEmpty()->end()
7070
->scalarNode('enabled')->defaultFalse()->end()
71+
->arrayNode('ip_white_list')
72+
->prototype('scalar')->end()
73+
->info('IPs for which 2FA will be skipped.')
74+
->setDeprecated('The "%node%" option is deprecated. Use "trusted_ip_list" instead with the same values.')
75+
->end()
7176
->arrayNode('trusted_ip_list')
7277
->prototype('scalar')->end()
7378
->defaultValue(['127.0.0.1'])

src/DependencyInjection/SonataUserExtension.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,22 @@ public function configureGoogleAuthenticator($config, ContainerBuilder $containe
174174

175175
if (!class_exists('Google\Authenticator\GoogleAuthenticator')
176176
&& !class_exists('Sonata\GoogleAuthenticator\GoogleAuthenticator')) {
177-
throw new \RuntimeException('Please add ``sonata-project/google-authenticator`` package');
177+
throw new \RuntimeException('Please add "sonata-project/google-authenticator" package');
178178
}
179179

180180
$container->setParameter('sonata.user.google.authenticator.forced_for_role', $config['google_authenticator']['forced_for_role']);
181-
$container->setParameter('sonata.user.google.authenticator.trusted_ip_list', $config['google_authenticator']['trusted_ip_list']);
181+
182+
// NEXT_MAJOR: Remove this checks and only set the `trusted_ip_list`.
183+
if (\count($config['google_authenticator']['ip_white_list']) > 0 && $config['google_authenticator']['trusted_ip_list'] !== ['127.0.0.1']) {
184+
throw new \LogicException('Please use only "trusted_ip_list" parameter, "ip_white_list" is deprecated.');
185+
}
186+
$trustedIpList = $config['google_authenticator']['trusted_ip_list'];
187+
if (\count($config['google_authenticator']['ip_white_list']) > 0) {
188+
$trustedIpList = $config['google_authenticator']['ip_white_list'];
189+
}
190+
// NEXT_MAJOR: Remove `sonata.user.google.authenticator.ip_white_list` parameter.
191+
$container->setParameter('sonata.user.google.authenticator.ip_white_list', $trustedIpList);
192+
$container->setParameter('sonata.user.google.authenticator.trusted_ip_list', $trustedIpList);
182193

183194
$container->getDefinition('sonata.user.google.authenticator.provider')
184195
->replaceArgument(0, $config['google_authenticator']['server']);

tests/DependencyInjection/ConfigurationTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function testDefault(): void
4242
],
4343
'google_authenticator' => [
4444
'enabled' => false,
45+
'ip_white_list' => [],
4546
'trusted_ip_list' => ['127.0.0.1'],
4647
'forced_for_role' => ['ROLE_ADMIN'],
4748
],

0 commit comments

Comments
 (0)