Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 456e558

Browse files
committed
bug #16493 [Security] Renamed key to secret Part 2 (WouterJ)
This PR was merged into the 2.8 branch. Discussion ---------- [Security] Renamed key to secret Part 2 Anonymous and RememberMe were already changed in #15141 This PR renames 2 more occurences of key in the Security: AnonymousAuthenticationListener and the Digest entry point. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 55f59d5 Renamed key to secret
2 parents 7c0b9b6 + 55f59d5 commit 456e558

File tree

11 files changed

+63
-28
lines changed

11 files changed

+63
-28
lines changed

UPGRADE-3.0.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,8 @@ UPGRADE FROM 2.x to 3.0
601601

602602
* The `Resources/` directory was moved to `Core/Resources/`
603603

604-
* The `key` settings of `anonymous` and `remember_me` are renamed to `secret`.
604+
* The `key` settings of `anonymous`, `remember_me` and `http_digest` are
605+
renamed to `secret`.
605606

606607
Before:
607608

@@ -614,6 +615,8 @@ UPGRADE FROM 2.x to 3.0
614615
anonymous: { key: "%secret%" }
615616
remember_me:
616617
key: "%secret%"
618+
http_digest:
619+
key: "%secret%"
617620
```
618621

619622
```xml
@@ -626,6 +629,7 @@ UPGRADE FROM 2.x to 3.0
626629
627630
<anonymous key="%secret%"/>
628631
<remember-me key="%secret%"/>
632+
<http-digest key="%secret%"/>
629633
</firewall>
630634
</config>
631635
```
@@ -638,6 +642,7 @@ UPGRADE FROM 2.x to 3.0
638642
// ...
639643
'anonymous' => array('key' => '%secret%'),
640644
'remember_me' => array('key' => '%secret%'),
645+
'http_digest' => array('key' => '%secret%'),
641646
),
642647
));
643648
```
@@ -653,6 +658,8 @@ UPGRADE FROM 2.x to 3.0
653658
anonymous: { secret: "%secret%" }
654659
remember_me:
655660
secret: "%secret%"
661+
http_digest:
662+
secret: "%secret%"
656663
```
657664

658665
```xml
@@ -665,6 +672,7 @@ UPGRADE FROM 2.x to 3.0
665672
666673
<anonymous secret="%secret%"/>
667674
<remember-me secret="%secret%"/>
675+
<http-digest secret="%secret%"/>
668676
</firewall>
669677
</config>
670678
```
@@ -677,6 +685,7 @@ UPGRADE FROM 2.x to 3.0
677685
// ...
678686
'anonymous' => array('secret' => '%secret%'),
679687
'remember_me' => array('secret' => '%secret%'),
688+
'http_digest' => array('secret' => '%secret%'),
680689
),
681690
));
682691
```

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ CHANGELOG
44
2.8.0
55
-----
66

7-
* deprecated the `key` setting of `anonymous` and `remember_me` in favor of the
8-
`secret` setting.
7+
* deprecated the `key` setting of `anonymous`, `remember_me` and `http_digest`
8+
in favor of the `secret` setting.
99

