Skip to content
Snippets Groups Projects
Commit b0d1f44b authored by Marko Ivancic's avatar Marko Ivancic
Browse files

Merge branch 'units' into 'main'

Improve unit test coverage

See merge request !9
parents 5ef6c2d1 5e3f2291
Branches
No related tags found
1 merge request!9Improve unit test coverage
Pipeline #81955 passed
Showing
with 136 additions and 636 deletions
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
...@@ -6,7 +6,7 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Activity\DoctrineD ...@@ -6,7 +6,7 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Activity\DoctrineD
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\TableConstants; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\TableConstants as BaseTableConstantsAlias;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration;
use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException;
use Throwable; use Throwable;
...@@ -41,11 +41,11 @@ class Version20220801000700CreateAuthenticationEventTable extends AbstractMigrat ...@@ -41,11 +41,11 @@ class Version20220801000700CreateAuthenticationEventTable extends AbstractMigrat
$table->addColumn('happened_at', Types::DATETIMETZ_IMMUTABLE); $table->addColumn('happened_at', Types::DATETIMETZ_IMMUTABLE);
$table->addColumn('client_ip_address', Types::STRING) $table->addColumn('client_ip_address', Types::STRING)
->setLength(TableConstants::COLUMN_IP_ADDRESS_LENGTH) ->setLength(BaseTableConstantsAlias::COLUMN_IP_ADDRESS_LENGTH)
->setNotnull(false); ->setNotnull(false);
$table->addColumn('authentication_protocol_designation', Types::STRING) $table->addColumn('authentication_protocol_designation', Types::STRING)
->setLength(TableConstants::COLUMN_AUTHENTICATION_PROTOCOL_DESIGNATION_LENGTH) ->setLength(BaseTableConstantsAlias::COLUMN_AUTHENTICATION_PROTOCOL_DESIGNATION_LENGTH)
->setNotnull(false); ->setNotnull(false);
$table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE); $table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE);
......
...@@ -7,15 +7,20 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Activity\DoctrineD ...@@ -7,15 +7,20 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Activity\DoctrineD
use DateTimeImmutable; use DateTimeImmutable;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
// phpcs:ignore
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Activity\DoctrineDbal\Traits\Repository\DeletableAuthenticationEventsTrait;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\Repository as BaseRepository; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\Repository as BaseRepository;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\TableConstants use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\TableConstants
as BaseTableConstants; as BaseTableConstants;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Connection; use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Connection;
use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException;
use Throwable; use Throwable;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Activity\DoctrineDbal\EntityTableConstants;
class Repository extends BaseRepository class Repository extends BaseRepository
{ {
use DeletableAuthenticationEventsTrait;
protected string $tableNameAuthenticationEvent; protected string $tableNameAuthenticationEvent;
public function __construct(Connection $connection, LoggerInterface $logger) public function __construct(Connection $connection, LoggerInterface $logger)
...@@ -114,11 +119,11 @@ class Repository extends BaseRepository ...@@ -114,11 +119,11 @@ class Repository extends BaseRepository
//'vsv.metadata AS sp_metadata', //'vsv.metadata AS sp_metadata',
BaseTableConstants::TABLE_ALIAS_SP_VERSION . '.' . BaseTableConstants::TABLE_ALIAS_SP_VERSION . '.' .
BaseTableConstants::TABLE_SP_VERSION_COLUMN_NAME_METADATA . BaseTableConstants::TABLE_SP_VERSION_COLUMN_NAME_METADATA .
' AS ' . TableConstants::ENTITY_ACTIVITY_COLUMN_NAME_SP_METADATA, ' AS ' . EntityTableConstants::ENTITY_ACTIVITY_COLUMN_NAME_SP_METADATA,
//'vuv.attributes AS user_attributes' //'vuv.attributes AS user_attributes'
BaseTableConstants::TABLE_ALIAS_USER_VERSION . '.' . BaseTableConstants::TABLE_ALIAS_USER_VERSION . '.' .
BaseTableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES . ' AS ' . BaseTableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES . ' AS ' .
TableConstants::ENTITY_ACTIVITY_COLUMN_NAME_USER_ATTRIBUTES EntityTableConstants::ENTITY_ACTIVITY_COLUMN_NAME_USER_ATTRIBUTES
)->from( )->from(
//'vds_authentication_event', 'vae' //'vds_authentication_event', 'vae'
$this->tableNameAuthenticationEvent, $this->tableNameAuthenticationEvent,
...@@ -215,29 +220,4 @@ class Repository extends BaseRepository ...@@ -215,29 +220,4 @@ class Repository extends BaseRepository
throw new StoreException($message, (int)$exception->getCode(), $exception); throw new StoreException($message, (int)$exception->getCode(), $exception);
} }
} }
/**
* @throws StoreException
*/
public function deleteAuthenticationEventsOlderThan(DateTimeImmutable $dateTime): void
{
try {
$queryBuilder = $this->connection->dbal()->createQueryBuilder();
$queryBuilder->delete($this->tableNameAuthenticationEvent)
->where(
$queryBuilder->expr()->lt(
TableConstants::TABLE_AUTHENTICATION_EVENT_COLUMN_NAME_HAPPENED_AT,
$queryBuilder->createNamedParameter($dateTime, Types::DATETIME_IMMUTABLE)
)
)->executeStatement();
} catch (Throwable $exception) {
$message = sprintf(
'Error executing query to delete old authentication events. Error was: %s.',
$exception->getMessage()
);
$this->logger->error($message);
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
}
} }
...@@ -19,12 +19,4 @@ class TableConstants ...@@ -19,12 +19,4 @@ class TableConstants
public const TABLE_AUTHENTICATION_EVENT_COLUMN_NAME_AUTHENTICATION_PROTOCOL_DESIGNATION = public const TABLE_AUTHENTICATION_EVENT_COLUMN_NAME_AUTHENTICATION_PROTOCOL_DESIGNATION =
'authentication_protocol_designation'; 'authentication_protocol_designation';
public const TABLE_AUTHENTICATION_EVENT_COLUMN_NAME_CREATED_AT = 'created_at'; public const TABLE_AUTHENTICATION_EVENT_COLUMN_NAME_CREATED_AT = 'created_at';
// Entity 'Activity' related.
public const ENTITY_ACTIVITY_COLUMN_NAME_SP_METADATA = 'sp_metadata';
public const ENTITY_ACTIVITY_COLUMN_NAME_USER_ATTRIBUTES = 'user_attributes';
public const ENTITY_ACTIVITY_COLUMN_NAME_HAPPENED_AT = 'happened_at';
public const ENTITY_ACTIVITY_COLUMN_NAME_CLIENT_IP_ADDRESS = 'client_ip_address';
public const ENTITY_ACTIVITY_COLUMN_NAME_AUTHENTICATION_PROTOCOL_DESIGNATION =
'authentication_protocol_designation';
} }
...@@ -7,18 +7,20 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal ...@@ -7,18 +7,20 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store\Repository; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store\Repository;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store\TableConstants; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store\TableConstants;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store as VersionedStore;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\HashDecoratedState; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\HashDecoratedState;
use SimpleSAML\Module\accounting\Data\Stores\Bases\DoctrineDbal\AbstractStore; use SimpleSAML\Module\accounting\Data\Stores\Bases\DoctrineDbal\AbstractStore;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Factory; use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Factory;
use SimpleSAML\Module\accounting\Data\Stores\Interfaces\StoreInterface; use SimpleSAML\Module\accounting\Data\Stores\Interfaces\StoreInterface;
use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException;
use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException;
use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\ModuleConfiguration;
use SimpleSAML\Module\accounting\Services\HelpersManager; use SimpleSAML\Module\accounting\Services\HelpersManager;
use Throwable; use Throwable;
class Store extends AbstractStore implements StoreInterface class Store extends AbstractStore implements StoreInterface
{ {
use VersionedStore\UserVersionResolvingTrait;
protected HelpersManager $helpersManager; protected HelpersManager $helpersManager;
private Repository $repository; private Repository $repository;
...@@ -125,118 +127,4 @@ class Store extends AbstractStore implements StoreInterface ...@@ -125,118 +127,4 @@ class Store extends AbstractStore implements StoreInterface
throw new StoreException($message, (int)$exception->getCode(), $exception); throw new StoreException($message, (int)$exception->getCode(), $exception);
} }
} }
/**
* @throws StoreException
*/
public function resolveUserId(HashDecoratedState $hashDecoratedState): int
{
$userIdentifierAttributeName = $this->moduleConfiguration->getUserIdAttributeName();
$userIdentifierValue = $hashDecoratedState->getState()->getFirstAttributeValue($userIdentifierAttributeName);
if ($userIdentifierValue === null) {
$message = sprintf('Attributes do not contain user ID attribute %s.', $userIdentifierAttributeName);
throw new UnexpectedValueException($message);
}
$userIdentifierValueHashSha256 = $this->helpersManager->getHash()->getSha256($userIdentifierValue);
// Check if it already exists.
try {
$result = $this->repository->getUser($userIdentifierValueHashSha256);
$userId = $result->fetchOne();
if ($userId !== false) {
return (int)$userId;
}
} catch (Throwable $exception) {
$message = sprintf('Error resolving user ID. Error was: %s.', $exception->getMessage());
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
// Create new
try {
$this->repository->insertUser($userIdentifierValue, $userIdentifierValueHashSha256);
} catch (Throwable $exception) {
$message = sprintf(
'Error inserting new user, however, continuing in case of race condition. Error was: %s.',
$exception->getMessage()
);
$this->logger->warning($message);
}
// Try again, this time it should exist...
try {
$result = $this->repository->getUser($userIdentifierValueHashSha256);
$userIdNew = $result->fetchOne();
if ($userIdNew !== false) {
return (int)$userIdNew;
}
$message = sprintf(
'Error fetching user even after insertion for identifier value hash SHA256 %s.',
$userIdentifierValueHashSha256
);
throw new StoreException($message);
} catch (Throwable $exception) {
$message = sprintf('Error resolving user ID. Error was: %s.', $exception->getMessage());
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
}
/**
* @throws StoreException
*/
public function resolveUserVersionId(int $userId, HashDecoratedState $hashDecoratedState): int
{
$attributeArrayHashSha256 = $hashDecoratedState->getAttributesArrayHashSha256();
// Check if it already exists.
try {
$result = $this->repository->getUserVersion($userId, $attributeArrayHashSha256);
$userVersionId = $result->fetchOne();
if ($userVersionId !== false) {
return (int)$userVersionId;
}
} catch (Throwable $exception) {
$message = sprintf('Error resolving user version ID. Error was: %s.', $exception->getMessage());
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
// Create new
try {
$this->repository->insertUserVersion(
$userId,
serialize($hashDecoratedState->getState()->getAttributes()),
$attributeArrayHashSha256
);
} catch (Throwable $exception) {
$message = sprintf(
'Error inserting new user version, however, continuing in case of race condition. Error was: %s.',
$exception->getMessage()
);
$this->logger->warning($message);
}
// Try again, this time it should exist...
try {
$result = $this->repository->getUserVersion($userId, $attributeArrayHashSha256);
$userVersionIdNew = $result->fetchOne();
if ($userVersionIdNew !== false) {
return (int)$userVersionIdNew;
}
$message = sprintf(
'Error fetching user version even after insertion for user ID %s.',
$userId
);
throw new StoreException($message);
} catch (Throwable $exception) {
$message = sprintf('Error resolving user version ID. Error was: %s.', $exception->getMessage());
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
}
} }
...@@ -6,7 +6,7 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal ...@@ -6,7 +6,7 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store\TableConstants; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\TableConstants as BaseTableConstantsAlias;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration;
use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException;
use Throwable; use Throwable;
...@@ -41,16 +41,16 @@ class CreateIdpTable extends AbstractMigration ...@@ -41,16 +41,16 @@ class CreateIdpTable extends AbstractMigration
->setAutoincrement(true); ->setAutoincrement(true);
$table->addColumn('entity_id', Types::STRING) $table->addColumn('entity_id', Types::STRING)
->setLength(TableConstants::COLUMN_ENTITY_ID_LENGTH); ->setLength(BaseTableConstantsAlias::COLUMN_ENTITY_ID_LENGTH);
$table->addColumn('entity_id_hash_sha256', Types::STRING) $table->addColumn('entity_id_hash_sha256', Types::STRING)
->setLength(TableConstants::COLUMN_HASH_SHA265_HEXITS_LENGTH) ->setLength(BaseTableConstantsAlias::COLUMN_HASH_SHA265_HEXITS_LENGTH)
->setFixed(true); ->setFixed(true);
$table->addColumn('metadata', Types::TEXT); $table->addColumn('metadata', Types::TEXT);
$table->addColumn('metadata_hash_sha256', Types::STRING) $table->addColumn('metadata_hash_sha256', Types::STRING)
->setLength(TableConstants::COLUMN_HASH_SHA265_HEXITS_LENGTH) ->setLength(BaseTableConstantsAlias::COLUMN_HASH_SHA265_HEXITS_LENGTH)
->setFixed(true); ->setFixed(true);
$table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE); $table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE);
......
...@@ -6,7 +6,7 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal ...@@ -6,7 +6,7 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store\TableConstants; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\TableConstants as BaseTableConstantsAlias;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration;
use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException;
use Throwable; use Throwable;
...@@ -41,16 +41,16 @@ class CreateSpTable extends AbstractMigration ...@@ -41,16 +41,16 @@ class CreateSpTable extends AbstractMigration
->setAutoincrement(true); ->setAutoincrement(true);
$table->addColumn('entity_id', Types::STRING) $table->addColumn('entity_id', Types::STRING)
->setLength(TableConstants::COLUMN_ENTITY_ID_LENGTH); ->setLength(BaseTableConstantsAlias::COLUMN_ENTITY_ID_LENGTH);
$table->addColumn('entity_id_hash_sha256', Types::STRING) $table->addColumn('entity_id_hash_sha256', Types::STRING)
->setLength(TableConstants::COLUMN_HASH_SHA265_HEXITS_LENGTH) ->setLength(BaseTableConstantsAlias::COLUMN_HASH_SHA265_HEXITS_LENGTH)
->setFixed(true); ->setFixed(true);
$table->addColumn('metadata', Types::TEXT); $table->addColumn('metadata', Types::TEXT);
$table->addColumn('metadata_hash_sha256', Types::STRING) $table->addColumn('metadata_hash_sha256', Types::STRING)
->setLength(TableConstants::COLUMN_HASH_SHA265_HEXITS_LENGTH) ->setLength(BaseTableConstantsAlias::COLUMN_HASH_SHA265_HEXITS_LENGTH)
->setFixed(true); ->setFixed(true);
$table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE); $table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE);
......
...@@ -4,75 +4,11 @@ declare(strict_types=1); ...@@ -4,75 +4,11 @@ declare(strict_types=1);
namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store\Migrations; namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store\Migrations;
use Doctrine\DBAL\Schema\Table; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\Migrations;
use Doctrine\DBAL\Types\Types;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store\TableConstants;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration;
use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException;
use Throwable;
use function sprintf; /**
* We use versioned data to manage users, so we reuse versioned user table definitions.
class CreateUserTable extends AbstractMigration */
class CreateUserTable extends Migrations\CreateUserTable
{ {
protected function getLocalTablePrefix(): string
{
return 'cds_';
}
/**
* @inheritDoc
* @throws MigrationException
*/
public function run(): void
{
$tableName = $this->preparePrefixedTableName('user');
try {
if ($this->schemaManager->tablesExist($tableName)) {
return;
}
$table = new Table($tableName);
$table->addColumn('id', Types::BIGINT)
->setUnsigned(true)
->setAutoincrement(true);
$table->addColumn('identifier', Types::TEXT)
->setLength(65535);
$table->addColumn('identifier_hash_sha256', Types::STRING)
->setLength(TableConstants::COLUMN_HASH_SHA265_HEXITS_LENGTH)
->setFixed(true);
$table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE);
$table->setPrimaryKey(['id']);
$table->addUniqueConstraint(['identifier_hash_sha256']);
$this->schemaManager->createTable($table);
} catch (Throwable $exception) {
throw $this->prepareGenericMigrationException(
sprintf('Error creating table \'%s.', $tableName),
$exception
);
}
}
/**
* @inheritDoc
* @throws MigrationException
*/
public function revert(): void
{
$tableName = $this->preparePrefixedTableName('user');
try {
$this->schemaManager->dropTable($tableName);
} catch (Throwable $exception) {
throw $this->prepareGenericMigrationException(sprintf('Could not drop table %s.', $tableName), $exception);
}
}
} }
...@@ -6,10 +6,9 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal ...@@ -6,10 +6,9 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\Migrations; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\Migrations;
/**
* We use versioned data to manage users, so we reuse versioned user table definitions.
*/
class CreateUserVersionTable extends Migrations\CreateUserVersionTable class CreateUserVersionTable extends Migrations\CreateUserVersionTable
{ {
protected function getLocalTablePrefix(): string
{
return 'cds_';
}
} }
...@@ -5,16 +5,22 @@ declare(strict_types=1); ...@@ -5,16 +5,22 @@ declare(strict_types=1);
namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store; namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Current\Store;
use DateTimeImmutable; use DateTimeImmutable;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Result; use Doctrine\DBAL\Result;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
// phpcs:ignore
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\Repository as VersionedRepository;
// phpcs:ignore
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\TableConstants as VersionedTableConstantsAlias;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Connection; use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Connection;
use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException;
use Throwable; use Throwable;
class Repository class Repository
{ {
// We user versioned user data, so let's reuse versioned user tables.
use VersionedRepository\UserVersionManagementTrait;
protected Connection $connection; protected Connection $connection;
protected LoggerInterface $logger; protected LoggerInterface $logger;
protected string $tableNameIdp; protected string $tableNameIdp;
...@@ -29,13 +35,23 @@ class Repository ...@@ -29,13 +35,23 @@ class Repository
$this->tableNameIdp = $this->preparePrefixedTableName(TableConstants::TABLE_NAME_IDP); $this->tableNameIdp = $this->preparePrefixedTableName(TableConstants::TABLE_NAME_IDP);
$this->tableNameSp = $this->preparePrefixedTableName(TableConstants::TABLE_NAME_SP); $this->tableNameSp = $this->preparePrefixedTableName(TableConstants::TABLE_NAME_SP);
$this->tableNameUser = $this->preparePrefixedTableName(TableConstants::TABLE_NAME_USER);
$this->tableNameUserVersion = $this->preparePrefixedTableName(TableConstants::TABLE_NAME_USER_VERSION); // For user management we use versioned data, so we will reuse tables from versioned data store.
$versionedDataStoreTablePrefix = VersionedTableConstantsAlias::TABLE_PREFIX;
$this->tableNameUser = $this->preparePrefixedTableName(
VersionedTableConstantsAlias::TABLE_NAME_USER,
$versionedDataStoreTablePrefix
);
$this->tableNameUserVersion = $this->preparePrefixedTableName(
VersionedTableConstantsAlias::TABLE_NAME_USER_VERSION,
$versionedDataStoreTablePrefix
);
} }
protected function preparePrefixedTableName(string $tableName): string protected function preparePrefixedTableName(string $tableName, string $tablePrefixOverride = null): string
{ {
return $this->connection->preparePrefixedTableName(TableConstants::TABLE_PREFIX . $tableName); $tablePrefix = $tablePrefixOverride ?? TableConstants::TABLE_PREFIX;
return $this->connection->preparePrefixedTableName($tablePrefix . $tableName);
} }
/** /**
...@@ -178,48 +194,48 @@ class Repository ...@@ -178,48 +194,48 @@ class Repository
string $metadataHashSha256, string $metadataHashSha256,
DateTimeImmutable $updatedAt = null DateTimeImmutable $updatedAt = null
): void { ): void {
$queryBuilder = $this->connection->dbal()->createQueryBuilder(); try {
$queryBuilder = $this->connection->dbal()->createQueryBuilder();
$updatedAt = $updatedAt ?? new DateTimeImmutable(); $updatedAt = $updatedAt ?? new DateTimeImmutable();
$queryBuilder->update($this->tableNameIdp) $queryBuilder->update($this->tableNameIdp)
->set( ->set(
TableConstants::TABLE_IDP_COLUMN_NAME_METADATA, TableConstants::TABLE_IDP_COLUMN_NAME_METADATA,
':' . TableConstants::TABLE_IDP_COLUMN_NAME_METADATA ':' . TableConstants::TABLE_IDP_COLUMN_NAME_METADATA
)
->set(
TableConstants::TABLE_IDP_COLUMN_NAME_METADATA_HASH_SHA256,
':' . TableConstants::TABLE_IDP_COLUMN_NAME_METADATA_HASH_SHA256
)
->set(
TableConstants::TABLE_IDP_COLUMN_NAME_UPDATED_AT,
':' . TableConstants::TABLE_IDP_COLUMN_NAME_UPDATED_AT
)
->setParameter(
TableConstants::TABLE_IDP_COLUMN_NAME_METADATA,
$metadata,
Types::STRING
)
->setParameter(
TableConstants::TABLE_IDP_COLUMN_NAME_METADATA_HASH_SHA256,
$metadataHashSha256,
Types::STRING
)
->setParameter(
TableConstants::TABLE_IDP_COLUMN_NAME_UPDATED_AT,
$updatedAt,
Types::DATETIMETZ_IMMUTABLE
)
->where(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq(
TableConstants::TABLE_IDP_COLUMN_NAME_ID,
$queryBuilder->createNamedParameter($idpId, Types::INTEGER)
)
) )
); ->set(
TableConstants::TABLE_IDP_COLUMN_NAME_METADATA_HASH_SHA256,
':' . TableConstants::TABLE_IDP_COLUMN_NAME_METADATA_HASH_SHA256
)
->set(
TableConstants::TABLE_IDP_COLUMN_NAME_UPDATED_AT,
':' . TableConstants::TABLE_IDP_COLUMN_NAME_UPDATED_AT
)
->setParameter(
TableConstants::TABLE_IDP_COLUMN_NAME_METADATA,
$metadata,
Types::STRING
)
->setParameter(
TableConstants::TABLE_IDP_COLUMN_NAME_METADATA_HASH_SHA256,
$metadataHashSha256,
Types::STRING
)
->setParameter(
TableConstants::TABLE_IDP_COLUMN_NAME_UPDATED_AT,
$updatedAt,
Types::DATETIMETZ_IMMUTABLE
)
->where(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq(
TableConstants::TABLE_IDP_COLUMN_NAME_ID,
$queryBuilder->createNamedParameter($idpId, Types::INTEGER)
)
)
);
try {
$queryBuilder->executeStatement(); $queryBuilder->executeStatement();
} catch (Throwable $exception) { } catch (Throwable $exception) {
$message = sprintf('Error executing query to update IdP. Error was: %s.', $exception->getMessage()); $message = sprintf('Error executing query to update IdP. Error was: %s.', $exception->getMessage());
...@@ -296,234 +312,52 @@ class Repository ...@@ -296,234 +312,52 @@ class Repository
string $metadataHashSha256, string $metadataHashSha256,
DateTimeImmutable $updatedAt = null DateTimeImmutable $updatedAt = null
): void { ): void {
$queryBuilder = $this->connection->dbal()->createQueryBuilder();
$updatedAt = $updatedAt ?? new DateTimeImmutable();
$queryBuilder->update($this->tableNameSp)
->set(
TableConstants::TABLE_SP_COLUMN_NAME_METADATA,
':' . TableConstants::TABLE_SP_COLUMN_NAME_METADATA
)
->set(
TableConstants::TABLE_SP_COLUMN_NAME_METADATA_HASH_SHA256,
':' . TableConstants::TABLE_SP_COLUMN_NAME_METADATA_HASH_SHA256
)
->set(
TableConstants::TABLE_SP_COLUMN_NAME_UPDATED_AT,
':' . TableConstants::TABLE_SP_COLUMN_NAME_UPDATED_AT
)
->setParameter(
TableConstants::TABLE_SP_COLUMN_NAME_METADATA,
$metadata,
Types::STRING
)
->setParameter(
TableConstants::TABLE_SP_COLUMN_NAME_METADATA_HASH_SHA256,
$metadataHashSha256,
Types::STRING
)
->setParameter(
TableConstants::TABLE_SP_COLUMN_NAME_UPDATED_AT,
$updatedAt,
Types::DATETIMETZ_IMMUTABLE
)
->where(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq(
TableConstants::TABLE_SP_COLUMN_NAME_ID,
$queryBuilder->createNamedParameter($spId, Types::INTEGER)
)
)
);
try {
$queryBuilder->executeStatement();
} catch (Throwable $exception) {
$message = sprintf('Error executing query to update SP. Error was: %s.', $exception->getMessage());
$this->logger->error($message, compact('spId', 'metadata', 'metadataHashSha256'));
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
}
/**
* @throws StoreException
*/
public function getUser(string $identifierHashSha256): Result
{
try { try {
$queryBuilder = $this->connection->dbal()->createQueryBuilder(); $queryBuilder = $this->connection->dbal()->createQueryBuilder();
/** @psalm-suppress TooManyArguments */ $updatedAt = $updatedAt ?? new DateTimeImmutable();
$queryBuilder->select(
TableConstants::TABLE_USER_COLUMN_NAME_ID,
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER,
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER_HASH_SHA256,
TableConstants::TABLE_USER_COLUMN_NAME_CREATED_AT,
)
->from($this->tableNameUser)
->where(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq(
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER_HASH_SHA256,
$queryBuilder->createNamedParameter($identifierHashSha256)
)
)
)->setMaxResults(1);
return $queryBuilder->executeQuery();
} catch (Throwable $exception) {
$message = sprintf(
'Error executing query to get user. Error was: %s.',
$identifierHashSha256,
$exception->getMessage()
);
$this->logger->error($message, compact('identifierHashSha256'));
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
}
/**
* @throws StoreException
*/
public function insertUser(
string $identifier,
string $identifierHashSha256,
DateTimeImmutable $createdAt = null
): void {
$queryBuilder = $this->connection->dbal()->createQueryBuilder();
$createdAt = $createdAt ?? new DateTimeImmutable(); $queryBuilder->update($this->tableNameSp)
->set(
$queryBuilder->insert($this->tableNameUser) TableConstants::TABLE_SP_COLUMN_NAME_METADATA,
->values( ':' . TableConstants::TABLE_SP_COLUMN_NAME_METADATA
[ )
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER => ':' . ->set(
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER, TableConstants::TABLE_SP_COLUMN_NAME_METADATA_HASH_SHA256,
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER_HASH_SHA256 => ':' . ':' . TableConstants::TABLE_SP_COLUMN_NAME_METADATA_HASH_SHA256
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER_HASH_SHA256, )
TableConstants::TABLE_USER_COLUMN_NAME_CREATED_AT => ':' . ->set(
TableConstants::TABLE_USER_COLUMN_NAME_CREATED_AT, TableConstants::TABLE_SP_COLUMN_NAME_UPDATED_AT,
] ':' . TableConstants::TABLE_SP_COLUMN_NAME_UPDATED_AT
) )
->setParameters( ->setParameter(
[ TableConstants::TABLE_SP_COLUMN_NAME_METADATA,
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER => $identifier, $metadata,
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER_HASH_SHA256 => $identifierHashSha256, Types::STRING
TableConstants::TABLE_USER_COLUMN_NAME_CREATED_AT => $createdAt, )
], ->setParameter(
[ TableConstants::TABLE_SP_COLUMN_NAME_METADATA_HASH_SHA256,
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER => Types::TEXT, $metadataHashSha256,
TableConstants::TABLE_USER_COLUMN_NAME_IDENTIFIER_HASH_SHA256 => Types::STRING, Types::STRING
TableConstants::TABLE_USER_COLUMN_NAME_CREATED_AT => Types::DATETIMETZ_IMMUTABLE )
] ->setParameter(
); TableConstants::TABLE_SP_COLUMN_NAME_UPDATED_AT,
$updatedAt,
try { Types::DATETIMETZ_IMMUTABLE
$queryBuilder->executeStatement(); )
} catch (Throwable $exception) {
$message = sprintf('Error executing query to insert user. Error was: %s.', $exception->getMessage());
$this->logger->error(
$message,
compact('identifier', 'identifierHashSha256')
);
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
}
/**
* @throws StoreException
*/
public function getUserVersion(int $userId, string $attributesHashSha256): Result
{
try {
$queryBuilder = $this->connection->dbal()->createQueryBuilder();
/** @psalm-suppress TooManyArguments */
$queryBuilder->select(
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ID,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_USER_ID,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES_HASH_SHA256,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_CREATED_AT,
)
->from($this->tableNameUserVersion)
->where( ->where(
$queryBuilder->expr()->and( $queryBuilder->expr()->and(
$queryBuilder->expr()->eq( $queryBuilder->expr()->eq(
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_USER_ID, TableConstants::TABLE_SP_COLUMN_NAME_ID,
$queryBuilder->createNamedParameter($userId, ParameterType::INTEGER) $queryBuilder->createNamedParameter($spId, Types::INTEGER)
),
$queryBuilder->expr()->eq(
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES_HASH_SHA256,
$queryBuilder->createNamedParameter($attributesHashSha256)
) )
) )
)->setMaxResults(1); );
return $queryBuilder->executeQuery();
} catch (Throwable $exception) {
$message = sprintf(
'Error executing query to get user version for user ID %s and attribute array hash %s. Error was: %s.',
$userId,
$attributesHashSha256,
$exception->getMessage()
);
$this->logger->error($message, compact('userId', 'attributesHashSha256'));
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
}
/**
* @throws StoreException
*/
public function insertUserVersion(
int $userId,
string $attributes,
string $attributesHashSha256,
DateTimeImmutable $createdAt = null
): void {
$queryBuilder = $this->connection->dbal()->createQueryBuilder();
$createdAt = $createdAt ?? new DateTimeImmutable();
$queryBuilder->insert($this->tableNameUserVersion)
->values(
[
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_USER_ID => ':' .
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_USER_ID,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES => ':' .
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES_HASH_SHA256 => ':' .
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES_HASH_SHA256,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_CREATED_AT => ':' .
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_CREATED_AT,
]
)
->setParameters(
[
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_USER_ID => $userId,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES => $attributes,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES_HASH_SHA256 => $attributesHashSha256,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_CREATED_AT => $createdAt,
],
[
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_USER_ID => Types::BIGINT,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES => Types::TEXT,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES_HASH_SHA256 => Types::STRING,
TableConstants::TABLE_USER_VERSION_COLUMN_NAME_CREATED_AT => Types::DATETIMETZ_IMMUTABLE,
]
);
try {
$queryBuilder->executeStatement(); $queryBuilder->executeStatement();
} catch (Throwable $exception) { } catch (Throwable $exception) {
$message = sprintf( $message = sprintf('Error executing query to update SP. Error was: %s.', $exception->getMessage());
'Error executing query to insert user version. Error was: %s.', $this->logger->error($message, compact('spId', 'metadata', 'metadataHashSha256'));
$exception->getMessage()
);
$this->logger->error($message, compact('userId', 'attributesHashSha256'));
throw new StoreException($message, (int)$exception->getCode(), $exception); throw new StoreException($message, (int)$exception->getCode(), $exception);
} }
} }
......
...@@ -31,22 +31,4 @@ class TableConstants extends BaseTableConstants ...@@ -31,22 +31,4 @@ class TableConstants extends BaseTableConstants
public const TABLE_SP_COLUMN_NAME_METADATA_HASH_SHA256 = 'metadata_hash_sha256'; public const TABLE_SP_COLUMN_NAME_METADATA_HASH_SHA256 = 'metadata_hash_sha256';
public const TABLE_SP_COLUMN_NAME_CREATED_AT = 'created_at'; public const TABLE_SP_COLUMN_NAME_CREATED_AT = 'created_at';
public const TABLE_SP_COLUMN_NAME_UPDATED_AT = 'updated_at'; public const TABLE_SP_COLUMN_NAME_UPDATED_AT = 'updated_at';
// Table 'user'
public const TABLE_NAME_USER = 'user';
public const TABLE_ALIAS_USER = self::TABLE_PREFIX . 'u';
public const TABLE_USER_COLUMN_NAME_ID = 'id'; // int
public const TABLE_USER_COLUMN_NAME_IDENTIFIER = 'identifier'; // text, varies... (can be ePTID, which is long XML).
public const TABLE_USER_COLUMN_NAME_IDENTIFIER_HASH_SHA256 = 'identifier_hash_sha256';
public const TABLE_USER_COLUMN_NAME_CREATED_AT = 'created_at';
// Table 'user_version' (versioned attributes)
public const TABLE_NAME_USER_VERSION = 'user_version';
public const TABLE_ALIAS_USER_VERSION = self::TABLE_PREFIX . 'uv';
public const TABLE_ALIAS_USER_VERSION_2 = self::TABLE_ALIAS_USER_VERSION . '_2';
public const TABLE_USER_VERSION_COLUMN_NAME_ID = 'id'; // int ID
public const TABLE_USER_VERSION_COLUMN_NAME_USER_ID = 'user_id'; // FK
public const TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES = 'attributes'; // Serialized attributes version
public const TABLE_USER_VERSION_COLUMN_NAME_ATTRIBUTES_HASH_SHA256 = 'attributes_hash_sha256';
public const TABLE_USER_VERSION_COLUMN_NAME_CREATED_AT = 'created_at';
} }
...@@ -11,13 +11,14 @@ use SimpleSAML\Module\accounting\Data\Stores\Bases\DoctrineDbal\AbstractStore; ...@@ -11,13 +11,14 @@ use SimpleSAML\Module\accounting\Data\Stores\Bases\DoctrineDbal\AbstractStore;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Factory; use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Factory;
use SimpleSAML\Module\accounting\Data\Stores\Interfaces\StoreInterface; use SimpleSAML\Module\accounting\Data\Stores\Interfaces\StoreInterface;
use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException;
use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException;
use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\ModuleConfiguration;
use SimpleSAML\Module\accounting\Services\HelpersManager; use SimpleSAML\Module\accounting\Services\HelpersManager;
use Throwable; use Throwable;
class Store extends AbstractStore implements StoreInterface class Store extends AbstractStore implements StoreInterface
{ {
use Store\UserVersionResolvingTrait;
protected HelpersManager $helpersManager; protected HelpersManager $helpersManager;
private Repository $repository; private Repository $repository;
...@@ -275,120 +276,6 @@ class Store extends AbstractStore implements StoreInterface ...@@ -275,120 +276,6 @@ class Store extends AbstractStore implements StoreInterface
} }
} }
/**
* @throws StoreException
*/
public function resolveUserId(HashDecoratedState $hashDecoratedState): int
{
$userIdentifierAttributeName = $this->moduleConfiguration->getUserIdAttributeName();
$userIdentifierValue = $hashDecoratedState->getState()->getFirstAttributeValue($userIdentifierAttributeName);
if ($userIdentifierValue === null) {
$message = sprintf('Attributes do not contain user ID attribute %s.', $userIdentifierAttributeName);
throw new UnexpectedValueException($message);
}
$userIdentifierValueHashSha256 = $this->helpersManager->getHash()->getSha256($userIdentifierValue);
// Check if it already exists.
try {
$result = $this->repository->getUser($userIdentifierValueHashSha256);
$userId = $result->fetchOne();
if ($userId !== false) {
return (int)$userId;
}
} catch (Throwable $exception) {
$message = sprintf('Error resolving user ID. Error was: %s.', $exception->getMessage());
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
// Create new
try {
$this->repository->insertUser($userIdentifierValue, $userIdentifierValueHashSha256);
} catch (Throwable $exception) {
$message = sprintf(
'Error inserting new user, however, continuing in case of race condition. Error was: %s.',
$exception->getMessage()
);
$this->logger->warning($message);
}
// Try again, this time it should exist...
try {
$result = $this->repository->getUser($userIdentifierValueHashSha256);
$userIdNew = $result->fetchOne();
if ($userIdNew !== false) {
return (int)$userIdNew;
}
$message = sprintf(
'Error fetching user even after insertion for identifier value hash SHA256 %s.',
$userIdentifierValueHashSha256
);
throw new StoreException($message);
} catch (Throwable $exception) {
$message = sprintf('Error resolving user ID. Error was: %s.', $exception->getMessage());
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
}
/**
* @throws StoreException
*/
public function resolveUserVersionId(int $userId, HashDecoratedState $hashDecoratedState): int
{
$attributeArrayHashSha256 = $hashDecoratedState->getAttributesArrayHashSha256();
// Check if it already exists.
try {
$result = $this->repository->getUserVersion($userId, $attributeArrayHashSha256);
$userVersionId = $result->fetchOne();
if ($userVersionId !== false) {
return (int)$userVersionId;
}
} catch (Throwable $exception) {
$message = sprintf('Error resolving user version ID. Error was: %s.', $exception->getMessage());
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
// Create new
try {
$this->repository->insertUserVersion(
$userId,
serialize($hashDecoratedState->getState()->getAttributes()),
$attributeArrayHashSha256
);
} catch (Throwable $exception) {
$message = sprintf(
'Error inserting new user version, however, continuing in case of race condition. Error was: %s.',
$exception->getMessage()
);
$this->logger->warning($message);
}
// Try again, this time it should exist...
try {
$result = $this->repository->getUserVersion($userId, $attributeArrayHashSha256);
$userVersionIdNew = $result->fetchOne();
if ($userVersionIdNew !== false) {
return (int)$userVersionIdNew;
}
$message = sprintf(
'Error fetching user version even after insertion for user ID %s.',
$userId
);
throw new StoreException($message);
} catch (Throwable $exception) {
$message = sprintf('Error resolving user version ID. Error was: %s.', $exception->getMessage());
throw new StoreException($message, (int)$exception->getCode(), $exception);
}
}
/** /**
* @throws StoreException * @throws StoreException
*/ */
......
File mode changed from 100644 to 100755
...@@ -6,7 +6,7 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal ...@@ -6,7 +6,7 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\TableConstants; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\TableConstants as BaseTableConstantsAlias;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration;
use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException;
use Throwable; use Throwable;
...@@ -41,10 +41,10 @@ class CreateIdpTable extends AbstractMigration ...@@ -41,10 +41,10 @@ class CreateIdpTable extends AbstractMigration
->setAutoincrement(true); ->setAutoincrement(true);
$table->addColumn('entity_id', Types::STRING) $table->addColumn('entity_id', Types::STRING)
->setLength(TableConstants::COLUMN_ENTITY_ID_LENGTH); ->setLength(BaseTableConstantsAlias::COLUMN_ENTITY_ID_LENGTH);
$table->addColumn('entity_id_hash_sha256', Types::STRING) $table->addColumn('entity_id_hash_sha256', Types::STRING)
->setLength(TableConstants::COLUMN_HASH_SHA265_HEXITS_LENGTH) ->setLength(BaseTableConstantsAlias::COLUMN_HASH_SHA265_HEXITS_LENGTH)
->setFixed(true); ->setFixed(true);
$table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE); $table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE);
......
...@@ -6,11 +6,13 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal ...@@ -6,11 +6,13 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\TableConstants; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\TableConstants as BaseTableConstantsAlias;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration;
use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException;
use Throwable; use Throwable;
use function sprintf;
class CreateIdpVersionTable extends AbstractMigration class CreateIdpVersionTable extends AbstractMigration
{ {
protected function getLocalTablePrefix(): string protected function getLocalTablePrefix(): string
...@@ -43,7 +45,7 @@ class CreateIdpVersionTable extends AbstractMigration ...@@ -43,7 +45,7 @@ class CreateIdpVersionTable extends AbstractMigration
$table->addColumn('metadata', Types::TEXT); $table->addColumn('metadata', Types::TEXT);
$table->addColumn('metadata_hash_sha256', Types::STRING) $table->addColumn('metadata_hash_sha256', Types::STRING)
->setLength(TableConstants::COLUMN_HASH_SHA265_HEXITS_LENGTH) ->setLength(BaseTableConstantsAlias::COLUMN_HASH_SHA265_HEXITS_LENGTH)
->setFixed(true); ->setFixed(true);
$table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE); $table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE);
...@@ -57,7 +59,7 @@ class CreateIdpVersionTable extends AbstractMigration ...@@ -57,7 +59,7 @@ class CreateIdpVersionTable extends AbstractMigration
$this->schemaManager->createTable($table); $this->schemaManager->createTable($table);
} catch (Throwable $exception) { } catch (Throwable $exception) {
throw $this->prepareGenericMigrationException( throw $this->prepareGenericMigrationException(
\sprintf('Error creating table \'%s.', $tableName), sprintf('Error creating table \'%s.', $tableName),
$exception $exception
); );
} }
...@@ -74,7 +76,7 @@ class CreateIdpVersionTable extends AbstractMigration ...@@ -74,7 +76,7 @@ class CreateIdpVersionTable extends AbstractMigration
try { try {
$this->schemaManager->dropTable($tableName); $this->schemaManager->dropTable($tableName);
} catch (Throwable $exception) { } catch (Throwable $exception) {
throw $this->prepareGenericMigrationException(\sprintf('Could not drop table %s.', $tableName), $exception); throw $this->prepareGenericMigrationException(sprintf('Could not drop table %s.', $tableName), $exception);
} }
} }
} }
...@@ -6,7 +6,7 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal ...@@ -6,7 +6,7 @@ namespace SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\DoctrineDbal\Versioned\Store\TableConstants; use SimpleSAML\Module\accounting\Data\Stores\Accounting\Bases\TableConstants as BaseTableConstantsAlias;
use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Data\Stores\Connections\DoctrineDbal\Bases\AbstractMigration;
use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException;
use Throwable; use Throwable;
...@@ -41,10 +41,10 @@ class CreateSpTable extends AbstractMigration ...@@ -41,10 +41,10 @@ class CreateSpTable extends AbstractMigration
->setAutoincrement(true); ->setAutoincrement(true);
$table->addColumn('entity_id', Types::STRING) $table->addColumn('entity_id', Types::STRING)
->setLength(TableConstants::COLUMN_ENTITY_ID_LENGTH); ->setLength(BaseTableConstantsAlias::COLUMN_ENTITY_ID_LENGTH);
$table->addColumn('entity_id_hash_sha256', Types::STRING) $table->addColumn('entity_id_hash_sha256', Types::STRING)
->setLength(TableConstants::COLUMN_HASH_SHA265_HEXITS_LENGTH) ->setLength(BaseTableConstantsAlias::COLUMN_HASH_SHA265_HEXITS_LENGTH)
->setFixed(true); ->setFixed(true);
$table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE); $table->addColumn('created_at', Types::DATETIMETZ_IMMUTABLE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment