Skip to content

Commit

Permalink
[FINNA-2393] Add proper authentication support.
Browse files Browse the repository at this point in the history
  • Loading branch information
EreMaijala committed Jun 27, 2024
1 parent cf409f1 commit fba4f21
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions conf/datasources.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
;
; RecordManager settings:
; type Harvester type (HTTPFiles, OAI-PMH (default), SFX, SierraApi)
; url Harvesting URL
; username Username for HTTP authentication (OAI-PMH, HTTPFiled)
; password Password for HTTP authentication (OAI-PMH, HTTPFiled)
; authType Authentication type for HTTP authentication (OAI-PMH, HTTPFiled).
; Allowed options are "basic" (default), "digest" and "ntlm".
; Digest and NTLM authentication require the Curl adapter to be used (see HTTP section in recordmanager.ini).
; institution The institution code mapped to the source (required)
; recordXPath xpath expression used when loading records from a file to identify a single record (optional, e.g. //record)
; format Record format in RecordManager
Expand Down Expand Up @@ -165,6 +171,8 @@
;[arc]
;institution = MyInst
;url = http://oai-pmh.ead-server/request
;username = "user"
;password = "secret"
;metadataPrefix = ead
;recordSplitterClass = "\RecordManager\Base\Splitter\Ead"
;format = ead
Expand Down
12 changes: 12 additions & 0 deletions src/RecordManager/Base/Harvest/AbstractBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ abstract class AbstractBase
*/
protected $baseURL = null;

/**
* HTTP authentication settings
*
* @var ?array
*/
protected $httpAuth = null;

/**
* Source ID
*
Expand Down Expand Up @@ -255,6 +262,11 @@ public function init(string $source, bool $verbose, bool $reharvest): void
}
$this->baseURL = $settings['url'];

if (($username = $settings['username']) && ($password = $settings['password'])) {
$type = $settings['authType'] ?? 'basic';
$this->httpAuth = [$username, $password, $type];
}

if (!empty($settings['preTransformation'])) {
foreach ((array)$settings['preTransformation'] as $transformation) {
$style = new \DOMDocument();
Expand Down
2 changes: 1 addition & 1 deletion src/RecordManager/Base/Harvest/HTTPFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected function retrieveFileList()
protected function retrieveFile($filename)
{
$url = $this->baseURL . $filename;
$request = $this->httpService->createClient($url);
$request = $this->httpService->createClient($url, ['auth' => $this->httpAuth]);
$this->infoMsg("Sending request: $url");

// Perform request and throw an exception on error:
Expand Down
2 changes: 1 addition & 1 deletion src/RecordManager/Base/Harvest/OaiPmh.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ protected function normalizeDate($date)
protected function sendRequest($verb, $params = [])
{
// Set up the request:
$client = $this->httpService->createClient($this->baseURL);
$client = $this->httpService->createClient($this->baseURL, ['auth' => $this->httpAuth]);
$params['verb'] = $verb;
$url = $this->httpService->appendQueryParams($this->baseURL, $params);

Expand Down

0 comments on commit fba4f21

Please sign in to comment.