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 CAS Authentication for VuFind VUFIND-422 #13

Closed
wants to merge 32 commits into from
Closed

Add CAS Authentication for VuFind VUFIND-422 #13

wants to merge 32 commits into from

Conversation

misilot
Copy link
Contributor

@misilot misilot commented Aug 9, 2013

Supports CAS authentication with the ability to set configuration via config.ini

@misilot
Copy link
Contributor Author

misilot commented Aug 9, 2013

Supersedes #12

@misilot
Copy link
Contributor Author

misilot commented Aug 9, 2013

@bemosior this should resolve the issue you were having.

@bemosior
Copy link
Contributor

I got this mostly implemented today. For the most part, everything appears to be working well.

Thoughts/questions:

  • Is there a way to assign the VuFind username (or other attributes) as the CAS principal? A workaround is to also pass the username as a SAML attribute, but it would be easier to say username = principal or username = username.
  • One of the available attributes should be the cat_password, since (at least in some cases) the catalog password is an attribute that can be passed by CAS.
    • There would also have to be logic to handle both cat_password and cat_pass_enc (the encrypted catalog password), as the case may be. I haven't checked the code, but VuFind might automatically handle that part.
  • If a target URL is specified (such as /vufind/, the user fails to be logged in (login button remains) unless they physically access /vufind/MyResearch/Home. This may just be a VuFind quirk.
  • In the config.ini, Required: CAS server URL makes more sense to be Required: CAS Hostname.

That's all I found. Thanks for putting this together!

@misilot
Copy link
Contributor Author

misilot commented Aug 12, 2013

Is there a way to assign the VuFind username (or other attributes) as the CAS principal?

What do you mean by this, that is what the cat_username is for no?

One of the available attributes should be the cat_password, since (at least in some cases) the catalog password is an attribute that can be passed by CAS.

I am working on adding the cat_password field to both the CAS and Shibboleth Auth (https://github.com/misilot/vufind/commit/86f4d41780c7b4eb8d9c333f7b59d3bdecf9491a and #15 ). The cat_pass_enc I am not sure we can add, at least how VuFind is currently written. @demiankatz, what do you think?

If a target URL is specified (such as /vufind/, the user fails to be logged in (login button remains) unless they physically access /vufind/MyResearch/Home. This may just be a VuFind quirk.

I think this is a VuFind quirk, as I think this is how it acted. Not sure if there is a way or where a good place would be in order to add in a \phpCAS::checkAuthentication(); at some point on every page load (that would require running the Auth() script everytime though as well, so phpCAS could be initialized.

In the config.ini, Required: CAS server URL makes more sense to be Required: CAS Hostname.
Made change see ef1871b

@bemosior
Copy link
Contributor

What do you mean by this, that is what the cat_username is for no?

VuFind uses an internal username for the MySQL entry it adds. For user identification and debugging purposes it might be nice to populate that with the principal, while cat_username and cat_password remain ILS-specific.

Thanks!

;[CAS]

; Required: the attribute CAS uses to uniquely identify users.
;username = uid
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what sets the VuFind username in the database. Not sure if I am still missing something.

@bemosior
Copy link
Contributor

It might just be confusion on my part. CAS returns a principal in the SAML assertion that is literally what the user types into the username field. The question is which "attribute" can be used to to assign the principal to a VuFind user field.

In the below example, "bemosior" is the principal:

<saml1:AttributeStatement>
    <saml1:Subject>
        <saml1:NameIdentifier>bemosior</saml1:NameIdentifier>
        <saml1:SubjectConfirmation>
            <saml1:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:artifact</saml1:ConfirmationMethod>
        </saml1:SubjectConfirmation>
    </saml1:Subject>
    <saml1:Attribute AttributeName="sn" AttributeNamespace="http://www.ja-sig.org/products/cas/">
        <saml1:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Mosior</saml1:AttributeValue>
    </saml1:Attribute>
    <saml1:Attribute AttributeName="catalog_barcode" AttributeNamespace="http://www.ja-sig.org/products/cas/">
        <saml1:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">123456789</saml1:AttributeValue>
    </saml1:Attribute>
</saml1:AttributeStatement>

It doesn't seem to have an attribute name in the same sense as "catalog_barcode".

@demiankatz
Copy link
Member

Regarding running \phpCAS::checkAuthentication(); on every page load, you might be able to achieve that with ZF2's event system if it's actually necessary.... but I don't know enough about CAS to fully understand the situation; is there a way to force targets to route throught MyResearch/Home so that this is unnecessary?

@misilot
Copy link
Contributor Author

misilot commented Aug 13, 2013

@bemosior the saml1:NameIdentifier attribute can be gotten from the function phpCAS::getUser(), and it will return the username in whatever case the user entered it. For example. If I enter mIsILOt it will return mIsILOt, or if I enter misilot it will return misilot. I would think most people would want to pull the username from CAS as an authoritative attribute if they are going to be storing in a database as such. That is why I used the attribute uid as that contains their username that is in LDAP. Is it not possible to get an attribute from CAS for the principal?

@demiankatz
Copy link
Member

I agree that it sounds like you wouldn't want to use the raw user input as the VuFind username, as that could cause weird inconsistent behavior. If anything, perhaps you would want to log that as a debug message or something.

@bemosior
Copy link
Contributor

@misilot and @demiankatz, that's a good point. I forgot that I had encountered a similar issue like that before (we ended up dealing with it cheaply by using fn:toLowerCase because the situation allowed), so the username question is a non-issue.

As far as the PR, I think we're in good shape once the cat_password is routed through saveCredentials().

@misilot
Copy link
Contributor Author

misilot commented Aug 14, 2013

@bemosior When you have a chance can you test this? Thanks!

@bemosior
Copy link
Contributor

I'm away on vacation and unable to test until the 26th; I apologize for the delay!

…ulled from the config file)

Thanks to Brad Busenius.
Resolves VUFIND-815.
…serves/new items).

Resolves VUFIND-873; thanks to David Lacy for reporting the problem.
@misilot
Copy link
Contributor Author

misilot commented Aug 20, 2013

@bemosior No problem. Thanks :) Enjoy your vacation.

@demiankatz
Copy link
Member

Too bad regarding phpCAS -- sounds like dev-master is the best option for now, but we should change it to a stable release as soon as that becomes possible.

I need to read up on all the features of the PR system; I know that I could be using it better than I am at the moment, but I haven't taken the time to study all the possibilities.

@misilot
Copy link
Contributor Author

misilot commented Aug 26, 2013

Made recommended changes for storing the cat_password as a temp value.

@bemosior
Copy link
Contributor

I had an interesting problem with getting the catalog password to be populated. After some debugging, I found a typo:

--- a/module/VuFind/src/VuFind/Auth/CAS.php
+++ b/module/VuFind/src/VuFind/Auth/CAS.php
@@ -157,7 +160,7 @@ class CAS extends AbstractBase

         // Save credentials if applicable:
         if (!empty ($catPassword) && !empty($user->cat_username)) {
-           $user->saveCredentials($user->cat_username, $casPassword);
+           $user->saveCredentials($user->cat_username, $catPassword);

         }

That seems to fix the issue for both encrypted and unencrypted catalog password fields.

I'm also having problems with convincing VuFind to use those credentials to authenticate against the ILS, but that is probably a local config issue. I'll work on figuring it out in the meantime (I need to anyway).

@misilot
Copy link
Contributor Author

misilot commented Sep 13, 2013

Since there have been a couple of releases since I created this PR, I am going to replace this PR with a current one, so it can be included possible in one of the next releases.

I will close this PR once the new one is made. (That way I can find the code :) )

