1
votes

I have a Symfony 2 application installed and I'm trying to use the security bundle and a user entity to deal with the login. When I try yo view the /about page I get redirected to the login page and then after I login with the correct information I get redirected right back to the login page. I know I entered in the right info that is stored in the database because if I enter in the wrong stuff I get an invalid password error on the login page. Also, when I look at the logs, the query to find the username has no parameters passed to it. Any ideas?

security.yml

security:
    encoders:
        Company\Project\Entity\User: 
            algorithm: sha512
            encode-as-base64: true

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        main:
            entity: { class: Company\Project\Entity\User}

    firewalls:
        main:
            pattern:    ^/
            form_login:
                check_path: /login_check
                login_path: /login

            logout:
                path:   /logout
                target: /
            anonymous: ~

    access_control:
        - { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https}
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
        - { path: ^/about, roles: ROLE_ADMIN, requires_channel: https }
1

1 Answers

2
votes

Nvm I figured it out. I had to implement Serializable on my user entity.

public function serialize()  
{  
    return serialize(array(  
        'username'        => $this->getUsername(),  
        'password'       => $this->getPassword(),  
        'salt'       => $this->getSalt(),  
        'roles'  => $this->getRoles()  
    ));  
} 

public function unserialize($serializedData)  
{  
    $unserializedData     = unserialize($serializedData);  

    $this->setUsername(isset($unserializedData['username']) ? $unserializedData['username'] : null);  
    $this->setPassword(isset($unserializedData['password']) ? $unserializedData['password'] : null);  
    $this->setSalt(isset($unserializedData['salt']) ? $unserializedData['salt'] : null);  
}