Single Logout Implementation for Shibboleth

151 views
Skip to first unread message

Alexander Ivanov

unread,
Apr 28, 2017, 12:07:25 PM4/28/17
to Dataverse Dev
Hey guys,

we have a Drupal application integrated with a Dataverse instance via Shibboleth IdP/SP, and I'm working on implementing a Single Logout (SLO) solution.

Our Drupal application has support for SLO in the shib_auth module with the setting "auto_destroy_session".  The Drupal application performs a check for whether or not there is a current valid Shibboleth session on every page request.  It checks for the global variable 'Shib-Identity-Provider' which is set by the SP and always present if there is a current valid session.  It also checks for a session variable which is set by the application when a Shibboleth login first takes place.  If the session variable is present but the global Shibboleth variable is not, that means that a Shibboleth login was performed for this user but there is no longer a valid Shibboleth session.  In this scenario, if "auto_destroy_session" is enabled, the user is logged out of the Drupal application.  This means that the IdP-initiated Single Logout process which destroys the user's Shibboleth session also has the effect of logging them out of Drupal.

I wanted to code this same functionality for our Dataverse application.  I created a new JSF filter called ShibAuthFilter to perform a check for a valid Shibboleth session upon every page request.  My code is attached.  The filter checks for the presence of a global variable that has to be present during a valid Shibboleth session, such as "Shib-Identity-Provider" which is set by the SP (https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPAttributeAccess).  It also checks for whether or not the current user had logged in via Shibboleth- is shibIdentityProvider value set for AuthenticatedUser?

I have a couple questions about my implementation:
1) Is a JSF Filter the best way to accomplish this check for valid Shibboleth session upon every page request?  From the documentation that I've read on JSF this seems to be a sensible approach, but perhaps there is a better way which would be more in tune with the application architecture of Dataverse?
2) Can you see any reason off hand why this filter would fail to work properly?  Because currently it doesn't work properly, and I'm in the process of setting up remote debugging in our AWS environment to step through the code.  The filter correctly keeps a user logged in if they did NOT authenticate via Shibboleth.  However, it prevents Shibboleth login completely and logs the user out as soon as they are redirected to /shib.xhtml.  I think that for whatever reason, it is unable to find the global Shibboleth variables that should be present during a Shibboleth session.  I don't understand why, because I used the same syntax to read these global variables as is already used in Shib.java, yet neither of these worked:
Object shibAttribute = httpServletRequest.getAttribute(ShibUtil.uniquePersistentIdentifier);
Object shibAttribute = httpServletRequest.getAttribute("Shib-Identity-Provider");

Thanks in advance for your help.

My Best,
Alex

ShibAuthFilter.java

Philip Durbin

unread,
Apr 28, 2017, 12:17:49 PM4/28/17
to datave...@googlegroups.com
Thanks, Alex! We owe you some code review and answers to your questions so as I mentioned at https://github.com/IQSS/dataverse/issues/3535#issuecomment-298041078 I just moved #3535 to Code Review on our kanban board to remind us to dig into this!

Phil

--
You received this message because you are subscribed to the Google Groups "Dataverse Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dataverse-dev+unsubscribe@googlegroups.com.
To post to this group, send email to datave...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dataverse-dev/1bd928e1-f02e-4de2-8579-966335b8c7f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Alexander Ivanov

unread,
Apr 28, 2017, 12:25:37 PM4/28/17
to Dataverse Dev
Thanks, Phil!

Alexander Ivanov

unread,
May 2, 2017, 1:05:23 AM5/2/17
to datave...@googlegroups.com
Hi all,

I figured out why my implementation didn't work.  The Shibboleth SP does not set global environment variables for Glassfish as it does for Apache: https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPAttributeAccess

In my implementation I was (incorrectly) trying to pull a global server variable by using httpServletRequest.getAttribute, which (as you probably know) actually pulls an attribute value from the HTTP request header.  The Shibboleth request header attributes are only present during the initial Shibboleth login request and not for any subsequent requests.  And since there are no global Shibboleth variables set for Glassfish, there is no way for the Dataverse application to check if the Shibboleth session is still active upon every page request by simply analyzing the global variables vs the session variables.. please correct me if I'm wrong

