Php 没有为“帐户”配置编码器;Collegelife\CommonBundle\Entity\Admin“;
我发现帐户“Cl\CommonBundle\Entity\Admin”没有配置编码器的问题 我还在SecurityBundle\Security\ClSecurityProvider.php中实现了ClSecurityProvider 有人能帮我解决这个问题吗?我从3-4天就被打动了。 我还没有完成自定义身份验证模块。Php 没有为“帐户”配置编码器;Collegelife\CommonBundle\Entity\Admin“;,php,symfony,Php,Symfony,我发现帐户“Cl\CommonBundle\Entity\Admin”没有配置编码器的问题 我还在SecurityBundle\Security\ClSecurityProvider.php中实现了ClSecurityProvider 有人能帮我解决这个问题吗?我从3-4天就被打动了。 我还没有完成自定义身份验证模块。 我想使用我的自定义身份验证代码。不要浪费时间对控制盘进行编码:)。。。尝试这个管理包的symfony2这是真的很好 下面是一个演示: (登录名:admin/pass:admin)
我想使用我的自定义身份验证代码。不要浪费时间对控制盘进行编码:)。。。尝试这个管理包的symfony2这是真的很好 下面是一个演示: (登录名:admin/pass:admin) 这是官方文件 我们在所有项目中都使用它,并使用fosUserBundle管理身份验证,fosUserBundle也是一个“必备”包 您有一个输入错误:
# security.yml
security:
encoders:
Cl\AdminBundle\Entity\Admin:
algorithm: sha1
encode_as_base64: false
iterations: 1
role_hierarchy:
ROLE_ADMIN: ROLE_ADMIN
providers:
cl_admin_security:
id: cl_admin_security_provider
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
admin_area:
pattern: ^/
provider: cl_admin_security
anonymous: ~
form_login:
login_path: /security
check_path: /security_check
default_target_path: /admin
username_parameter: _useremail
password_parameter: _userpassword
logout:
path: _demo_logout
target: _demo
access_control:
- { path: ^/security, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, roles: ROLE_ADMIN }
# routing.yml
_security_check:
path: /security_check
_security:
path: /security
defaults: { _controller: ClSecurityBundle:Login:index }
// Cl\CommonBundle\Entity\Admin\ClSecurityProvider.php
namespace Cl\SecurityBundle\Security;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Cl\CommonBundle\Entity\Admin;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\NoResultException;
class ClSecurityProvider implements UserProviderInterface
{
private $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
/**
* Loads the user for the given username.
*
* This method must throw UsernameNotFoundException if the user is not
* found.
*
* @throws UsernameNotFoundException if the user is not found
* @param string $username The username
*
* @return UserInterface
*/
public function loadUserByUsername($username)
{
$admin = $this->findUserBy(array("email" => $username));
if (!$admin) {
$message = sprintf(
'Unable to find an active admin ClCommonBundle:Admin object identified by "%s".', $admin
);
throw new UsernameNotFoundException($message);
}
return $admin;
}
public function refreshUser(UserInterface $admin)
{
//return $this->loadUserByUsername($admin->getUsername());
$class = get_class($admin);
if (!$this->supportsClass($class)) { //This should be $class not $user
$message = sprintf('Unsupported class type : %s', $class);
throw new UnsupportedUserException($message);
}
return $this->find($user->getId());
}
/**
* Whether this provider supports the given user class
*
* @param string $class
*
* @return Boolean
*/
public function supportsClass($class)
{
return $class == "Cl\CommonBundle\Entity\Admin";
//return $this->getEntityName() === $class || is_subclass_of($class, $this->getEntityName());
}
/**
* findUserBy
*
* @param array $criteria
*
* @return mixed
*/
protected function findUserBy(array $criteria)
{
$repository = $this->em->getRepository('Cl\CommonBundle\Entity\Admin');
return $repository->findOneBy($criteria);
}
}
应该是
encoders:
Cl\AdminBundle\Entity\Admin
我还应该指出,您的标题是“collelife\CommonBundle\Entity\Admin” 您的问题不清楚,请提供更多信息/规格我想为我的应用程序创建管理面板。因此,我使用symfony 2.3,并使用自定义用户提供程序进行身份验证。现在我得到一个错误,没有为帐户“Cl\CommonBundle\Entity\Admin”配置编码器。您可以阅读我的提供商代码security.yml、service.yml、routing.yml。现在我还包括service.yml代码……service.yml代码。参数:cl_admin_security_provider.class:cl\SecurityBundle\security\clSecurityProvider服务:cl_admin_security_provider:class:%cl_admin_security_provider.class%参数:[@doctrine.orm.entity_manager]#参数:[cl\CommonBundle\entity\admin]查尔斯谢谢您的快速回复。Hi@Dipak。我调整了你问题的格式,使其正确显示。您真的在尝试实现一个完整的自定义身份验证系统,比如:或者您只是在尝试插入您自己的UserProvider?很大的不同。是的,我提到了索纳塔和fos,但我应该尝试一次成功的创作。我很感激你的回答,但我想自己实现这些东西。@Dipak chavda Symfony2有很高的学习曲线,特别是如果你来自过程编码,并且OOP知识很差的话。因此,如果您在任何情况下都有时间对Symfony2文档(特别是安全组件)进行适当的研究,也可以使用其他人提供的一些好包。祝你好运谢谢,但我怎么知道没有试验,我得到了这个错误的配置,所以它不重要的OOPs知识,我关心的是目前的问题。我真的很感谢你的回答。
encoders:
Cl\CommonBundle\Entity\Admin