Commit a187b58677885c528370ec752a8d4bc27ea218ac

Authored by Aníbal Pacheco
1 parent fa86fef565
Exists in master

New RoR support and new settings needed for using XML-Signature

Showing 3 changed files with 12 additions and 9 deletions Side-by-side Diff

app/controllers/saml_controller.rb View file @ a187b58
1   -require 'onelogin/saml'
  1 +require 'ruby-saml'
2 2  
3 3 class SamlController < ApplicationController
4 4 skip_before_filter :verify_authenticity_token, :only => [:consume]
5 5  
6 6  
... ... @@ -6,15 +6,15 @@
6 6  
7 7 def index
8 8 settings = Account.get_saml_settings
9   - request = Onelogin::Saml::Authrequest.new
  9 + request = OneLogin::RubySaml::Authrequest.new
10 10 redirect_to(request.create(settings))
11 11 end
12 12  
13 13 def consume
14   - response = Onelogin::Saml::Response.new(params[:SAMLResponse])
  14 + response = OneLogin::RubySaml::Response.new(params[:SAMLResponse])
15 15 response.settings = Account.get_saml_settings
16 16  
17   - if response.is_valid? && user = User.find_by_mail(response.name_id)
  17 + if response.is_valid? && user = User.find_by_login(response.name_id)
18 18  
19 19 self.logged_user = user
20 20 # generate a key and set cookie if autologin
app/models/account.rb View file @ a187b58
1   -require 'onelogin/saml'
  1 +require 'ruby-saml'
2 2  
3 3 class Account < ActiveRecord::Base
4 4 def Account.get_saml_settings
5 5  
6 6 options = YAML::load(ERB.new(IO.read(File.join(Rails.root, 'config', 'saml_auth.yml'))).result)
7   - settings = Onelogin::Saml::Settings.new
  7 + settings = OneLogin::RubySaml::Settings.new
8 8  
9 9 settings.assertion_consumer_service_url = options[Rails.env]['assertion_consumer_service_url']
10 10 settings.issuer = options[Rails.env]['issuer']
11 11 settings.idp_sso_target_url = options[Rails.env]['idp_sso_target_url']
12 12 settings.idp_cert_fingerprint = options[Rails.env]['idp_cert_fingerprint']
13 13 settings.name_identifier_format = options[Rails.env]['name_identifier_format']
  14 + settings.private_key = options[Rails.env]['private_key']
  15 + settings.private_key_pass = options[Rails.env]['private_key_pass']
  16 + settings.certificate = options[Rails.env]['certificate']
14 17  
15 18 settings
16 19 end
config/routes.rb View file @ a187b58
1   -ActionController::Routing::Routes.draw do |map|
2   - map.saml_login 'auth/saml', :controller => 'saml', :action => 'index'
3   - map.saml_consume 'auth/saml/consume', :controller => 'saml', :action => 'consume'
  1 +RedmineApp::Application.routes.draw do
  2 + match 'auth/saml', :to => 'saml#index', :as => 'saml_login'
  3 + match 'auth/saml/consume', :to => 'saml#consume', :as => 'saml_consume'
4 4 end