1010
2.6.0
1111
-----

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,26 @@ public function getKey()
5858
public function addConfiguration(NodeDefinition $node)
5959
{
6060
$node
61+
->beforeNormalization()
62+
->ifTrue(function ($v) { return isset($v['key']); })
63+
->then(function ($v) {
64+
if (isset($v['secret'])) {
65+
throw new \LogicException('Cannot set both key and secret options for http_digest, use only secret instead.');
66+
}
67+
68+
@trigger_error('http_digest.key is deprecated since version 2.8 and will be removed in 3.0. Use http_digest.secret instead.', E_USER_DEPRECATED);
69+
70+
$v['secret'] = $v['key'];
71+
72+
unset($v['key']);
73+
74+
return $v;
75+
})
76+
->end()
6177
->children()
6278
->scalarNode('provider')->end()
6379
->scalarNode('realm')->defaultValue('Secured Area')->end()
64-
->scalarNode('key')->isRequired()->cannotBeEmpty()->end()
80+
->scalarNode('secret')->isRequired()->cannotBeEmpty()->end()
6581
->end()
6682
;
6783
}
@@ -76,7 +92,7 @@ protected function createEntryPoint($container, $id, $config, $defaultEntryPoint
7692
$container
7793
->setDefinition($entryPointId, new DefinitionDecorator('security.authentication.digest_entry_point'))
7894
->addArgument($config['realm'])
79-
->addArgument($config['key'])
95+
->addArgument($config['secret'])
8096
;
8197

8298
return $entryPointId;

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
'simple' => array('pattern' => '/login', 'security' => false),
6565
'secure' => array('stateless' => true,
6666
'http_basic' => true,
67-
'http_digest' => array('key' => 'TheKey'),
67+
'http_digest' => array('secret' => 'TheSecret'),
6868
'form_login' => true,
6969
'anonymous' => true,
7070
'switch_user' => true,

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
<firewall name="secure" stateless="true">
5151
<http-basic />
52-
<http-digest key="TheKey" />
52+
<http-digest secret="TheSecret" />
5353
<form-login />
5454
<anonymous />
5555
<switch-user />

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ security:
4747
stateless: true
4848
http_basic: true
4949
http_digest:
50-
key: TheKey
50+
secret: TheSecret
5151
form_login: true
5252
anonymous: true
5353
switch_user: true

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ CHANGELOG
44
2.8.0
55
-----
66

7-
* deprecated `getKey()` of the `AnonymousToken`, `RememberMeToken` and `AbstractRememberMeServices` classes
8-
in favor of `getSecret()`.
7+
* deprecated `getKey()` of the `AnonymousToken`, `RememberMeToken`,
8+
`AbstractRememberMeServices` and `DigestAuthenticationEntryPoint` classes in favor of `getSecret()`.
99
* deprecated `Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface`, use
1010
`Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface` instead
1111
* deprecated `Symfony\Component\Security\Core\Authentication\SimpleFormAuthenticatorInterface`, use

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testAuthenticateWhenTokenIsNotSupported()
3333
/**
3434
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
3535
*/
36-
public function testAuthenticateWhenKeyIsNotValid()
36+
public function testAuthenticateWhenSecretIsNotValid()
3737
{
3838
$provider = $this->getProvider('foo');
3939

@@ -48,19 +48,19 @@ public function testAuthenticate()
4848
$this->assertSame($token, $provider->authenticate($token));
4949
}
5050

51-
protected function getSupportedToken($key)
51+
protected function getSupportedToken($secret)
5252
{
5353
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken', array('getSecret'), array(), '', false);
5454
$token->expects($this->any())
5555
->method('getSecret')
56-
->will($this->returnValue($key))
56+
->will($this->returnValue($secret))
5757
;
5858

5959
return $token;
6060
}
6161

62-
protected function getProvider($key)
62+
protected function getProvider($secret)
6363
{
64-
return new AnonymousAuthenticationProvider($key);
64+
return new AnonymousAuthenticationProvider($secret);
6565
}
6666
}

src/Symfony/Component/Security/Http/EntryPoint/DigestAuthenticationEntryPoint.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
*/
2525
class DigestAuthenticationEntryPoint implements AuthenticationEntryPointInterface
2626
{
27-
private $key;
27+
private $secret;
2828
private $realmName;
2929
private $nonceValiditySeconds;
3030
private $logger;
3131

32-
public function __construct($realmName, $key, $nonceValiditySeconds = 300, LoggerInterface $logger = null)
32+
public function __construct($realmName, $secret, $nonceValiditySeconds = 300, LoggerInterface $logger = null)
3333
{
3434
$this->realmName = $realmName;
35-
$this->key = $key;
35+
$this->secret = $secret;
3636
$this->nonceValiditySeconds = $nonceValiditySeconds;
3737
$this->logger = $logger;
3838
}
@@ -43,7 +43,7 @@ public function __construct($realmName, $key, $nonceValiditySeconds = 300, Logge
4343
public function start(Request $request, AuthenticationException $authException = null)
4444
{
4545
$expiryTime = microtime(true) + $this->nonceValiditySeconds * 1000;
46-
$signatureValue = md5($expiryTime.':'.$this->key);
46+
$signatureValue = md5($expiryTime.':'.$this->secret);
4747
$nonceValue = $expiryTime.':'.$signatureValue;
4848
$nonceValueBase64 = base64_encode($nonceValue);
4949

@@ -65,11 +65,21 @@ public function start(Request $request, AuthenticationException $authException =
6565
}
6666

6767
/**
68-
* @return string
68+
* @deprecated Since version 2.8, to be removed in 3.0. Use getSecret() instead.
6969
*/
7070
public function getKey()
7171
{
72-
return $this->key;
72+
@trigger_error(__method__.'() is deprecated since version 2.8 and will be removed in 3.0. Use getSecret() instead.', E_USER_DEPRECATED);
73+
74+
return $this->getSecret();
75+
}
76+
77+
/**
78+
* @return string
79+
*/
80+
public function getSecret()
81+
{
82+
return $this->secret;
7383
}
7484

7585
/**

src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
class AnonymousAuthenticationListener implements ListenerInterface
2828
{
2929
private $tokenStorage;
30-
private $key;
30+
private $secret;
3131
private $authenticationManager;
3232
private $logger;
3333

34-
public function __construct(TokenStorageInterface $tokenStorage, $key, LoggerInterface $logger = null, AuthenticationManagerInterface $authenticationManager = null)
34+
public function __construct(TokenStorageInterface $tokenStorage, $secret, LoggerInterface $logger = null, AuthenticationManagerInterface $authenticationManager = null)
3535
{
3636
$this->tokenStorage = $tokenStorage;
37-
$this->key = $key;
37+
$this->secret = $secret;
3838
$this->authenticationManager = $authenticationManager;
3939
$this->logger = $logger;
4040
}
@@ -51,7 +51,7 @@ public function handle(GetResponseEvent $event)
5151
}
5252

5353
try {
54-
$token = new AnonymousToken($this->key, 'anon.', array());
54+
$token = new AnonymousToken($this->secret, 'anon.', array());
5555
if (null !== $this->authenticationManager) {
5656
$token = $this->authenticationManager->authenticate($token);
5757
}

src/Symfony/Component/Security/Http/Tests/EntryPoint/DigestAuthenticationEntryPointTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testStart()
2323

2424
$authenticationException = new AuthenticationException('TheAuthenticationExceptionMessage');
2525

26-
$entryPoint = new DigestAuthenticationEntryPoint('TheRealmName', 'TheKey');
26+
$entryPoint = new DigestAuthenticationEntryPoint('TheRealmName', 'TheSecret');
2727
$response = $entryPoint->start($request, $authenticationException);
2828

2929
$this->assertEquals(401, $response->getStatusCode());
@@ -34,7 +34,7 @@ public function testStartWithNoException()
3434
{
3535
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
3636

37-
$entryPoint = new DigestAuthenticationEntryPoint('TheRealmName', 'TheKey');
37+
$entryPoint = new DigestAuthenticationEntryPoint('TheRealmName', 'TheSecret');
3838
$response = $entryPoint->start($request);
3939

4040
$this->assertEquals(401, $response->getStatusCode());
@@ -47,7 +47,7 @@ public function testStartWithNonceExpiredException()
4747

4848
$nonceExpiredException = new NonceExpiredException('TheNonceExpiredExceptionMessage');
4949

50-
$entryPoint = new DigestAuthenticationEntryPoint('TheRealmName', 'TheKey');
50+
$entryPoint = new DigestAuthenticationEntryPoint('TheRealmName', 'TheSecret');
5151
$response = $entryPoint->start($request, $nonceExpiredException);
5252

5353
$this->assertEquals(401, $response->getStatusCode());

0 commit comments

Comments
 (0)