Skip to content

Commit

Permalink
fix(User): Removed deprecated User salt column
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Sep 15, 2023
1 parent 712b389 commit 1294167
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 61 deletions.
7 changes: 0 additions & 7 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ IR_DRIVER=gd
MESSENGER_TRANSPORT_DSN=redis://redis:6379/messages
###< symfony/messenger ###

# blackfire.io
BLACKFIRE_LOG_LEVEL=4
BLACKFIRE_SERVER_ID=
BLACKFIRE_SERVER_TOKEN=
BLACKFIRE_CLIENT_ID=
BLACKFIRE_CLIENT_TOKEN=

TRUSTED_PROXIES=127.0.0.1,172.19.0.1,172.19.0.2,REMOTE_ADDR

###> sentry/sentry-symfony ###
Expand Down
11 changes: 1 addition & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ services:
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: db_name
MYSQL_HOST: db
MYSQL_USER: db_user
MYSQL_PASSWORD: db_password
links:
Expand Down Expand Up @@ -197,16 +198,6 @@ services:
- "traefik.http.routers.${APP_NAMESPACE}_secure.tls=true"
- "traefik.http.routers.${APP_NAMESPACE}_secure.service=${APP_NAMESPACE}"

blackfire:
image: blackfire/blackfire
environment:
# Exposes BLACKFIRE_* environment variables from the host
BLACKFIRE_LOG_LEVEL: ${BLACKFIRE_LOG_LEVEL}
BLACKFIRE_SERVER_ID: ${BLACKFIRE_SERVER_ID}
BLACKFIRE_SERVER_TOKEN: ${BLACKFIRE_SERVER_TOKEN}
BLACKFIRE_CLIENT_ID: ${BLACKFIRE_CLIENT_ID}
BLACKFIRE_CLIENT_TOKEN: ${BLACKFIRE_CLIENT_TOKEN}

mailer:
image: mailhog/mailhog
ports:
Expand Down
31 changes: 31 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20230915134833.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230915134833 extends AbstractMigration
{
public function getDescription(): string
{
return 'Remove useless user salt column.';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE users DROP salt');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE users ADD salt VARCHAR(64) NOT NULL');
}
}
36 changes: 5 additions & 31 deletions lib/RoadizCoreBundle/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
use JMS\Serializer\Annotation as Serializer;
use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordStrength;
use RZ\Roadiz\Core\AbstractEntities\AbstractHuman;
use RZ\Roadiz\CoreBundle\Form\Constraint\ValidFacebookName;
use RZ\Roadiz\CoreBundle\Repository\UserRepository;
use RZ\Roadiz\CoreBundle\Security\User\AdvancedUserInterface;
use RZ\Roadiz\Random\SaltGenerator;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation as SymfonySerializer;
use Symfony\Component\Validator\Constraints as Assert;
use RZ\Roadiz\CoreBundle\Form\Constraint\ValidFacebookName;

#[
ORM\Entity(repositoryClass: UserRepository::class),
Expand Down Expand Up @@ -121,15 +120,6 @@ class User extends AbstractHuman implements UserInterface, AdvancedUserInterface
#[Assert\Length(max: 200)]
private string $username = '';

/**
* The salt to use for hashing.
*/
#[ORM\Column(name: 'salt', type: 'string', length: 64)]
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
#[Assert\Length(max: 64)]
private string $salt = '';

/**
* Encrypted password.
*/
Expand Down Expand Up @@ -239,9 +229,6 @@ public function __construct()
$this->groups = new ArrayCollection();
$this->sendCreationConfirmationEmail(false);
$this->initAbstractDateTimed();

$saltGenerator = new SaltGenerator();
$this->setSalt($saltGenerator->generateSalt());
}

/**
Expand Down Expand Up @@ -361,17 +348,7 @@ public function setPictureUrl(?string $pictureUrl): User
*/
public function getSalt(): ?string
{
return $this->salt;
}

/**
* @param string $salt
* @return $this
*/
public function setSalt(string $salt): User
{
$this->salt = $salt;
return $this;
return null;
}

/**
Expand Down Expand Up @@ -881,8 +858,8 @@ public function __serialize(): array
{
return [
$this->password,
$this->salt,
$this->username,
$this->getSalt(),
$this->enabled,
$this->id,
$this->email,
Expand All @@ -898,10 +875,11 @@ public function __serialize(): array

public function __unserialize(array $data): void
{
$salt = null;
[
$this->password,
$this->salt,
$this->username,
$salt,
$this->enabled,
$this->id,
$this->email,
Expand Down Expand Up @@ -968,10 +946,6 @@ public function isEqualTo(UserInterface $user): bool
return false;
}

if ($this->getSalt() !== $user->getSalt()) {
return false;
}

if ($this->getUsername() !== $user->getUsername()) {
return false;
}
Expand Down
12 changes: 0 additions & 12 deletions lib/RoadizCoreBundle/src/Exception/EmptySaltException.php

This file was deleted.

1 change: 0 additions & 1 deletion lib/RoadizCoreBundle/src/Repository/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ public static function getSearchableColumnsNames(ClassMetadataInfo $metadata): a
'childrenOrder',
'childrenOrderDirection',
'password',
'salt',
'token',
'confirmationToken'
])
Expand Down

0 comments on commit 1294167

Please sign in to comment.