main
1# frozen_string_literal: true
2
3require 'saml/kit/bindings/binding'
4require 'saml/kit/bindings/http_post'
5require 'saml/kit/bindings/http_redirect'
6require 'saml/kit/bindings/url_builder'
7
8module Saml
9 module Kit
10 # This module is responsible for exposing
11 # the different SAML bindings that are
12 # supported by this gem.
13 module Bindings
14 BINDINGS_2_0 = 'urn:oasis:names:tc:SAML:2.0:bindings'
15 HTTP_ARTIFACT = "#{BINDINGS_2_0}:HTTP-Artifact"
16 HTTP_POST = "#{BINDINGS_2_0}:HTTP-POST"
17 HTTP_REDIRECT = "#{BINDINGS_2_0}:HTTP-Redirect"
18 ALL = {
19 http_post: HTTP_POST,
20 http_redirect: HTTP_REDIRECT,
21 http_artifact: HTTP_ARTIFACT,
22 }.freeze
23
24 def self.binding_for(binding)
25 ALL[binding]
26 end
27
28 def self.to_symbol(binding)
29 case binding
30 when HTTP_REDIRECT
31 :http_redirect
32 when HTTP_POST
33 :http_post
34 else
35 binding
36 end
37 end
38
39 def self.create_for(binding, location)
40 case binding
41 when HTTP_REDIRECT
42 HttpRedirect.new(location: location)
43 when HTTP_POST
44 HttpPost.new(location: location)
45 else
46 Binding.new(binding: binding, location: location)
47 end
48 end
49 end
50 end
51end