diff --git a/htdocs/PI/index.php b/htdocs/PI/index.php index 3c90c59e7..e74c29d6b 100644 --- a/htdocs/PI/index.php +++ b/htdocs/PI/index.php @@ -398,10 +398,10 @@ function authByIdentifier($forceStrictForHosts = false) { // Check if it is registered API Authentication credential. $authEntServ = \Factory::getAPIAuthenticationService(); - $authEnt = $authEntServ->getAPIAuthentication($this->identifier); + $authEnts = $authEntServ->getAPIAuthentication($this->identifier); - if (!is_null($authEnt)) { - $authEntServ->updateLastUseTime($authEnt); + if (count($authEnts) > 0) { + $authEntServ->updateLastUseTime($authEnts); $authenticated = true; } diff --git a/htdocs/web_portal/static_html/goc5_logo.html b/htdocs/web_portal/static_html/goc5_logo.html index 4d96abe9f..37cd6ed9f 100644 --- a/htdocs/web_portal/static_html/goc5_logo.html +++ b/htdocs/web_portal/static_html/goc5_logo.html @@ -4,7 +4,7 @@

- GOCDB 5.10.2 + GOCDB 5.10.3

diff --git a/lib/Gocdb_Services/APIAuthenticationService.php b/lib/Gocdb_Services/APIAuthenticationService.php index 60e10ab01..1e14f476b 100644 --- a/lib/Gocdb_Services/APIAuthenticationService.php +++ b/lib/Gocdb_Services/APIAuthenticationService.php @@ -37,7 +37,7 @@ function __construct() { * Returns the APIAuthentication entity associated with the given identifier. * * @param string $ident Identifier (e.g. X.509 DN as string) - * @return \APIAuthentication APIAuthentication associated with this identifier + * @return \APIAuthentication[] APIAuthentication associated with this identifier */ public function getAPIAuthentication($ident) { @@ -48,12 +48,13 @@ public function getAPIAuthentication($ident) { $dql = "SELECT a FROM APIAuthentication a " . "WHERE (a.identifier = :ident)" ; + /* @var $qry \Doctine\DBAL\query */ $qry = $this->em->createQuery($dql); $qry->setParameter('ident', $ident); - $apiAuth = $qry->getOneOrNullResult(); + $apiAuths = $qry->getResult(); - return $apiAuth; + return $apiAuths; } /** @@ -188,17 +189,19 @@ public function editAPIAuthentication(\APIAuthentication $authEntity, \User $use /** * Set the last use time field to the current UTC time * - * @param \APIAuthentication $authEntity entity to update + * @param \APIAuthentication[] $authEntities entity to update * @throws \Exception if the update fails */ - public function updateLastUseTime(\APIAuthentication $authEntity) { - + public function updateLastUseTime(array $authEntities) + { $this->em->getConnection()->beginTransaction(); try { - $authEntity->setLastUseTime(); - - $this->em->persist($authEntity); + /* @var \APIAuthentication $authEntity */ + foreach ($authEntities as $authEntity) { + $authEntity->setLastUseTime(); + $this->em->persist($authEntity); + } $this->em->flush(); $this->em->getConnection()->commit(); @@ -220,14 +223,15 @@ public function updateLastUseTime(\APIAuthentication $authEntity) { */ public function uniqueAPIAuthEnt(\Site $site, $identifier, $type) { - $authEnt = $this->getAPIAuthentication($identifier, $type); + $authEntities = $this->getAPIAuthentication($identifier, $type); - if (!is_null($authEnt) && - $authEnt->getParentSite()->getId() == $site->getId()) { - throw new \Exception( - "An authentication object of type \"$type\" and with identifier " . - "\"$identifier\" already exists for " . $site->getName() - ); + foreach ($authEntities as $authEnt) { + if ($authEnt->getParentSite()->getId() == $site->getId()) { + throw new \Exception( + "An authentication object of type \"$type\" and with identifier " . + "\"$identifier\" already exists for " . $site->getName() + ); + } } } /** diff --git a/tests/unit/lib/Gocdb_Services/APIAuthenticationServiceTest.php b/tests/unit/lib/Gocdb_Services/APIAuthenticationServiceTest.php index 39b6b486d..2888d6f38 100644 --- a/tests/unit/lib/Gocdb_Services/APIAuthenticationServiceTest.php +++ b/tests/unit/lib/Gocdb_Services/APIAuthenticationServiceTest.php @@ -170,10 +170,11 @@ public function testGetAPIAuthentication() $ident = '/CN=A Dummy Subject'; $type = 'X.509'; - // Start with no APIAuthentication entities to be found - $this->assertNull( + // Start with no APIAuthentication entities to be found + $this->assertCount( + 0, $authEntServ->getAPIAuthentication($ident), - "Non-null value returned when searching for APIAuthentication entity " . + "Non-zero count returned when searching for APIAuthentication entity " . "for id:{$ident} when expected none." ); @@ -194,9 +195,15 @@ public function testGetAPIAuthentication() $authEntMatched = $authEntServ->getAPIAuthentication($ident); + $this->assertCount( + 1, + $authEntMatched, + "Failed to return single APIAuthentication entity searching for id:{$ident}." + ); + $this->assertTrue( - $authEnt === $authEntMatched, - "Failed to return APIAuthentication entity for id:{$ident}." + $authEnt === $authEntMatched[0], + "Failed to return matching APIAuthentication entity searching for for id:{$ident}." ); } }