replace the authentication layer and user entity in sylius

725 views Asked by At

I have created a symfony2 project and custom Authentication Provider (http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html) is used. my new task is to create an E-commerce application in sylius which should work alongside with my current symfony2 project. i want to make my current user table in symfony2 project as user provider in sylius...is it possible to create such project..... since fosUserBundle and fosOauthServer bundel are installed in sylius how can i override these bundles with my custom authentication mechanism

My symfony2 project configurations are mentioned below

I tried the following in security.yml

 security:
     encoders:
         AppBundle\Entity\Users:
             algorithm: bcrypt

    providers:
        our_db_provider:
            entity:
                class: AppBundle:Users

        api_key_user_provider:
            id: api_key_user_provider


    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt|error)|css|images|js)/
            security: false

        api:
            pattern: ^/api
            stateless: true
            simple_preauth:
                authenticator: apikey_authenticator
            provider: api_key_user_provider    

        web:
            anonymous: ~
            http_basic: ~
            provider: our_db_provider
            form_login:
                login_path: /login
                check_path: /login_check

this is my user class

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * Users
 *
 * @ORM\Table(name="users", uniqueConstraints=  {@ORM\UniqueConstraint(name="users_user_name_unique", columns={"user_name"}),   @ORM\UniqueConstraint(name="users_xmpp_password_unique", columns=  {"xmpp_password"})})
 * @ORM\Entity(repositoryClass="AppBundle\Entity\UsersRepository")
 */


class Users implements UserInterface, \Serializable {

/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer", nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $id;

/**
 * @var integer
 *
 * @ORM\Column(name="parent_id", type="integer", nullable=false)
 */
private $parentId;

/**
 * @var string
 *
 * @ORM\Column(name="first_name", type="string", length=100, nullable=false)
 */
private $firstName;

/**
 * @var string
 *
 * @ORM\Column(name="last_name", type="string", length=100, nullable=false)
 */
private $lastName;

/**
 * @var string
 *
 * @ORM\Column(name="user_name", type="string", length=120, nullable=false)
 */
private $userName;

/**
 * @var string
 *
 * @ORM\Column(name="reg_type", type="string", length=20, nullable=false)
 */
private $regType;

/**
 * @var string
 *
 * @ORM\Column(name="oauth_uid", type="string", length=255, nullable=false)
 */
private $oauthUid;

/**
 * @var boolean
 *
 * @ORM\Column(name="active", type="boolean", nullable=false)
 */
private $active;

/**
 * @var string
 *
 * @ORM\Column(name="email", type="string", length=100, nullable=false)
 */
private $email;

/**
 * @var string
 *
 * @ORM\Column(name="password", type="string", length=150, nullable=false)
 */
private $password;

/**
 * @var string
 *
 * @ORM\Column(name="xmpp_password", type="string", length=20, nullable=false)
 */
private $xmppPassword;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="created_at", type="datetime", nullable=false)
 */
private $createdAt = '0000-00-00 00:00:00';

/**
 * @var \DateTime
 *
 * @ORM\Column(name="updated_at", type="datetime", nullable=false)
 */
private $updatedAt = '0000-00-00 00:00:00';

/**
 * @var \DateTime
 *
 * @ORM\Column(name="deleted_at", type="datetime", nullable=true)
 */
private $deletedAt;

/**
 * @var string
 *
 * @ORM\Column(name="activation_code", type="string", length=50, nullable=true)
 */
private $activationCode;

/**
 * @var string
 *
 * @ORM\Column(name="user_profile_pic", type="string", length=200, nullable=false)
 */
private $userProfilePic = 'uploads/defaults/user/profile_pic.jpg';

/**
 * @var string
 *
 * @ORM\Column(name="user_timeline_pic", type="string", length=200, nullable=false)
 */
private $userTimelinePic = 'uploads/defaults/user/timeline_pic.jpg';

/**
 * @var string
 *
 * @ORM\Column(name="country", type="string", length=50, nullable=false)
 */
private $country;

/**
 * @var string
 *
 * @ORM\Column(name="state", type="string", length=50, nullable=false)
 */
private $state;

/**
 * @var string
 *
 * @ORM\Column(name="city", type="string", length=50, nullable=false)
 */
private $city;

/**
 * @var string
 *
 * @ORM\Column(name="hobbies", type="string", length=100, nullable=false)
 */
private $hobbies;

/**
 * @var string
 *
 * @ORM\Column(name="interests", type="string", length=100, nullable=false)
 */
private $interests;

/**
 * @var string
 *
 * @ORM\Column(name="about", type="string", length=500, nullable=false)
 */
private $about;

/**
 * @var boolean
 *
 * @ORM\Column(name="gender", type="boolean", nullable=false)
 */
private $gender;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="dob", type="date", nullable=false)
 */
private $dob;

/**
 * @var integer
 *
 * @ORM\Column(name="quickblox_id", type="integer", nullable=false)
 */
private $quickbloxId;

/**
 * @var boolean
 *
 * @ORM\Column(name="privacy", type="boolean", nullable=false)
 */
private $privacy = '0';

