Skip to content

Commit 5b298ad

Browse files
committed
Make it possible to use the publish workflow checker when no security is defined at all. fix #104
1 parent bada6d7 commit 5b298ad

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

PublishWorkflow/PublishWorkflowChecker.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ public function __construct(ContainerInterface $container, AccessDecisionManager
9797
*/
9898
public function getToken()
9999
{
100-
if (null === $this->token) {
101-
$securityContext = $this->container->get('security.context');
102-
103-
return $securityContext->getToken();
100+
if (null === $this->token && $this->container->has('security.context')) {
101+
return $this->container->get('security.context')->getToken();
104102
}
105103

106104
return $this->token;
@@ -135,21 +133,19 @@ public function isGranted($attributes, $object = null)
135133
$attributes = array($attributes);
136134
}
137135

138-
$securityContext = $this->container->get('security.context');
139-
140-
if (null !== $securityContext->getToken()
141-
&& (count($attributes) === 1)
136+
if ((count($attributes) === 1)
142137
&& self::VIEW_ATTRIBUTE === reset($attributes)
143-
&& $securityContext->isGranted($this->bypassingRole)
138+
&& $this->container->has('security.context')
139+
&& null !== $this->container->get('security.context')->getToken()
140+
&& $this->container->get('security.context')->isGranted($this->bypassingRole)
144141
) {
145142
return true;
146143
}
147144

148145
$token = $this->getToken();
149-
if (null === $token) {
150-
// not logged in, surely we can not skip the check.
151-
// create a dummy token to check for publication even if no
152-
// firewall is present.
146+
147+
// not logged in, just check with a dummy token
148+
if (!$token) {
153149
$token = new AnonymousToken('', '');
154150
}
155151

0 commit comments

Comments
 (0)