# 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);
}
}
我没有找到编码器的问题已配置帐户“CL \ CommonBundle \实体\管理员”。无编码器已经配置了帐户“Collegelife CommonBundle 实体管理员”
我也曾在SecurityBundle \安全\ ClsecurityProvider.php实施ClSecurityProvider
谁能帮我对这个问题我从3-4天来袭。 我还没有完成自定义验证模块。 我想使用我的自定义验证码。
你的问题还不清楚,请提供更多信息/规格 – 2014-09-11 12:15:04
我想为我的应用程序创建管理面板。所以我使用了symfony 2.3并使用自定义用户提供程序进行身份验证。现在我收到一个错误:没有编码器已被配置为账户“Cl \ CommonBundle \ Entity \ Admin”。你可以阅读我的代码provider.yml,service.yml,routing.yml。现在我包含service.yml代码也是.... – 2014-09-11 12:17:37
service.yml代码。 参数: cl_admin_security_provider.class:CL \ SecurityBundle \安全\ clSecurityProvider 服务: cl_admin_security_provider: 类:%cl_admin_security_provider.class% 参数:[@ doctrine.orm.entity_manager] #arguments:[CL \ CommonBundle \ Entity \ Admin] – 2014-09-11 12:20:32