/**
 * @var string
 *
 * @ORM\Column(name="school", type="string", length=255, nullable=false)
 */
private $school;

/**
 * @var string
 *
 * @ORM\Column(name="college", type="string", length=255, nullable=false)
 */
private $college;

/**
 * @var string
 *
 * @ORM\Column(name="work", type="string", length=255, nullable=false)
 */
private $work;

/**
 * @var string
 *
 * @ORM\Column(name="relationship_status", type="string", length=50, nullable=false)
 */
private $relationshipStatus;



public function getSalt() {
    // you *may* need a real salt depending on your encoder
    // see section on salt below
    return null;
}



public function getRoles() {
    return array('ROLE_API');
}

public function eraseCredentials() {

}

/** @see \Serializable::serialize() */
public function serialize() {
    return serialize(array(
        $this->id,
        $this->email,
            // see section on salt below
            // $this->salt,
    ));
}

/** @see \Serializable::unserialize() */
public function unserialize($serialized) {
    list (
            $this->id,
            $this->email,
            // see section on salt below
            // $this->salt
            ) = unserialize($serialized);
}

/**
 * Get id
 *
 * @return integer 
 */
public function getId() {
    return $this->id;
}

/**
 * Set parentId
 *
 * @param integer $parentId
 * @return Users
 */
public function setParentId($parentId) {
    $this->parentId = $parentId;

    return $this;
}

/**
 * Get parentId
 *
 * @return integer 
 */
public function getParentId() {
    return $this->parentId;
}

/**
 * Set firstName
 *
 * @param string $firstName
 * @return Users
 */
public function setFirstName($firstName) {
    $this->firstName = $firstName;

    return $this;
}

/**
 * Get firstName
 *
 * @return string 
 */
public function getFirstName() {
    return $this->firstName;
}

/**
 * Set lastName
 *
 * @param string $lastName
 * @return Users
 */
public function setLastName($lastName) {
    $this->lastName = $lastName;

    return $this;
}

/**
 * Get lastName
 *
 * @return string 
 */
public function getLastName() {
    return $this->lastName;
}

/**
 * Set userName
 *
 * @param string $userName
 * @return Users
 */
public function setUserName($userName) {
    $this->userName = $userName;

    return $this;
}

/**
 * Get userName
 *
 * @return string 
 */
public function getUserName() {
    return $this->email;
}

/**
 * Set regType
 *
 * @param string $regType
 * @return Users
 */
public function setRegType($regType) {
    $this->regType = $regType;

    return $this;
}

/**
 * Get regType
 *
 * @return string 
 */
public function getRegType() {
    return $this->regType;
}

/**
 * Set oauthUid
 *
 * @param string $oauthUid
 * @return Users
 */
public function setOauthUid($oauthUid) {
    $this->oauthUid = $oauthUid;

    return $this;
}

/**
 * Get oauthUid
 *
 * @return string 
 */
public function getOauthUid() {
    return $this->oauthUid;
}

/**
 * Set active
 *
 * @param boolean $active
 * @return Users
 */
public function setActive($active) {
    $this->active = $active;

    return $this;
}

/**
 * Get active
 *
 * @return boolean 
 */
public function getActive() {
    return $this->active;
}

/**
 * Set email
 *
 * @param string $email
 * @return Users
 */
public function setEmail($email) {
    $this->email = $email;

    return $this;
}

/**
 * Get email
 *
 * @return string 
 */
public function getEmail() {
    return $this->email;
}

/**
 * Set password
 *
 * @param string $password
 * @return Users
 */
public function setPassword($password) {
    $this->password = $password;

    return $this;
}

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

/**
 * Set xmppPassword
 *
 * @param string $xmppPassword
 * @return Users
 */
public function setXmppPassword($xmppPassword) {
    $this->xmppPassword = $xmppPassword;

    return $this;
}

/**
 * Get xmppPassword
 *
 * @return string 
 */
public function getXmppPassword() {
    return $this->xmppPassword;
}

/**
 * Set createdAt
 *
 * @param \DateTime $createdAt
 * @return Users
 */
public function setCreatedAt($createdAt) {
    $this->createdAt = $createdAt;

    return $this;
}

/**
 * Get createdAt
 *
 * @return \DateTime 
 */
public function getCreatedAt() {
    return $this->createdAt;
}

/**
 * Set updatedAt
 *
 * @param \DateTime $updatedAt
 * @return Users
 */
public function setUpdatedAt($updatedAt) {
    $this->updatedAt = $updatedAt;

    return $this;
}

/**
 * Get updatedAt
 *
 * @return \DateTime 
 */
public function getUpdatedAt() {
    return $this->updatedAt;
}

/**
 * Set deletedAt
 *
 * @param \DateTime $deletedAt
 * @return Users
 */
public function setDeletedAt($deletedAt) {
    $this->deletedAt = $deletedAt;

    return $this;
}

/**
 * Get deletedAt
 *
 * @return \DateTime 
 */
public function getDeletedAt() {
    return $this->deletedAt;
}

