Class: IntegrationPal::SamlController

Inherits:
ApplicationController show all
Defined in:
app/controllers/integration_pal/saml_controller.rb

Defined Under Namespace

Classes: ERBContext

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate!

Class Method Details

.idp_metadataObject



23
24
25
# File 'app/controllers/integration_pal/saml_controller.rb', line 23

def 
   ||= parse_meta_file(IntegrationPal.)
end

.parse_meta_file(filename) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/integration_pal/saml_controller.rb', line 4

def parse_meta_file(filename)
  possible_names = ['.erb', ''].map { |ext| filename+ext }
  possible_paths = []

  ['config/saml', 'config'].each do |prefix|
    possible_names.each do |filename|
      possible_paths << Rails.root.join(prefix, filename)
    end
  end

  meta_path = possible_paths.find &:exist?

  meta_file = File.read(meta_path)
  if meta_path.extname == '.erb'
    meta_file = ERB.new(meta_file).result(ERBContext.new.get_binding)
  end
  SAML2::Entity.parse(meta_file)
end

.sp_metadataObject



27
28
29
# File 'app/controllers/integration_pal/saml_controller.rb', line 27

def 
   ||= parse_meta_file(IntegrationPal.)
end

Instance Method Details

#createObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/integration_pal/saml_controller.rb', line 48

def create
  response, _relay_state = SAML2::Bindings::HTTP_POST.decode(request.request_parameters)
  unless self.class..valid_response?(response, self.class.)
    logger.error("Failed to validate SAML response: #{response.errors}")
    raise ActionController::RoutingError.new('Not Found')
  end

  reset_session
  session[:saml_username] = response.assertions.first.subject.name_id.id
  logger.info("Logged in using SAML2 as #{session[:saml_username]}")

  redirect_to root_url
end

#logoutObject



62
63
64
65
# File 'app/controllers/integration_pal/saml_controller.rb', line 62

def logout
  reset_session
  redirect_to root_url
end

#metadataObject



67
68
69
# File 'app/controllers/integration_pal/saml_controller.rb', line 67

def 
  render xml: self.class..to_xml
end

#newObject



43
44
45
46
# File 'app/controllers/integration_pal/saml_controller.rb', line 43

def new
  authn_request = self.class..initiate_authn_request(self.class.)
  redirect_to SAML2::Bindings::HTTPRedirect.encode(authn_request)
end