main
1# frozen_string_literal: true
2
3module Saml
4 module Kit
5 module Cli
6 module Commands
7 class Decode < Thor
8 desc 'redirect uri', 'Decodes the uri using the HTTP Redirect binding'
9 method_option :export, default: nil, required: false
10 def redirect(uri)
11 print_report_for(redirect_binding.deserialize(uri))
12 rescue StandardError => error
13 say error.message, :red
14 end
15
16 desc(
17 'post saml',
18 'Decodes the SAMLRequest/SAMLResponse using the HTTP Post binding'
19 )
20 method_option :export, default: nil, required: false
21 def post(saml)
22 print_report_for(post_binding.deserialize('SAMLRequest' => saml))
23 rescue StandardError => error
24 say error.message, :red
25 end
26
27 desc 'raw <file>', 'Decode the contents of a decoded file'
28 def raw(file)
29 content = IO.read(File.expand_path(file))
30 print_report_for(Document.to_saml_document(content))
31 rescue StandardError => error
32 say error.message, :red
33 end
34
35 private
36
37 def print_report_for(document, export = options[:export])
38 IO.write(export, document.to_xml) if export
39 2.times { say '' }
40 Report.new(document).print(self)
41 end
42
43 def post_binding(location = '')
44 Saml::Kit::Bindings::HttpPost.new(location: location)
45 end
46
47 def redirect_binding(location = '')
48 Saml::Kit::Bindings::HttpRedirect.new(location: location)
49 end
50 end
51 end
52 end
53 end
54end