/**
 * Set activationCode
 *
 * @param string $activationCode
 * @return Users
 */
public function setActivationCode($activationCode) {
    $this->activationCode = $activationCode;

    return $this;
}

/**
 * Get activationCode
 *
 * @return string 
 */
public function getActivationCode() {
    return $this->activationCode;
}

/**
 * Set userProfilePic
 *
 * @param string $userProfilePic
 * @return Users
 */
public function setUserProfilePic($userProfilePic) {
    $this->userProfilePic = $userProfilePic;

    return $this;
}

/**
 * Get userProfilePic
 *
 * @return string 
 */
public function getUserProfilePic() {
    return $this->userProfilePic;
}

/**
 * Set userTimelinePic
 *
 * @param string $userTimelinePic
 * @return Users
 */
public function setUserTimelinePic($userTimelinePic) {
    $this->userTimelinePic = $userTimelinePic;

    return $this;
}

/**
 * Get userTimelinePic
 *
 * @return string 
 */
public function getUserTimelinePic() {
    return $this->userTimelinePic;
}

/**
 * Set country
 *
 * @param string $country
 * @return Users
 */
public function setCountry($country) {
    $this->country = $country;

    return $this;
}

/**
 * Get country
 *
 * @return string 
 */
public function getCountry() {
    return $this->country;
}

/**
 * Set state
 *
 * @param string $state
 * @return Users
 */
public function setState($state) {
    $this->state = $state;

    return $this;
}

/**
 * Get state
 *
 * @return string 
 */
public function getState() {
    return $this->state;
}

/**
 * Set city
 *
 * @param string $city
 * @return Users
 */
public function setCity($city) {
    $this->city = $city;

    return $this;
}

/**
 * Get city
 *
 * @return string 
 */
public function getCity() {
    return $this->city;
}

/**
 * Set hobbies
 *
 * @param string $hobbies
 * @return Users
 */
public function setHobbies($hobbies) {
    $this->hobbies = $hobbies;

    return $this;
}

/**
 * Get hobbies
 *
 * @return string 
 */
public function getHobbies() {
    return $this->hobbies;
}

/**
 * Set interests
 *
 * @param string $interests
 * @return Users
 */
public function setInterests($interests) {
    $this->interests = $interests;

    return $this;
}

/**
 * Get interests
 *
 * @return string 
 */
public function getInterests() {
    return $this->interests;
}

/**
 * Set about
 *
 * @param string $about
 * @return Users
 */
public function setAbout($about) {
    $this->about = $about;

    return $this;
}

/**
 * Get about
 *
 * @return string 
 */
public function getAbout() {
    return $this->about;
}

/**
 * Set gender
 *
 * @param boolean $gender
 * @return Users
 */
public function setGender($gender) {
    $this->gender = $gender;

    return $this;
}

/**
 * Get gender
 *
 * @return boolean 
 */
public function getGender() {
    return $this->gender;
}

/**
 * Set dob
 *
 * @param \DateTime $dob
 * @return Users
 */
public function setDob($dob) {
    $this->dob = $dob;

    return $this;
}

/**
 * Get dob
 *
 * @return \DateTime 
 */
public function getDob() {
    return $this->dob;
}

/**
 * Set quickbloxId
 *
 * @param integer $quickbloxId
 * @return Users
 */
public function setQuickbloxId($quickbloxId) {
    $this->quickbloxId = $quickbloxId;

    return $this;
}

/**
 * Get quickbloxId
 *
 * @return integer 
 */
public function getQuickbloxId() {
    return $this->quickbloxId;
}

/**
 * Set privacy
 *
 * @param boolean $privacy
 * @return Users
 */
public function setPrivacy($privacy) {
    $this->privacy = $privacy;

    return $this;
}

/**
 * Get privacy
 *
 * @return boolean 
 */
public function getPrivacy() {
    return $this->privacy;
}

/**
 * Set school
 *
 * @param string $school
 * @return Users
 */
public function setSchool($school) {
    $this->school = $school;

    return $this;
}

/**
 * Get school
 *
 * @return string 
 */
public function getSchool() {
    return $this->school;
}

/**
 * Set college
 *
 * @param string $college
 * @return Users
 */
public function setCollege($college) {
    $this->college = $college;

    return $this;
}

/**
 * Get college
 *
 * @return string 
 */
public function getCollege() {
    return $this->college;
}

/**
 * Set work
 *
 * @param string $work
 * @return Users
 */
public function setWork($work) {
    $this->work = $work;

    return $this;
}

/**
 * Get work
 *
 * @return string 
 */
public function getWork() {
    return $this->work;
}

/**
 * Set relationshipStatus
 *
 * @param string $relationshipStatus
 * @return Users
 */
public function setRelationshipStatus($relationshipStatus) {
    $this->relationshipStatus = $relationshipStatus;

    return $this;
}

/**
 * Get relationshipStatus
 *
 * @return string 
 */
public function getRelationshipStatus() {
    return $this->relationshipStatus;
}
1

There are 1 answers

2
michalmarcinkowski On

You can find the answer here https://github.com/Sylius/Sylius/issues/2931.