I found a different way to make Shibboleth Single Logout functional for our implementation.   I created a custom logout page (logout.xhtml) and a new Java class LogoutPage.java.. when the user navigates to this page the user session is destroyed, and the user is redirected to the IdP Profile logout page (https://idp.stage.qdr.org/idp/profile/Logout) which then destroys all active SP sessions effectively logging the user out of Drupal.  I've modified the DataverseHeaderFragment.logout method to do the same thing- destroy the user session and then redirect to the IdP Profile logout page.  And I've added a logout hook to our Drupal application to redirect the user to the new Dataverse logout page.  Therefore, no matter where the user clicks Log Out, the Dataverse session will be destroyed and the user will be sent to the IdP Profile Logout page which will terminate all current Shibboleth sessions for the user, effectively logging the user out of Drupal as well.

I can provide the details to my implementation, but I do not think that it is generalizable

My Best,
Alex


--
You received this message because you are subscribed to a topic in the Google Groups "Dataverse Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dataverse-dev/_PU0SvYvrXc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dataverse-dev+unsubscribe@googlegroups.com.

To post to this group, send email to datave...@googlegroups.com.

Philip Durbin

unread,
May 2, 2017, 3:30:01 PM5/2/17
to datave...@googlegroups.com
Hi Alex,

Thanks for testing and writing. I was staring at your `ShibAuthFilter.java` file and your list of questions again yesterday afternoon trying to think of what to say and you've already learned on your own something I wanted to mention thanks to your own testing. Thanks!

As you noticed, data that is asserted by the IdP is only available when the user is redirected to `Shib.java`. This is our opportunity to capture some of it in the database. The "entityID" of the IdP and the "eppn" are persisted to the `persistentuserid` field of the `authenticateduserlookup`[1] table (separated by a pipe character) and the first name, last name, etc are persisted to various fields in the `authenticateduser`[2] table.

I suppose that while we're looking at the assertion from the IdP we could persist somewhere the "logout" URL such as "https://idp.stage.qdr.org/ idp/profile/Logout" if the IdP asserts it. I'm wondering if it's in the IdP metadata but I don't see it near the "SingleSignOnService" stuff at https://github.com/IQSS/dataverse/blob/v4.6.1/doc/sphinx-guides/source/_static/installation/files/etc/shibboleth/dataverse-idp-metadata.xml#L66 . If it *is* in the IdP metadata, I wonder if we can expose it as JSON just like how DiscoFeed exposes that underlying XML: https://demo.dataverse.org/Shibboleth.sso/DiscoFeed

I hope this is helpful. I'm actually going on vacation soon but I'll check in with you when I get back.

Thanks!

Phil

1. http://phoenix.dataverse.org/schemaspy/latest/tables/authenticateduserlookup.html
2. http://phoenix.dataverse.org/schemaspy/latest/tables/authenticateduser.html

--
You received this message because you are subscribed to the Google Groups "Dataverse Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dataverse-dev+unsubscribe@googlegroups.com.

To post to this group, send email to datave...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Alexander Ivanov

unread,
May 15, 2017, 11:22:02 PM5/15/17
to datave...@googlegroups.com
Thanks Phil

>we could persist somewhere the "logout" URL such as "https://idp.stage.qdr.org/idp/profile/Logout"

This is not necessary.  This url is standardized for Shibboleth "Proprietary/Simple" Single Logout as documented here:

The path is always /profile/Logout

Alexander Ivanov

unread,
May 16, 2017, 7:57:39 AM5/16/17
to datave...@googlegroups.com
Although I suppose that persisting the Logout URL makes sense if the hostname of the IdP is not persisted anywhere.  I wonder what would be the best way to capture either the Shibboleth IdP hostname or the Logout URL when the user is redirected to Shib.java?

For now, in our QDR Dataverse, I will be using the database "setting" table to store the value for "ShibLogoutUrl"

Best,
Alex

Philip Durbin

unread,
May 16, 2017, 8:34:57 AM5/16/17
to datave...@googlegroups.com
A single ShibLogoutUrl value in the setting table won't work for Dataverse installations that support multiple Identity Providers such as https://dataverse.harvard.edu , https://dataverse.unc.edu , https://dataverse.tdl.org , and others that I may be forgetting.

You're right that the IdP hostname isn't persisted in the database anywhere. When a user logs, setShibIdentityProvider is called, putting the value in the session, but the *entityID* of the IdP is used, not the *hostname* of the IdP. Often an entityId looks like a hostname but the older ones especially can look like "urn:mace:incommon:mit.edu" for example, any arbitrary string.

Thanks for the tip about "/profile/Logout" being standardized. To complete the URL, should we create a setShibIdPHostname method and also put the hostname of the Identity Provider in the session?

Phil
 


For more options, visit https://groups.google.com/d/optout.

Alexander Ivanov

unread,
May 16, 2017, 2:53:25 PM5/16/17
to datave...@googlegroups.com
> To complete the URL, should we create a setShibIdPHostname method and also put the hostname of the Identity Provider in the session?

This sounds like the right approach.  Would you like me to create a pull request and take a shot at coding this, or does your dev team have it covered?

Philip Durbin

unread,
May 16, 2017, 3:37:07 PM5/16/17
to datave...@googlegroups.com
Please create a pull request, if you can!

We are busy will all the stuff at http://dataverse.org/goals-roadmap-and-releases :)


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages