8000 [Security] Renamed key to secret Part 2 by wouterj · Pull Request #16493 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security] Renamed key to secret Part 2 #16493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion UPGRADE-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@ UPGRADE FROM 2.x to 3.0

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

* The `key` settings of `anonymous` and `remember_me` are renamed to `secret`.
* The `key` settings of `anonymous`, `remember_me` and `http_digest` are
renamed to `secret`.

Before:

Expand All @@ -614,6 +615,8 @@ UPGRADE FROM 2.x to 3.0
anonymous: { key: "%secret%" }
remember_me:
key: "%secret%"
http_digest:
key: "%secret%"
```

```xml
Expand All @@ -626,6 +629,7 @@ UPGRADE FROM 2.x to 3.0

<anonymous key="%secret%"/>
<remember-me key="%secret%"/>
<http-digest key="%secret%"/>
</firewall>
</config>
```
Expand All @@ -638,6 +642,7 @@ UPGRADE FROM 2.x to 3.0
// ...
'anonymous' => array('key' => '%secret%'),
'remember_me' => array('key' => '%secret%'),
'http_digest' => array('key' => '%secret%'),
),
));
```
Expand All @@ -653,6 +658,8 @@ UPGRADE FROM 2.x to 3.0
anonymous: { secret: "%secret%" }
remember_me:
secret: "%secret%"
http_digest:
secret: "%secret%"
```

```xml
Expand All @@ -665,6 +672,7 @@ UPGRADE FROM 2.x to 3.0

<anonymous secret="%secret%"/>
<remember-me secret="%secret%"/>
<http-digest secret="%secret%"/>
</firewall>
</config>
```
Expand All @@ -677,6 +685,7 @@ UPGRADE FROM 2.x to 3.0
// ...
'anonymous' => array('secret' => '%secret%'),
'remember_me' => array('secret' => '%secret%'),
'http_digest' => array('secret' => '%secret%'),
),
));
```
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/SecurityBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ CHANGELOG
2.8.0
-----

* deprecated the `key` setting of `anonymous` and `remember_me` in favor of the
`secret` setting.
* deprecated the `key` setting of `anonymous`, `remember_me` and `http_digest`
in favor of the `secret` setting.

2.6.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,26 @@ public function getKey()
public function addConfiguration(NodeDefinition $node)
{
$node
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['key']); })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_key_exist may be better, to acount for null values (otherwise they would not trigger the BC layer and then be reported as invalid keys).
I'm not sure it is necessary for this particular case though, as empty values are not allowed for the secret, and so no existing (working) project can have null in this setting. But we may need to check other places

->then(function ($v) {
if (isset($v['secret'])) {
throw new \LogicException('Cannot set both key and secret options for http_digest, use only secret instead.');
}

@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);

$v['secret'] = $v['key'];

unset($v['key']);

return $v;
})
->end()
->children()
->scalarNode('provider')->end()
->scalarNode('realm')->defaultValue('Secured Area')->end()
->scalarNode('key')->isRequired()->cannotBeEmpty()->end()
->scalarNode('secret')->isRequired()->cannotBeEmpty()->end()
->end()
;
}
Expand All @@ -76,7 +92,7 @@ protected function createEntryPoint($container, $id, $config, $defaultEntryPoint
$container
->setDefinition($entryPointId, new DefinitionDecorator('security.authentication.digest_entry_point'))
->addArgument($config['realm'])
->addArgument($config['key'])
->addArgument($config['secret'])
;

return $entryPointId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
'simple' => array('pattern' => '/login', 'security' => false),
'secure' => array('stateless' => true,
'http_basic' => true,
'http_digest' => array('key' => 'TheKey'),
'http_digest' => array('secret' => 'TheSecret'),
'form_login' => true,
'anonymous' => true,
'switch_user' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<firewall name="secure" stateless="true">
<http-basic />
<http-digest key="TheKey" />
<http-digest secret="TheSecret" />
<form-login />
<anonymous />
<switch-user />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ security:
stateless: true
http_basic: true
http_digest:
key: TheKey
secret: TheSecret
form_login: true
anonymous: true
switch_user: true
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Security/CHANGELOG.md
F438
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ CHANGELOG
2.8.0
-----

* deprecated `getKey()` of the `AnonymousToken`, `RememberMeToken` and `AbstractRememberMeServices` classes
in favor of `getSecret()`.
* deprecated `getKey()` of the `AnonymousToken`, `RememberMeToken`,
`AbstractRememberMeServices` and `DigestAuthenticationEntryPoint` classes in favor of `getSecret()`.
* deprecated `Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface`, use
`Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface` instead
* deprecated `Symfony\Component\Security\Core\Authentication\SimpleFormAuthenticatorInterface`, use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testAuthenticateWhenTokenIsNotSupported()
/**
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
*/
public function testAuthenticateWhenKeyIsNotValid()
public function testAuthenticateWhenSecretIsNotValid()
{
$provider = $this->getProvider('foo');

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

protected function getSupportedToken($key)
protected function getSupportedToken($secret)
{
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken', array('getSecret'), array(), '', false);
$token->expects($this->any())
->method('getSecret')
->will($this->returnValue($key))
->will($this->returnValue($secret))
;

return $token;
}

protected function getProvider($key)
protected function getProvider($secret)
{
return new AnonymousAuthenticationProvider($key);
return new AnonymousAuthenticationProvider($secret);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
*/
class DigestAuthenticationEntryPoint implements AuthenticationEntryPointInterface
{
private $key;
private $secret;
private $realmName;
private $nonceValiditySeconds;
private $logger;

public function __construct($realmName, $key, $nonceValiditySeconds = 300, LoggerInterface $logger = null)
public function __construct($realmName, $secret, $nonceValiditySeconds = 300, LoggerInterface $logger = null)
{
$this->realmName = $realmName;
$this->key = $key;
$this->secret = $secret;
$this->nonceValiditySeconds = $nonceValiditySeconds;
$this->logger = $logger;
}
Expand All @@ -43,7 +43,7 @@ public function __construct($realmName, $key, $nonceValiditySeconds = 300, Logge
public function start(Request $request, AuthenticationException $authException = null)
{
$expiryTime = microtime(true) + $this->nonceValiditySeconds * 1000;
$signatureValue = md5($expiryTime.':'.$this->key);
$signatureValue = md5($expiryTime.':'.$this->secret);
$nonceValue = $expiryTime.':'.$signatureValue;
$nonceValueBase64 = base64_encode($nonceValue);

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

/**
* @return string
* @deprecated Since version 2.8, to be removed in 3.0. Use getSecret() instead.
*/
public function getKey()
{
return $this->key;
@trigger_error(__method__.'() is deprecated since version 2.8 and will be removed in 3.0. Use getSecret() instead.', E_USER_DEPRECATED);

return $this->getSecret();
}

/**
* @return string
*/
public function getSecret()
{
return $this->secret;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
class AnonymousAuthenticationListener implements ListenerInterface
{
private $tokenStorage;
private $key;
private $secret;
private $authenticationManager;
private $logger;

public function __construct(TokenStorageInterface $tokenStorage, $key, LoggerInterface $logger = null, AuthenticationManagerInterface $authenticationManager = null)
public function __construct(TokenStorageInterface $tokenStorage, $secret, LoggerInterface $logger = null, AuthenticationManagerInterface $authenticationManager = null)
{
$this->tokenStorage = $tokenStorage;
$this->key = $key;
$this->secret = $secret;
$this->authenticationManager = $authenticationManager;
$this->logger = $logger;
}
Expand All @@ -51,7 +51,7 @@ public function handle(GetResponseEvent $event)
}

try {
$token = new AnonymousToken($this->key, 'anon.', array());
$token = new AnonymousToken($this->secret, 'anon.', array());
if (null !== $this->authenticationManager) {
$token = $this->authenticationManager->authenticate($token);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testStart()

$authenticationException = new AuthenticationException('TheAuthenticationExceptionMessage');

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

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

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

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

$nonceExpiredException = new NonceExpiredException('TheNonceExpiredExceptionMessage');

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

$this->assertEquals(401, $response->getStatusCode());
Expand Down
0