maestrano-rails 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  class Maestrano::Rails::SamlBaseController < ApplicationController
2
2
  attr_reader :saml_response, :user_auth_hash, :group_auth_hash, :user_group_rel_hash
3
+ protect_from_forgery :except => [:consume]
3
4
  around_filter :saml_response_transaction, only: [:consume]
4
5
 
5
6
  # Initialize the SAML request and redirects the
@@ -17,8 +18,12 @@ class Maestrano::Rails::SamlBaseController < ApplicationController
17
18
  yield
18
19
  Maestrano::SSO.set_session(session,@user_auth_hash)
19
20
  rescue Exception => e
20
- logger.error e
21
- redirect_to "#{Maestrano::SSO.unauthorized_url}?err=internal"
21
+ if Rails.env.development?
22
+ raise
23
+ else
24
+ logger.error e
25
+ redirect_to "#{Maestrano::SSO.unauthorized_url}?err=internal"
26
+ end
22
27
  end
23
28
  end
24
29
 
@@ -29,9 +34,9 @@ class Maestrano::Rails::SamlBaseController < ApplicationController
29
34
  @user_auth_hash = Maestrano::SSO::BaseUser.new(@saml_response).to_hash
30
35
  @group_auth_hash = Maestrano::SSO::BaseGroup.new(@saml_response).to_hash
31
36
  @user_group_rel_hash = {
32
- user_uid: @saml_response.attributes['uid'],
33
- group_uid: @saml_response.attributes['group_uid'],
34
- role: @saml_response.attributes['group_role']
37
+ user_uid: @user_auth_hash[:uid],
38
+ group_uid: @group_auth_hash[:uid],
39
+ role: @user_auth_hash[:extra][:group][:role]
35
40
  }
36
41
  end
37
42
  end
@@ -2,6 +2,7 @@ class AddMaestranoTo<%= table_name.camelize %> < ActiveRecord::Migration
2
2
  def self.up
3
3
  change_table(:<%= table_name %>) do |t|
4
4
  <%= migration_data -%>
5
+ end
5
6
  end
6
7
 
7
8
  def self.down
@@ -26,7 +26,7 @@ Maestrano.configure do |config|
26
26
  # ==> Application host
27
27
  # This is your application host (e.g: mysuperapp.com) which is ultimately
28
28
  # used to redirect users to the right SAML url during SSO handshake.
29
- config.app_host = Rails.env.production? ? 'https://my-production-app.com' : 'http://localhost::3000'
29
+ config.app_host = Rails.env.production? ? 'https://my-production-app.com' : 'http://localhost:3000'
30
30
 
31
31
  # ==> SSO Initialization endpoint
32
32
  # This is your application path to the SAML endpoint that allows users to
@@ -1,3 +1,5 @@
1
+ require 'digest/sha1'
2
+
1
3
  module Maestrano
2
4
  module Rails
3
5
  module MaestranoAuthResource
@@ -62,8 +64,20 @@ module Maestrano
62
64
  info = OpenStruct.new(auth_hash[:info])
63
65
  extra = OpenStruct.new(auth_hash[:extra])
64
66
 
65
- # Create entity and call mapping block
67
+ # Create entity
66
68
  entity = self.new
69
+
70
+ # Set password on entity in case this is required
71
+ # This is done before the mapping block in case
72
+ # password has been taken care of by the developer
73
+ password = Digest::SHA1.hexdigest("#{Time.now.utc}-#{rand(100)}")[0..20]
74
+ begin
75
+ entity.password = password if entity.respond_to?(:password)
76
+ entity.password_confirmation = password if entity.respond_to?(:password_confirmation)
77
+ rescue Exception => e
78
+ end
79
+
80
+ # Call mapping block
67
81
  self.maestrano_options[:mapping].call(entity,info,extra)
68
82
 
69
83
  # Finally set provider and uid then save
@@ -1,5 +1,5 @@
1
1
  module Maestrano
2
2
  module Rails
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: maestrano-rails
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Arnaud Lachaume
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: "0.1"
34
+ version: "0.2"
35
35
  type: :runtime
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency