cmsso

Company specific Single Sign On for rails applications.

Installation

Simply add cmsso to your Gemfile and bundle it up.

gem 'cmsso'

Usage

Configure cmsso gem with an initializer.

Cmsso.configure do |config|
  config.module_key = 'my_module_key'

  # optional settings
  config.base_uri   = "http://cmservice-chbs#{environment}.{company}.net:3056/persons"
  config.proxy      = "proxy.{company}.net:2010"
end

This is how your application controller could look like.

class ApplicationController < ActionController::Base
  include Cmsso
  protect_from_forgery
  before_filter :authorize
  include ApplicationHelper
  helper_method :current_user

  def current_user
    @current_user ||= current_user_from_session || current_user_from_cmsso  
  end

  private

  def current_user_from_session
    session[:person]
  end

  def current_user_from_cmsso
    person = Cmsso::Member.find(request.headers) || Cmsso::Member.create(request.headers)

    if person 
      session[:person] = person 
    else
      flash.now[:error] = Cmsso::Member.note
      AL.warn(Cmsso::Member.note)
      return Cmsso::Member.new({full_name: "Unknown"})
    end  
  end

  def authorize
    current_user
  end

end

Cmsso::Member.create will create the user with a guest role. This method call is optional.

In views you can check roles as follows.

current_user.administrator?     # true if a user has adminintrator role
current_user.operator?              # true if a user has operator role
current_user.user?                      # true if a user has user roles 
current_user.guest?                     # true if a user has guest role 

To display the user name in a view do the following:

current_user.full_name

Note

uses MIT-LICENSE.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request