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

Add an access_test method to API to dev #402

Merged
merged 5 commits into from
Dec 6, 2022
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
16 changes: 13 additions & 3 deletions htdocs/PI/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ function getXml() {
$em = \Factory::getEntityManager();

switch ($this->method) {
case "access_test":
require_once($directory . 'AccessTest.php');
$this->authByIdentifier(true);
$xml = (new AccessTest())->getRenderingOutput();
break;
case "get_site":
require_once($directory . 'GetSite.php');
$this->authByIdentifier();
Expand Down Expand Up @@ -367,9 +372,14 @@ function getXml() {
return $xml;
}

/* Authorize a request based on the supplied identifier */
/*
* Authorize a request based on the supplied identifier
* @param boolean $forceStrictForHosts If true, restriction of
* personal data is forced
* for hosts.
*/

function authByIdentifier() {
function authByIdentifier($forceStrictForHosts = false) {
require_once __DIR__.'/../web_portal/controllers/utils.php';
require_once __DIR__.'/../../lib/Doctrine/entities/APIAuthentication.php';

Expand All @@ -395,7 +405,7 @@ function authByIdentifier() {
$authenticated = true;
}

if (!\Factory::getConfigService()->isRestrictPDByRole()) {
if (!\Factory::getConfigService()->isRestrictPDByRole($forceStrictForHosts)) {
// Only a 'valid' identifier is needed.
$authenticated = true;
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/web_portal/static_html/goc5_logo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- <img src="img/Logo-1.6.png" class="logo_image" height="39" style="vertical-align: middle;"/>-->
<h3 class="Logo_Text Small_Bottom_Margin Standard_Padding"
style="vertical-align: middle; margin-left: 0.2em;">
GOCDB 5.10.1
GOCDB 5.10.2
</h3>

</a>
Expand Down
8 changes: 7 additions & 1 deletion lib/Gocdb_Services/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,15 @@ public function GetPortalURL() {
/**
* How Personal Data is restricted;
* See description in local_info.xml but in brief:
* @param boolean $forceStrict If true, restriction of personal data
* is forced.
* @returns false for legacy behaviour, true for role-based personal data restriction
*/
public function isRestrictPDByRole() {
public function isRestrictPDByRole($forceStrict = false)
{
if ($forceStrict === true)
return true;

$localInfo = $this->GetLocalInfoXML();
$value = $localInfo->restrict_personal_data;
if((string) $value == "true") {
Expand Down
32 changes: 32 additions & 0 deletions lib/Gocdb_Services/PI/AccessTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Class to manage output of the Access Test result
*/

namespace org\gocdb\services;

use SimpleXMLElement;

class AccessTest
{
/**
* @return string XML used to signal successful authorization return
*/
public function getRenderingOutput()
{
$xmlElem = new SimpleXMLElement("<results />");
$xmlElem->addAttribute('identifier', Get_User_Principle_PI());
$xmlElem->addChild('authorized', 'true');

$domSxe = dom_import_simplexml($xmlElem);

$dom = new \DOMDocument('1.0');
$dom->encoding = 'UTF-8';
$domSxe = $dom->importNode($domSxe, true);
$domSxe = $dom->appendChild($domSxe);
$dom->formatOutput = true;

return $dom->saveXML();
}
}