Hub single sign-onHub is a Ruby On Rails application with accompanying library gem which manages user accounts for a web site. Its main use is for sites that run more than one Rails application within a single domain. Through integration with the Hub library gem, applications share Hub user details so that a user only has to create one account and log in or out of one place. Without Hub, users have to create and manage individual accounts for individual applications. Hub is therefore a single sign-on mechanism. Applications require modifications to use Hub. Applications that already have the concept of users and accounts must be modified with some care, because the application’s own account mechanism must be replaced or overlaid with the single sign-on alternative. Applications that have no account mechanism are much simpler to modify. You may wish to add Hub support to such applications so that users must create accounts to perform certain actions, such as posting to a forum or blog that might otherwise be completely open to the public – and therefore completely open to spam. Hub has three main components. The Hub application handles users creating accounts, logging in and out and managing their account settings, through an ActiveRecord database connection and the library gem. User information stored securely in the database while the gem is used to record details when a user logs in or discard those details when a user logs out. The gem does this by sending objects to or reading objects from the third component, a small distributed Ruby server. Running on Unix domain sockets, the server allows all Hub-integrated Rails applications to share information on a logged in user without needing secondary ActiveRecord connections to the Hub database or any detailed knowledge of Hub’s user account model. Everything is hidden by the Hub library gem API. The Hub core is very distantly based on the Acts as Authenticated shell. InstallationDownloadingPresently, only a version of Hub with views styled for the RISC OS Open web site is available. In future I hope to add a more generic and more easily customised version. The latest version of the Hub application is available at: http://www.riscosopen.org/tarballs/svn/hub.tar.bz2 The latest version of the Hub gem source code is available at: https://www.riscosopen.org/tarballs/svn/hubssolib.tar.bz2 The Hub library gemFirst of all, download and unpack the Hub gem sources. Change into the source directory (usually, gem build hubssolib.gemspec Install the Hub gem using the gem install hubssolib-0.2.5.gem If you run multiple gem repositories you can instruct gem install hubssolib-0.2.5.gem --install-dir=/home/username/gems The DRb serverThe Hub DRb server consists of a small wrapper Ruby script which does most of its work using the Hub gem. To run the server, you need to first specify a DRb connection URI in the HUB_CONNECTION_URI="drbunix:/home/username/sockets/hub_drb" export HUB_CONNECTION_URI ruby /home/username/hub/hub_sso_server.rb & The Hub applicationFinally you can install the Hub application using whatever mechanism you prefer to application installation. See ample documentation elsewhere on the Web for information on installing Ruby On Rails applications – Hub itself contains the default rails README file with quite a lot of information in it. Some configuration is needed using externally set environment variables. These are actually picked up by the Hub gem but you won’t know what values to set until the application, DRb server and gem are all installed.
Usually, these are set up in a Web server configuration file as part of launching an FCGI process to host the Hub application. Don’t forget to set up the application’s Testing the installationVisit your application in a Web browser and follow the links to sign up for a new account. To sign up, provide a name that will be displayed to users and a valid e-mail address. A confirmation message is sent to the address, containing a link that must be followed to activate the account. One created, users can log in and out of their accounts (with the possibility of sending a password reset request to their e-mail address in case they forget how to log in) and change their screen names. Users cannot change their recorded e-mail address – instead, they must create a new account under the new address. As the first user of the Hub application, you test your installation by simply going through the sign-up process. The first account is automatically constructed with administrator privileges. If you are successfully able to visit the signup page, create your account, validate the signup using the confirmation e-mail message and subsequently log in or out of the new account, then Hub is correctly installed Administrative use of the Hub applicationAdministrative account users are presented with extra options in the Hub control panel when they log on. You can list currently logged on users, list all users and modify account settings for any user, including deleting their accounts. Accounts have a list of roles associated with them. Roles define whether or not a user has administrative privileges, webmaster privileges and so-on. When you integrate Hub with another application, you define exactly what these roles are because (as described below) you must assign lists of roles required to access protected controller actions. Accounts can be assigned more than one role. Whether or not you ever want to do this will depend entirely on how you set up the roles required to access various controller actions as you integrate Hub with whichever applications you wish to work under the single sign-on mechanism. Integrating with applicationsFor full integration with Hub, particularly when it comes to showing or hiding things in application views, you need to know some of the Hub programmer interface. This API is described in detail later. First, we need to consider basic application integration issues, mostly revolving around modifying the application controllers. For more information on the interfaces used by the examples show, consult the detailed API documentation further down. Applications without an existing user modelApplications with no concept of user log-in are easy to integrate with Hub. Applications with only the concept of logging in for administrative purposes are similarly easy, provided your administrators do not mind having to log in using the application’s own administrative mechanisms (so you basically treat the application as if it has no existing user model). To integrate, add the Hub filters into # Hub single sign-on support. require 'hub_sso_lib' include HubSsoLib::Core before_filter :hubssolib_beforehand after_filter :hubssolib_afterwards Within any controller which has actions which you wish to protect with Hub login, define a variable def FooController.hubssolib_permissions @@hubssolib_permissions end To define the permissions variable you create an instance of @@hubssolib_permissions = HubSsoLib::Permissions.new({
:show => [ :admin, :webmaster, :privileged, :normal ],
:edit => [ :admin, :webmaster ]
})
In this example, any user can access the controller’s A user’s role(s) must match at least one of the privileges in the array for a given action – so even if your account has an administrator role (and only an administrator role), it won’t be able to access a protected action unless @@hubssolib_permissions = HubSsoLib::Permissions.new({
:weblist => [ :webmaster, :privileged ]
})
Here, only accounts with the webmaster or privileged role associated can access the Applications with an existing user modelIf you want to integrate Hub with an application which already has the concept of user accounts, logging in and logging out, there are two main approaches.
Neither approach is problem-free and both require quite a lot of effort and testing. Automated testing is very hard because the modified application’s behaviour depends upon logging in or out of Hub, which is running elsewhere. Unfortunately Rails doesn’t offer a universally supported single sign-on mechanism so applications all use different approaches to user management; this means that there is no magic bullet to integration with Hub. You have to learn and understand the structure of the application being integrated and be prepared to make changes that are potentially quite extensive. Hub library APIThe Hub component interfaces that should be used by application authors when integrating with the Hub single sign-on mechanism are described below. If you want a complete list of all public interfaces, consult the file RolesEvery Hub user account has assigned to it one or more Roles. For day to day use, roles are managed using the Hub application front-end. Role names are defined as symbols. Defined names are:
When setting access permissions for actions in controllers (see next section), you specify the permissions in terms of the role names above. This means that you really define the true meaning of each of the four roles by their use within controllers. It isn’t necessary to use all four roles or, if you want to add more, you can extend the PermissionsHub protects against access to actions in controller by using a Permitted roles are expressed as single symbols or their equivalent strings, or an array containing many symbols or equivalent strings. Most often, an array of symbols is used. To create a permissions object, instantiate @@hubssolib_permissions = HubSsoLib::Permissions.new({
:show => [ :admin, :webmaster, :privileged, :normal ],
:edit => [ :admin, :webmaster ]
})
Here, all roles are allowed to access the The above line of code typically appears at the start of the class definition for the controller to which you are restricting access. class AccountController < ApplicationController
@@hubssolib_permissions = HubSsoLib::Permissions.new({
...permissions here…
})
...existing class contents here…
end
Having created the permissions object, you need to expose variable def AccountController.hubssolib_permissions
@@hubssolib_permissions
end
So the full preamble in this example is: class AccountController < ApplicationController
@@hubssolib_permissions = HubSsoLib::Permissions.new({
...permissions here…
})
def AccountController.hubssolib_permissions
@@hubssolib_permissions
end
...existing class contents here…
end
While you can ask a specific Permissions object whether or not an action is permitted for a given role or roles using the CoreThe Hub # Hub single sign-on support. require 'hub_sso_lib' include HubSsoLib::Core before_filter :hubssolib_beforehand after_filter :hubssolib_afterwards All internal methods have the The “before” filter:
| |||||||||||||||||
|
The HTML and CSS herein are licensed under a Creative Commons License. |
A.D.Hodgkinson Updated 17 Nov 2007 |