Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TYPO3 v9 compatibility #23

Merged
merged 9 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions Classes/OpenidService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use TYPO3\CMS\Core\Crypto\Random;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Service\AbstractService;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
Expand Down Expand Up @@ -170,7 +171,6 @@ public function getUser()
}
$userRecord = null;
if ($this->openIDResponse instanceof \Auth_OpenID_ConsumerResponse) {
$GLOBALS['BACK_PATH'] = $this->getBackPath();
// We are running inside the OpenID return script
// Note: we cannot use $this->openIDResponse->getDisplayIdentifier()
// because it may return a different identifier. For example,
Expand Down Expand Up @@ -280,6 +280,7 @@ protected function getUserRecord($openIDIdentifier)
$openIDIdentifier = $this->normalizeOpenID($openIDIdentifier);
// $openIDIdentifier always has a trailing slash
// but tx_openid_openid field possibly not so check for both alternatives in database
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->authenticationInformation['db_user']['table']);
$queryBuilder->getRestrictions()->removeAll();
$record = $queryBuilder
Expand Down Expand Up @@ -475,6 +476,7 @@ protected function normalizeOpenID($openIDIdentifier)
}
// A URI with a missing scheme is normalized to a http URI
if (!preg_match('#^https?://#', $openIDIdentifier)) {
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->authenticationInformation['db_user']['table']);
$queryBuilder->getRestrictions()->removeAll();
$row = $queryBuilder
Expand Down Expand Up @@ -511,19 +513,6 @@ protected function normalizeOpenID($openIDIdentifier)
return $openIDIdentifier;
}

/**
* Calculates the path to the TYPO3 directory from the current directory
*
* @return string
*/
protected function getBackPath()
{
$extPath = ExtensionManagementUtility::siteRelPath('openid');
$segmentCount = count(explode('/', $extPath));
$path = str_pad('', $segmentCount * 3, '../') . TYPO3_mainDir;
return $path;
}

/**
* Obtains a real identifier for the user
*
Expand Down
34 changes: 21 additions & 13 deletions Classes/OpenidStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand All @@ -41,38 +43,39 @@ class OpenidStore extends \Auth_OpenID_OpenIDStore
*/
public function storeAssociation($serverUrl, $association)
{
$builder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::ASSOCIATION_TABLE_NAME);
$builder->getRestrictions()->removeAll();
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::ASSOCIATION_TABLE_NAME);
$queryBuilder->getRestrictions()->removeAll();

$builder->getConnection()->beginTransaction();
$queryBuilder->getConnection()->beginTransaction();

$existingAssociations = $builder
$existingAssociations = $queryBuilder
->count('*')
->from(self::ASSOCIATION_TABLE_NAME)
->where(
$builder->expr()->eq('server_url', $builder->createNamedParameter($serverUrl)),
$builder->expr()->eq('assoc_handle', $builder->createNamedParameter($association->handle)),
$builder->expr()->eq('expires', $builder->createNamedParameter(time(), \PDO::PARAM_INT))
$queryBuilder->expr()->eq('server_url', $queryBuilder->createNamedParameter($serverUrl)),
$queryBuilder->expr()->eq('assoc_handle', $queryBuilder->createNamedParameter($association->handle)),
$queryBuilder->expr()->eq('expires', $queryBuilder->createNamedParameter(time(), \PDO::PARAM_INT))
)
->execute()
->fetchColumn();

if ($existingAssociations) {
$builder
$queryBuilder
->update(self::ASSOCIATION_TABLE_NAME)
->values([
'content' => base64_encode(serialize($association)),
'tstamp' => time()
])
->where(
$builder->expr()->eq('server_url', $builder->createNamedParameter($serverUrl)),
$builder->expr()->eq('assoc_handle', $builder->createNamedParameter($association->handle)),
$builder->expr()->eq('expires', $builder->createNamedParameter(time(), \PDO::PARAM_INT))
$queryBuilder->expr()->eq('server_url', $queryBuilder->createNamedParameter($serverUrl)),
$queryBuilder->expr()->eq('assoc_handle', $queryBuilder->createNamedParameter($association->handle)),
$queryBuilder->expr()->eq('expires', $queryBuilder->createNamedParameter(time(), \PDO::PARAM_INT))
)
->execute();
} else {
// In the next query we can get race conditions. sha1_hash prevents many associations from being stored for one server
$builder
$queryBuilder
->insert(self::ASSOCIATION_TABLE_NAME)
->values([
'assoc_handle' => $association->handle,
Expand All @@ -85,7 +88,7 @@ public function storeAssociation($serverUrl, $association)
->execute();
}

$builder->getConnection()->commit();
$queryBuilder->getConnection()->commit();
}

/**
Expand All @@ -95,6 +98,7 @@ public function storeAssociation($serverUrl, $association)
*/
public function cleanupAssociations()
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::ASSOCIATION_TABLE_NAME);
$queryBuilder->getRestrictions()->removeAll();
return $queryBuilder->delete(self::ASSOCIATION_TABLE_NAME)->where('expires <= ' . time())->execute();
Expand All @@ -110,6 +114,7 @@ public function cleanupAssociations()
public function getAssociation($serverUrl, $handle = null)
{
$this->cleanupAssociations();
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::ASSOCIATION_TABLE_NAME);
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder->select('uid', 'content')->from(self::ASSOCIATION_TABLE_NAME)->where(
Expand Down Expand Up @@ -147,6 +152,7 @@ public function getAssociation($serverUrl, $handle = null)
*/
public function removeAssociation($serverUrl, $handle)
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::ASSOCIATION_TABLE_NAME);
$queryBuilder->getRestrictions()->removeAll();
$deletedCount = $queryBuilder
Expand All @@ -166,6 +172,7 @@ public function removeAssociation($serverUrl, $handle)
public function cleanupNonces()
{
$where = 'crdate < ' . (time() - self::NONCE_STORAGE_TIME);
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::NONCE_TABLE_NAME);
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder->delete(self::NONCE_TABLE_NAME)->where($where)->execute();
Expand All @@ -189,6 +196,7 @@ public function useNonce($serverUrl, $timestamp, $salt)
'server_url' => $serverUrl,
'tstamp' => $timestamp
];
/** @var Connection $connection */
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::NONCE_TABLE_NAME);
$affectedRows = $connection->createQueryBuilder()->insert(self::NONCE_TABLE_NAME)->values($values)->execute();
$result = $affectedRows > 0;
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"authors": [
{
"name": "Dmitry Dulepov",
"email": "dmitry@typo3.org",
"email": "dmitry[email protected]",
"role": "Developer"
},
{
Expand All @@ -21,9 +21,8 @@
"ext-gmp": "*",
"ext-curl": "*",
"ext-dom": "*",
"typo3/cms-core": "~8.5",
"typo3/cms-sv": "~8.5",
"typo3/cms-setup": "~8.5"
"typo3/cms-core": ">=8.7.19,<=9.5.999",
"typo3/cms-setup": ">=8.7.19,<=9.5.999"
},
"replace": {
"openid": "self.version",
Expand Down
7 changes: 3 additions & 4 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
'uploadfolder' => 0,
'createDirs' => '',
'clearCacheOnLoad' => 0,
'version' => '8.0.2',
'version' => '9.5.0',
'constraints' => [
'depends' => [
'typo3' => '8.7.0-8.7.99',
'sv' => '8.7.0-8.7.99',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you removed it due to not being available in v9 anymore. I still suggest adding it to the suggests section, in order to have a correct dependency chain (loading order) in v8.
It is of course not critical as core extensions are loaded first anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not critical because openid can be loaded in any order. It does not use anything from other extensions during TYPO3 initialisation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just ignore that. Otherwise it may confuse people when installing the ext in the EM.

'setup' => '8.7.0-8.7.99',
'typo3' => '8.7.19-9.5.999',
'setup' => '8.7.19-9.5.999',
],
'conflicts' => [
'naw_openid' => '',
Expand Down