Commit f5ebff23ef25b059697f4b59cd364f4d6ad1c88d

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

Encode and decode SAML-response to make it valid under non ascii characters

Showing 1 changed file with 8 additions and 5 deletions Side-by-side Diff

app/controllers/saml_controller.rb View file @ f5ebff2
  1 +require 'base64'
1 2 require 'ruby-saml'
2 3  
3 4 class SamlController < ApplicationController
4 5  
... ... @@ -15,13 +16,15 @@
15 16 end
16 17  
17 18 def consume
18   - response = OneLogin::RubySaml::Response.new(params[:SAMLResponse])
  19 + response = OneLogin::RubySaml::Response.new(Base64.decode64(
  20 + params[:SAMLResponse]).force_encoding('utf-8').encode('windows-1252'))
19 21 response.settings = Account.get_saml_settings
20 22  
21   - name_id_tokens = response.name_id.split('-')
22   - name_id_map = {'68909' => 'CI', '68912' => 'PSP', 'DO' => 'DO'}
23   - if response.is_valid? && user = User.find_by_login([name_id_tokens[0],
24   - name_id_map[name_id_tokens[1]], name_id_tokens[2]].join('-'))
  23 + name_id_tokens = response.name_id.downcase.split('-')
  24 + name_id_map = {'68909' => 'ci', '68912' => 'psp', 'do' => 'do'}
  25 + name_id = [name_id_tokens[0], name_id_map[name_id_tokens[1]],
  26 + name_id_tokens[2]].join('-')
  27 + if response.is_valid? && user = User.find_by_login(name_id)
25 28  
26 29 self.logged_user = user
27 30 # generate a key and set cookie if autologin