Extension:Shibboleth Authentication

Overview
Shibboleth is a Single Signon identity managment solution that's a project of Internet2. It's in use not only in many universities through the US and elsewhere but also on sites such as openidp to provide authentication to a range of applications. This extension allows mediawiki to use Shibboleth as an external authentication source.

Current Version: 1.1.6

Compatibility
This extension is designed for MediaWiki 1.7 and up. If you want to use this extension with the 1.6 branch or earlier look at bugs 5819 and 6006 and apply the SVN changes that took place.

Shibboleth Configuration
The extension requires that shibboleth be configured and set up on the web server the wiki is hosted on. Once Shibboleth is running on the web server make sure your configuration file is correctly set-up. Your IdP should be able to help you with this. The extension uses lazy sessions and a WAYF url so you'll want to verify these are setup as well. (You can actually use full sessions if you want, but the extension is designed to use lazy sessions to allow for the standard wiki auth to co-exist alongside.) You'll need to tell the extension which WAYF url to use.

The part of the configuration file (shibboleth.xml) where a WAYF url will be present is here: ...   

For lazy sessions in Apache, the following lines in your apache configuration files will do: ...  AuthType shibboleth Require shibboleth 

If you don't want lazy sessions but instead would rather require shibboleth authentication, then use: ...  AuthType shibboleth ShibRequireSession On       Require valid-user 

Download the Extension
The code for the extension is at the bottom of this page. Place it in the extensions folder, in a file called "ShibAuthPlugin.php."

Extension Configuration
Now it's time to configure and load the extension. To do that, just add the following lines to LocalSettings.php in the root of the mediawiki directory.

Most of the configuration directives are of the form: $shib_SOMELETTERS = data_manipulation_functions($_SERVER['HEADER_FOR_SHIB_DATA']); This allows you to map whatever shibboleth identifers you chose to a variety of fields for each user as well as use the standard PHP functions to massage the data as it enters. All the Shibboleth data has been placed in the $_SERVER superglobal by the Shibboleth module and should be available. You may need to run a script like the following to determine exactly what data is available: <? //Drop this into a directory where sessions are required //or where you are already authenticated and then simply //access it to see the mapping. while(list($index, $data) = each($_SERVER)) {	echo "$index -> $data "; } ?>

At the very minimum you'll need to make the following changes:
 * 1) Place the following code into the LocalSettings.php file.
 * 2) Set the WAYF url.
 * 3) Map a valid piece of Shib data for the username.
 * 4) Look over the rest of the variables and ensure that you don't want to make any more changes.

require_once('extensions/ShibAuthPlugin.php');
 * 1) Shibboleth Authentication Stuff
 * 2) Load ShibAuthPlugin

$shib_WAYF = "idp.example.org";
 * 1) Last portion of the shibboleth WAYF url for lazy sessions.
 * 2) This value is found in your shibboleth.xml file on the setup for your SP
 * 3) WAYF url will look something like: /Shibboleth.sso/WAYF/$shib_WAYF

$shib_Https = true;
 * 1) Is the assertion consumer service located at an https address (highly recommended)
 * 2) Default for compatibility with previous version: false

$shib_LoginHint = "Login via Single Sign-on";
 * 1) Prompt for user to login

$shib_AssertionConsumerServiceURL = "/Shibboleth.sso";
 * 1) Where is the assertion consumer service located on the website?
 * 2) Default: "/Shibboleth.sso"

$shib_map_info = "true";
 * 1) Do you want to map in names from Shibboleth data?
 * 2) Feel free to use extra PHP code to munge the variables if you'd like
 * 3) Additionally if you wish to only map some of the name data, set this to true
 * 4) and either blank shib_RN and shib_email or comment them out entirely.

$olderror = error_reporting(E_ALL ^ E_NOTICE);
 * 1) Ssssh.... quiet down errors

$shib_RN = ucfirst(strtolower($_SERVER['HTTP_FIRST_NAME'])). ' '	 . ucfirst(strtolower($_SERVER['HTTP_LAST_NAME']));
 * 1) Map Real Name to what Shibboleth variable(s)?

$shib_email = $_SERVER['HTTP_EMAIL'];
 * 1) Map e-mail to what Shibboleth variable?

$shib_UN = strtolower($_SERVER['HTTP_EMAIL']);
 * 1) This is required to map to something
 * 2) You should beware of possible namespace collisions, it is best to chose
 * 3) something that will not violate MW's usual restrictions on characters
 * 4) Map Username to what Shibboleth variable?


 * 1) Shibboleth doesn't really support logging out very well. To take care of
 * 2) this we simply get rid of the logout link when a user is logged in through
 * 3) Shib. Alternatively, you can uncomment and set the variable below to a link
 * 4) that will either clear the user's cookies or log the user out of the Idp and
 * 5) instead of deleting the logout link, the extension will change it instead.
 * 6) $shib_logout = "http://example.org";

error_reporting($olderror);
 * 1) Turn error reporting back on

SetupShibAuth;
 * 1) Activate Shibboleth Plugin

Using the Extension
The extension is designed to be fairly simple to use. Once everything is configured and Shibboleth is running a link will appear at the top right hand corner of the screen next to the normal mediawiki login link that says "login via single sign-on." Clicking this link will bounce the user to the WAYF url which will pass them to the IdP for authentication. When they come back they'll be logged in.

Adding more Metadata
If you wish to add more mappings from Mediawiki data to Shibboleth data than is available, you can simply add them in the configuration file. The only code changes you will have to do are in the updateUser function of the ShibAuthPlugin.php file.

Logout Functionality
Shibboleth currently has no good way to log people out. By default logout is disabled once people sign in through Shibboleth. Alternatively you may point logout to a url provided by your local IdP which will allow logout. If your local IdP doesn't support this and you really would like to log people out, simply create a small php script to unset the Shibboleth cookies and point people towards that, then redirect them to the standard mediawiki logout script.

Username Munging
While the extension will enforce the rule that all usernames must begin with a capital letter, it will not enforce any of the rest of mediawiki's usual rules for usernames. If your Shibboleth data will break other mediawiki username rules you should filter that out at the configuration level when $shib_UN gets set. In addition, if your shibboleth data includes sets of usernames that may only be separated by difference of upper and lower-case initial letters (Like "Nick@example.org" and "nick@example.org") then the plugin will treat these two as if they were not distinct. Again the solution is to provide additional filtering in LocalSettings.php. By default we simply use the user's e-mail addresses converting any letters to lowercase and then pass those in. (Again, the extension takes care of converting the initial letter to uppercase.)

Differences between 1.1.6 and 1.1.5

 * Compatibility fixes for upcoming MW 1.10.0 release. (They broke the plugin again :-\)
 * Fix error in some versions of php and MW that caused the plugin to fail
 * Fix PHP notice about an undefined variable
 * When $shib_RN is not null and $shib_map_info is set to true the plugin will now display the user's name in their URLs instead of their username. This looks pretty slick, but may need to be more configurable in the future.

Differences between 1.1.5 and 1.1.4

 * Some of the cleanups in 1.1.4 blocked an untested codepath and prevented the plugin from working

Differences between 1.1.4 and 1.1.3

 * Security Fix: Namespace collisions are now handled by clobbering the old user
 * Cleanup for setting passwords, more compatible with new changes, less kludgy code as well
 * Fixed longstanding warning caused by a typo in an earlier version of the code (oops)

Differences between 1.1.3 and 1.1.2

 * Extra error handling plus compatibility fixes for mediawiki version 1.6.8 (hook patches added)

Differences between 1.1.2 and 1.1.1

 * Compatibilty fixes for 1.9

Differences between 1.1.1 and 1.1

 * Preserve compatibility with 1.0 configuration files for $shib_LoginHint

Differences between 1.1 and 1.0

 * Extra configuration options
 * shib_Https (whether the AssertionConsumerService url is at https, default is false)
 * shib_AssertionConsumerServiceURL (defaults to /Shibboleth.sso)
 * Sites that are accessed via https are redirected there after logging in using lazy authentication
 * Login Form Cleanup
 * New Contributor: Steven Langenaken

Acknowledgements
These folks have helped out by reporting issues and breakages or testing early code releases to help eliminate issues and breakages. Without them this software would have more bugs.

Bug Reporters

 * Martin Kos - Reported breakage in 1.1.4
 * Eric Jiang - Reported breakage in 1.1.1

Testers

 * Joe Pomianek - UCSD