Skip to content

Commit 665a831

Browse files
authored
Merge pull request #417 from ineilson/multiple-apiauth
Same API identifier at multiple sites to master.
2 parents fc2d676 + 91e8f9a commit 665a831

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

htdocs/PI/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,10 @@ function authByIdentifier($forceStrictForHosts = false) {
398398
// Check if it is registered API Authentication credential.
399399

400400
$authEntServ = \Factory::getAPIAuthenticationService();
401-
$authEnt = $authEntServ->getAPIAuthentication($this->identifier);
401+
$authEnts = $authEntServ->getAPIAuthentication($this->identifier);
402402

403-
if (!is_null($authEnt)) {
404-
$authEntServ->updateLastUseTime($authEnt);
403+
if (count($authEnts) > 0) {
404+
$authEntServ->updateLastUseTime($authEnts);
405405
$authenticated = true;
406406
}
407407

htdocs/web_portal/static_html/goc5_logo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- <img src="img/Logo-1.6.png" class="logo_image" height="39" style="vertical-align: middle;"/>-->
55
<h3 class="Logo_Text Small_Bottom_Margin Standard_Padding"
66
style="vertical-align: middle; margin-left: 0.2em;">
7-
GOCDB 5.10.2
7+
GOCDB 5.10.3
88
</h3>
99

1010
</a>

lib/Gocdb_Services/APIAuthenticationService.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function __construct() {
3737
* Returns the APIAuthentication entity associated with the given identifier.
3838
*
3939
* @param string $ident Identifier (e.g. X.509 DN as string)
40-
* @return \APIAuthentication APIAuthentication associated with this identifier
40+
* @return \APIAuthentication[] APIAuthentication associated with this identifier
4141
*/
4242
public function getAPIAuthentication($ident) {
4343

@@ -48,12 +48,13 @@ public function getAPIAuthentication($ident) {
4848
$dql = "SELECT a FROM APIAuthentication a " .
4949
"WHERE (a.identifier = :ident)" ;
5050

51+
/* @var $qry \Doctine\DBAL\query */
5152
$qry = $this->em->createQuery($dql);
5253
$qry->setParameter('ident', $ident);
5354

54-
$apiAuth = $qry->getOneOrNullResult();
55+
$apiAuths = $qry->getResult();
5556

56-
return $apiAuth;
57+
return $apiAuths;
5758
}
5859

5960
/**
@@ -188,17 +189,19 @@ public function editAPIAuthentication(\APIAuthentication $authEntity, \User $use
188189
/**
189190
* Set the last use time field to the current UTC time
190191
*
191-
* @param \APIAuthentication $authEntity entity to update
192+
* @param \APIAuthentication[] $authEntities entity to update
192193
* @throws \Exception if the update fails
193194
*/
194-
public function updateLastUseTime(\APIAuthentication $authEntity) {
195-
195+
public function updateLastUseTime(array $authEntities)
196+
{
196197
$this->em->getConnection()->beginTransaction();
197198

198199
try {
199-
$authEntity->setLastUseTime();
200-
201-
$this->em->persist($authEntity);
200+
/* @var \APIAuthentication $authEntity */
201+
foreach ($authEntities as $authEntity) {
202+
$authEntity->setLastUseTime();
203+
$this->em->persist($authEntity);
204+
}
202205

203206
$this->em->flush();
204207
$this->em->getConnection()->commit();
@@ -220,14 +223,15 @@ public function updateLastUseTime(\APIAuthentication $authEntity) {
220223
*/
221224
public function uniqueAPIAuthEnt(\Site $site, $identifier, $type) {
222225

223-
$authEnt = $this->getAPIAuthentication($identifier, $type);
226+
$authEntities = $this->getAPIAuthentication($identifier, $type);
224227

225-
if (!is_null($authEnt) &&
226-
$authEnt->getParentSite()->getId() == $site->getId()) {
227-
throw new \Exception(
228-
"An authentication object of type \"$type\" and with identifier " .
229-
"\"$identifier\" already exists for " . $site->getName()
230-
);
228+
foreach ($authEntities as $authEnt) {
229+
if ($authEnt->getParentSite()->getId() == $site->getId()) {
230+
throw new \Exception(
231+
"An authentication object of type \"$type\" and with identifier " .
232+
"\"$identifier\" already exists for " . $site->getName()
233+
);
234+
}
231235
}
232236
}
233237
/**

tests/unit/lib/Gocdb_Services/APIAuthenticationServiceTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,11 @@ public function testGetAPIAuthentication()
170170

171171
$ident = '/CN=A Dummy Subject';
172172
$type = 'X.509';
173-
// Start with no APIAuthentication entities to be found
174-
$this->assertNull(
173+
// Start with no APIAuthentication entities to be found
174+
$this->assertCount(
175+
0,
175176
$authEntServ->getAPIAuthentication($ident),
176-
"Non-null value returned when searching for APIAuthentication entity " .
177+
"Non-zero count returned when searching for APIAuthentication entity " .
177178
"for id:{$ident} when expected none."
178179
);
179180

@@ -194,9 +195,15 @@ public function testGetAPIAuthentication()
194195

195196
$authEntMatched = $authEntServ->getAPIAuthentication($ident);
196197

198+
$this->assertCount(
199+
1,
200+
$authEntMatched,
201+
"Failed to return single APIAuthentication entity searching for id:{$ident}."
202+
);
203+
197204
$this->assertTrue(
198-
$authEnt === $authEntMatched,
199-
"Failed to return APIAuthentication entity for id:{$ident}."
205+
$authEnt === $authEntMatched[0],
206+
"Failed to return matching APIAuthentication entity searching for for id:{$ident}."
200207
);
201208
}
202209
}

0 commit comments

Comments
 (0)