我正在为使用API密钥写一个自定义身份验证提供程序。我现在主要工作,但有一件事让我感到困惑。我已经找到了创建这个行为到Symfony的部分:在Symfony2中,为什么完全通过身份验证的用户也进行了匿名身份验证?
供应商/ symfony中/ symfony中/ src目录/ Symfony的/分量/安全/核心/授权/选民/ AuthenticatedVoter.php:
/**
* {@inheritdoc}
*/
public function vote(TokenInterface $token, $object, array $attributes)
{
$result = VoterInterface::ACCESS_ABSTAIN;
foreach ($attributes as $attribute) {
if (!$this->supportsAttribute($attribute)) {
continue;
}
$result = VoterInterface::ACCESS_DENIED;
if (self::IS_AUTHENTICATED_FULLY === $attribute
&& $this->authenticationTrustResolver->isFullFledged($token)) {
return VoterInterface::ACCESS_GRANTED;
}
if (self::IS_AUTHENTICATED_REMEMBERED === $attribute
&& ($this->authenticationTrustResolver->isRememberMe($token)
|| $this->authenticationTrustResolver->isFullFledged($token))) {
return VoterInterface::ACCESS_GRANTED;
}
if (self::IS_AUTHENTICATED_ANONYMOUSLY === $attribute
&& ($this->authenticationTrustResolver->isAnonymous($token)
|| $this->authenticationTrustResolver->isRememberMe($token)
|| $this->authenticationTrustResolver->isFullFledged($token))) {
return VoterInterface::ACCESS_GRANTED;
}
}
return $result;
}
为什么在最后一节中提到“如果你完全认证了,或者记住了你也是匿名登录的”?当然,如果你是匿名登录的,那么你并不完全成熟,或者反之亦然。
我试图解决这个问题的原因是因为我有一个我的API的防火墙部分,你传递一个用户名和密码,以便从那时起创建一个用于身份验证的令牌。如果您尚未使用API密钥进行身份验证,即如果用户“已注销”(无状态),我只希望此区域可以访问。
我该如何实现这种行为?
不完全是我真的以后。我可以发现用户是否以特定的方式足够简单地被认证。 Symfony似乎分配权限的方式似乎很奇怪。完全验证应该意味着你不是匿名的,但在Symfony中你是默认的。 – Seer