Skip to content

Commit 2dc0980

Browse files
committed
Merge pull request #1052 from bshaffer/fixes-security-authentication-provider-cookbook-article-2.0
fixes "A Token was not found in the SecurityContext" error
2 parents f1355d2 + 0cca576 commit 2dc0980

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

cookbook/security/custom_authentication_provider.rst

+17-18
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,29 @@ set an authenticated token in the security context if successful.
116116
{
117117
$request = $event->getRequest();
118118
119-
if (!$request->headers->has('x-wsse')) {
120-
return;
121-
}
119+
if ($request->headers->has('x-wsse')) {
122120
123-
$wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/';
121+
$wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/';
124122
125-
if (preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) {
126-
$token = new WsseUserToken();
127-
$token->setUser($matches[1]);
123+
if (preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) {
124+
$token = new WsseUserToken();
125+
$token->setUser($matches[1]);
128126
129-
$token->digest = $matches[2];
130-
$token->nonce = $matches[3];
131-
$token->created = $matches[4];
127+
$token->digest = $matches[2];
128+
$token->nonce = $matches[3];
129+
$token->created = $matches[4];
132130
133-
try {
134-
$returnValue = $this->authenticationManager->authenticate($token);
131+
try {
132+
$returnValue = $this->authenticationManager->authenticate($token);
135133
136-
if ($returnValue instanceof TokenInterface) {
137-
return $this->securityContext->setToken($returnValue);
138-
} else if ($returnValue instanceof Response) {
139-
return $event->setResponse($returnValue);
134+
if ($returnValue instanceof TokenInterface) {
135+
return $this->securityContext->setToken($returnValue);
136+
} else if ($returnValue instanceof Response) {
137+
return $event->setResponse($returnValue);
138+
}
139+
} catch (AuthenticationException $e) {
140+
// you might log something here
140141
}
141-
} catch (AuthenticationException $e) {
142-
// you might log something here
143142
}
144143
}
145144

0 commit comments

Comments
 (0)