Giter Club home page Giter Club logo

easy-security-bundle's People

Contributors

javiereguiluz avatar kbond avatar ninsuo avatar phpdev avatar pierredup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easy-security-bundle's Issues

Proposal to add new helper methods

@ninsuo in this comment is proposing to add new methods:

<?php

namespace BaseBundle\Services;

use Doctrine\ORM\Proxy\Proxy;
use EasyCorp\Bundle\EasySecurityBundle\Security\Security as BaseSecurity;
use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\Security\Core\User\UserInterface;

class Security extends BaseSecurity
{
    use ContainerAwareTrait;

    /**
     * This method should only be used to enforce login on development
     * environment (when you don't have an internet connection for example)
     * or on demo websites where visitors can try features requiring authentication.
     *
     * @param int $id
     * 
     * @return Security
     */
    public function loginById($id)
    {
        $user = $this->container
           ->get('doctrine')
           ->getManager()
           ->getRepository('BaseBundle:User')
           ->findOneById($id);

        $this->login(
            $this->container
                ->get('base.oauth_user_provider')
                ->loadUserByUsername($user->getUsername())
        );

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function login(UserInterface $user, $firewallName = 'main')
    {
        $token = new OAuthToken(null, $user->getRoles());
        $token->setUser($this->getRealEntity($user));
        $token->setAuthenticated(true);
        $this->container->get('security.token_storage')->setToken($token);
        $this->container->get('session')->set("_security_{$firewallName}", serialize($token));
        $this->container->get('session')->save();

        return $this;
    }

    /**
     * This method is used to store a real entity and not a doctrine proxy
     * on the tokenstorage (they internally do a get_class and if the entity
     * was lazily loaded, it will be an instance of a proxy).
     *
     * @param mixed $proxy
     *
     * @return mixed
     */
    public function getRealEntity($proxy)
    {
        if ($proxy instanceof Proxy) {
            $metadata              = $this->getManager()->getMetadataFactory()->getMetadataFor(get_class($proxy));
            $class                 = $metadata->getName();
            $entity                = new $class();
            $reflectionSourceClass = new \ReflectionClass($proxy);
            $reflectionTargetClass = new \ReflectionClass($entity);
            foreach ($metadata->getFieldNames() as $fieldName) {
                $reflectionPropertySource = $reflectionSourceClass->getProperty($fieldName);
                $reflectionPropertySource->setAccessible(true);
                $reflectionPropertyTarget = $reflectionTargetClass->getProperty($fieldName);
                $reflectionPropertyTarget->setAccessible(true);
                $reflectionPropertyTarget->setValue($entity, $reflectionPropertySource->getValue($proxy));
            }

            return $entity;
        }

        return $proxy;
    }
}

He says that they are useful when:

On many dev purposes (notably when there are only hwi ways to login on disconnected envs), I required those.

Thoughts? Thanks!

RoleHierarchy instance of Session

EasyCorp\Bundle\EasySecurityBundle\Security\Security::__construct() must be an instance of Symfony\Component\Security\Core\Role\RoleHierarchy, instance of Symfony\Component\HttpFoundation\Session\Session given

symfony": "^3.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.