/circulation-saml-test

Testbed which could be used for testing SAML-based patron authentication in Circulation Manager (part of https://librarysimplified.org/)

Primary LanguagePythonMIT LicenseMIT

circulation-saml-test

Testbed which could be used for testing SAML-based patron authentication in Circulation Manager.

Architecture

Project consists of the following modules:

The architecture of the testbed is shown in the picture below: Testbed architecture

  • cm-test.hilbertteam.net is a circulation-test instance used for authenticating and downloading books using Circulation Manager (cm.hilbertteam.net)
  • cm.hilbertteam.net is a Circulation Manager instance with a SAML authentication provider acting as a SAML Service Provider (SP)
  • idp.hilbertteam.net is a shibboleth-idp instance acting as a SAML Identity Provider (IdP)
  • opds.hilbertteam.net and opds.hilbert.team are two instances of flask-sp serving two different OPDS feeds using SAML

Usage


For circulation manager developers

In case this environment is being used to test out SAML authentication integration with an already running CM on a development machine docker-compose-saml-test.yml can be used instead This file does not contain the db,es,cm and cm-test services.


Preparing the local environment

  1. Update host names in .env file
  2. Replace all the host names with 127.0.0.1 in etc/hosts file:
127.0.0.1     idp.hilbertteam.net
127.0.0.1     opds.hilbertteam.net
127.0.0.1     opds.hilbert.team
127.0.0.1     cm.hilbertteam.net
127.0.0.1     cm-test.hilbertteam.net
  1. Build containers:
docker-compose build
  1. Run metadata service to generate SAML metadata first (we need to run it first because it's used by other services):
docker-compose up -d metadata

NOTE: If the metadata service runs multiple times (over the course of development) it may overwrite the the output files In which case one would get an error while trying to authenticate

The application you have accessed is not registered for use with this service.

In this case please ensure the output cm.xml and idp.xml still match what has been set in the CM's Patron Authentication

  1. Run all other services:
docker-compose up -d

Setting up Circulation Manager

Setting up a new administrator account

  1. Open Circulation Manager and set up an administrator account: Setting up an administrator account

  2. Login into Circulation Manager: Logging into Circulation Manager

Setting up a new library

  1. Login into Circulation Manager: Setting up Circulation Manager

  2. Start setting up a new library by clicking on Create new library: Setting up a new library

  3. Fill in new library details: Setting up a new library

  4. Scroll down, click on Submit and wait until new library is created: Setting up a new library

Setting up new collections

  1. Click on Collections to start setting up collections: Setting up a new collection

  2. Click on Create new collection: Setting up a new collection

  3. Fill in details of a new collection using OPDS1_HOSTNAME as a URL: Setting up a new collection

  4. Scroll down, associate the new collection with the library, click on Add library and then click on Submit: Setting up a new collection

  5. Create a new collection using OPDS2_HOSTNAME as a URL: Setting up a new collection

Setting up a SAML authentication provider

  1. Click on Patron authentication to start setting up a SAML authentication provider: Setting up a SAML authentication provider

  2. Click on Create new patron authentication service: Setting up a SAML authentication provider

  3. Fill in patron details using cm.xml to fill in SP details and idp.xml to fill in IdP details: Setting up a SAML authentication provider

  4. Scroll down, associate the library with the provider and click on Add library: Setting up a SAML authentication provider

  5. Click on Submit to finish creating a new authentication provider: Setting up a SAML authentication provider

Setting up an Elasticsearch service

  1. Click on Search to start setting up an Elasticsearch service: Setting up an Elasticsearch service

  2. Click on Create new search service: Setting up an Elasticsearch service

  3. Fill in details of an Elasticsearch service using es as a URL: Setting up an Elasticsearch service

Importing the OPDS feeds

  1. Connect to the Circulation Manager's Docker container:
docker-compose exec cm bash
  1. Activate a Python virtual environment:
(env)> source env/bin/activate
  1. Import the OPDS feeds:
(env)> bin/opds_import_monitor
  1. Update the Elasticsearch indices:
(env)> bin/search_index_refresh

Testing SAML authentication

  1. Open Circulation Manager test application and click on Authenticate to start authentication process: Authenticating with Circulation Manager

  2. Enter credentials from init-users.ldif.tmpl: Authenticating with Circulation Manager

ℹ️ If you face an authentication issue, it might be because the LDAP server failed to import users. Please refer to Troubleshooting section for detailed instructions how to resolve this issue.

  1. Click on Accept on the consent screen: Authenticating with Circulation Manager

  2. Borrow a book clicking on Borrow, wait until the operation is finished and then return back: Borrowing a book

  3. Download a book by clicking on Download: Downloading a book

  4. Observe the downloaded book: Downloading a book

Troubleshooting

LDAP users don't get imported

Please note that sometimes LDAP server doesn't import correctly which results in authentication errors. To resolve this issue you will need to do the following:

docker-compose exec ldap bash

bash> ldapadd -x -D"cn=Directory Manager" -w${LDAP_MANAGER_PASSWORD} -f /init-users.ldif

Circulation Manager test applications errors out with error code 500

Sometimes during development and rebuilding/restarting of the containers you get error with the error code 500 when accessing Circulation Manager test application. Reason might be stale access token that gets rejected by the Circulation Manager. Solution is to delete the session cookie on the Circulation Manager test application and refresh the page.

Books don't show up

If you don't see any books in the admin UI or SimplyE, it might because the Elasticsearch server failed to import metadata because the cluster is in read-only state. To resolve the issue you need to do the following:

  1. Update the Elasticsearch indices:
docker-compose exec es bash

bash> curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'
bash> curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

bash> exit
  1. Truncate work coverage records to be able to recreate the search index:
docker-compose exec db bash

psql -U simplified simplified_circulation_dev  # Please use the credentials from .env file
psql> truncate workcoveragerecords;
psql> exit;

bash> exit
  1. Recreate the search index:
docker-compose exec cm bash

bash>  source env/bin/activate
(env)> bin/search_index_refresh
(env)> exit
  1. Clear the CM's cache:
docker-compose exec db bash

psql -U simplified simplified_circulation_dev  # Please use the credentials from .env file
psql> truncate cachedfeeds;
psql> exit;

bash> exit