@demiankatz
Copy link
Member

Sounds good -- I don't think there have been any major changes that should affect this code, so hopefully updating the PR won't be too much work. I've been waiting to hear more from Benjamin before merging this -- any news on those ILS authentication issues?

@bemosior
Copy link
Contributor

I'm having some idiot issues with Voyager authentication and VF2. I'll post on the list early next week to hopefully work through it, but there's no reason the CAS authentication shouldn't work based on the testing I completed previously.

@demiankatz
Copy link
Member

Thanks for the clarification. In that case, I'll review and merge the new PR as soon as it arrives.

@misilot misilot closed this Sep 27, 2013
EreMaijala added a commit to EreMaijala/vufind that referenced this pull request Jun 17, 2015
olli-gold pushed a commit to olli-gold/vufind that referenced this pull request Jun 20, 2016
fixes style issues in DAIA.php and PAIA.php
skellamp added a commit to skellamp/vufind that referenced this pull request Jun 14, 2023
dltj added a commit to dltj/vufind that referenced this pull request Oct 7, 2024
This corrects a problem with new VuFind users being created from a Shibboleth login. Without this change, we see this exception and stack trace:

```
2024-10-07T14:04:23-04:00 ERR (3): VuFind\Auth\Manager: Laminas\Db\RowGateway\Exception\InvalidArgumentException: Not a valid column in this row: cat_password in /usr/local/vufind-pmalibrary/vendor/laminas/laminas-db/src/RowGateway/AbstractRowGateway.php:294
Stack trace:
#0 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Db/Row/User.php(964): Laminas\Db\RowGateway\AbstractRowGateway->__get()
vufind-org#1 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Auth/ILSAuthenticator.php(224): VuFind\Db\Row\User->getRawCatPassword()
vufind-org#2 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Auth/Shibboleth.php(240): VuFind\Auth\ILSAuthenticator->getCatPasswordForUser()
vufind-org#3 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Auth/Manager.php(743): VuFind\Auth\Shibboleth->authenticate()
vufind-org#4 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Controller/MyResearchController.php(217): VuFind\Auth\Manager->login()
vufind-org#5 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-mvc/src/Controller/AbstractActionController.php(72): VuFind\Controller\MyResearchController->homeAction()
vufind-org#6 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Controller/Feature/CatchIlsExceptionsTrait.php(76): Laminas\Mvc\Controller\AbstractActionController->onDispatch()
vufind-org#7 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-eventmanager/src/EventManager.php(319): VuFind\Controller\MyResearchController->onDispatch()
vufind-org#8 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-eventmanager/src/EventManager.php(177): Laminas\EventManager\EventManager->triggerListeners()
vufind-org#9 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-mvc/src/Controller/AbstractController.php(105): Laminas\EventManager\EventManager->triggerEventUntil()
vufind-org#10 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-mvc/src/DispatchListener.php(117): Laminas\Mvc\Controller\AbstractController->dispatch()
vufind-org#11 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-eventmanager/src/EventManager.php(319): Laminas\Mvc\DispatchListener->onDispatch()
vufind-org#12 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-eventmanager/src/EventManager.php(177): Laminas\EventManager\EventManager->triggerListeners()
vufind-org#13 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-mvc/src/Application.php(319): Laminas\EventManager\EventManager->triggerEventUntil()
vufind-org#14 /usr/local/vufind-pmalibrary/public/index.php(71): Laminas\Mvc\Application->run()
```
demiankatz pushed a commit to dltj/vufind that referenced this pull request Oct 8, 2024
This corrects a problem with new VuFind users being created from a Shibboleth login. Without this change, we see this exception and stack trace:

```
2024-10-07T14:04:23-04:00 ERR (3): VuFind\Auth\Manager: Laminas\Db\RowGateway\Exception\InvalidArgumentException: Not a valid column in this row: cat_password in /usr/local/vufind-pmalibrary/vendor/laminas/laminas-db/src/RowGateway/AbstractRowGateway.php:294
Stack trace:
#0 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Db/Row/User.php(964): Laminas\Db\RowGateway\AbstractRowGateway->__get()
vufind-org#1 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Auth/ILSAuthenticator.php(224): VuFind\Db\Row\User->getRawCatPassword()
vufind-org#2 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Auth/Shibboleth.php(240): VuFind\Auth\ILSAuthenticator->getCatPasswordForUser()
vufind-org#3 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Auth/Manager.php(743): VuFind\Auth\Shibboleth->authenticate()
vufind-org#4 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Controller/MyResearchController.php(217): VuFind\Auth\Manager->login()
vufind-org#5 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-mvc/src/Controller/AbstractActionController.php(72): VuFind\Controller\MyResearchController->homeAction()
vufind-org#6 /usr/local/vufind-pmalibrary/module/VuFind/src/VuFind/Controller/Feature/CatchIlsExceptionsTrait.php(76): Laminas\Mvc\Controller\AbstractActionController->onDispatch()
vufind-org#7 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-eventmanager/src/EventManager.php(319): VuFind\Controller\MyResearchController->onDispatch()
vufind-org#8 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-eventmanager/src/EventManager.php(177): Laminas\EventManager\EventManager->triggerListeners()
vufind-org#9 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-mvc/src/Controller/AbstractController.php(105): Laminas\EventManager\EventManager->triggerEventUntil()
vufind-org#10 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-mvc/src/DispatchListener.php(117): Laminas\Mvc\Controller\AbstractController->dispatch()
vufind-org#11 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-eventmanager/src/EventManager.php(319): Laminas\Mvc\DispatchListener->onDispatch()
vufind-org#12 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-eventmanager/src/EventManager.php(177): Laminas\EventManager\EventManager->triggerListeners()
vufind-org#13 /usr/local/vufind-pmalibrary/vendor/laminas/laminas-mvc/src/Application.php(319): Laminas\EventManager\EventManager->triggerEventUntil()
vufind-org#14 /usr/local/vufind-pmalibrary/public/index.php(71): Laminas\Mvc\Application->run()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants