Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7659177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:17:55+00:00 2026-05-31T13:17:55+00:00

With currented build of Symfony 2.1 it should be possible to use MongoDB as

  • 0

With currented build of Symfony 2.1 it should be possible to use MongoDB as Userprovider for the SecurityBundle without using FOSUserBundle (as introduced here: mongodb symfony user authentication?).

Can’t figure out, where is actually the problem in the code, but I can’t login with the predefined user test:test.

My security.yml looks like this:

security:
    encoders:
        test\TestBundle\Document\User: plaintext
    providers:
        document_members:
            mongodb: { class: testTestBundle:User, property: username }
    firewalls:
        secured_area:
            pattern:    ^/
            http_basic:
                realm:    "Login to TEST"
    access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }
    role_hierarchy:
        ROLE_ADMIN:     ROLE_USER

The test/TestBundle/Document/User.php-Document:


namespace test\TestBundle\Document;

use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
 * @ODM\Document(collection="user", repositoryClass="test\TestBundle\Document\UserRepository")
 */
class User implements UserInterface, EquatableInterface
{

    /**
     * @ODM\Id
     */
    protected $id;

    /**
     * @ODM\String
     */
    protected $username;

    /**
     * @ODM\String
     */
    protected $password;

    /**
     * @ODM\Collection
     */
    protected $roles = array();

    /**
     * @ODM\String
     */
    protected $salt;

    /**
     * @ODM\Boolean
     */
    protected $isActive;

// Setter

    /**
     * @param String
     */
    public function setUsername($username)
    {
        $this->username = $username;
    }

    /**
     * @param String
     */
    public function setPassword($password)
    {
        $this->password = $password;
    }

    /**
     * @param String
     */
    public function setRole($role)
    {
        $this->roles[] = $role;
    }

    /**
     * @param array
     */
    public function setRoles(array $roles)
    {
        $this->roles = (array) $roles;
    }

    /**
     * @param String
     */
    public function setSalt($salt)
    {
        $this->salt = $salt;
    }

// Getter

    /**
     * @return String
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * @return String
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * @return array
     */
    public function getRoles()
    {
        return $this->roles;
    }

    /**
     * @return String
     */
    public function getSalt()
    {
        return $this->salt;
    }

// General

    public function __construct()
    {
        $this->isActive = true;
        $this->salt = '';
    }

    public function isEqualTo(UserInterface $user)
    {
        return $user->getUsername() === $this->username;
    }

    public function eraseCredentials()
    {
    }

}

the test/TestBundle/Document/UserRepository.php:

namespace test\TestBundle\Document;

use Doctrine\ODM\MongoDB\DocumentRepository;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;

class UserRepository extends DocumentRepository implements UserProviderInterface
{
    public function loadUserByUsername($username)
    {
        $q = $this->createQueryBuilder()
            ->field('username')->equals((string) $username)
            ->getQuery();

        try
        {
            $user = $q->getSingleResult();
        }
        catch (NoResultException $e)
        {
            throw new UsernameNotFoundException(sprintf('Can\'t find Username "%s"', $username), null, 0, $e);
        }

        return $user;
    }

    public function refreshUser(UserInterface $user)
    {
        $class = get_class($user);
        if (!$this->supportsClass($class)) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $class));
        }

        return $this->loadUserByUsername($user->getUsername());
    }

    public function supportsClass($class)
    {
        return $class === 'test\TestBundle\Document\User';
    }
}

The specific route:

Admin:
    pattern:  /admin
    defaults: { _controller: testTestBundle:Test:index }

(will lead to an existing controller and view)

the predefined user-Document looks like this:

Array
(
    [_id] => 4f59b5731c911ab41e001234
    [username] => test
    [password] => test
    [roles] => Array
        (
            [0] => ROLE_ADMIN
        )

    [salt] => 
    [isActive] => 1
)

But I can’t login with the username test and password test at /admin.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:17:55+00:00Added an answer on May 31, 2026 at 1:17 pm

    problem is related to an issue with using symfony on apache + fastCGI (https://github.com/symfony/symfony/pull/3551).

    Above code works as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently i have a build process in place for all of our apps using
I'm using Zend Framework for some projects and want to build up PHPUnit test
Question: Can CMake generate build scripts that do not, in any way, use CMake?
I'm trying to build a form using symfony2, but I keep getting the error
I'm working on a project using Symfony 2, I've built a bundle to handle
We currently build our Android (Java) projects using the built-in Eclipse build tools. Then
i currently build an application use spring as framework. and i want to test
I'm attempting to create a user login for Facebook and Windows LiveId using DotNetOpenAuth
I currently build all my applications with hudson using xcodebuild followed by a xcrun
I have a current build process which does a .NET build using MSBuild and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.