forked from saml-idp/saml_idp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saml_idp.rb
92 lines (77 loc) · 2.37 KB
/
saml_idp.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# encoding: utf-8
module SamlIdp
require 'active_support/all'
require 'saml_idp/saml_response'
require 'saml_idp/xml_security'
require 'saml_idp/configurator'
require 'saml_idp/controller'
require 'saml_idp/default'
require 'saml_idp/metadata_builder'
require 'saml_idp/version'
require 'saml_idp/engine' if defined?(::Rails) && Rails::VERSION::MAJOR > 2
def self.config
@config ||= SamlIdp::Configurator.new
end
def self.configure
yield config
end
def self.metadata
@metadata ||= MetadataBuilder.new(config)
end
end
# TODO Needs extraction out
module Saml
module XML
module Namespaces
METADATA = "urn:oasis:names:tc:SAML:2.0:metadata"
ASSERTION = "urn:oasis:names:tc:SAML:2.0:assertion"
SIGNATURE = "http://www.w3.org/2000/09/xmldsig#"
PROTOCOL = "urn:oasis:names:tc:SAML:2.0:protocol"
module Statuses
SUCCESS = "urn:oasis:names:tc:SAML:2.0:status:Success"
end
module Consents
UNSPECIFIED = "urn:oasis:names:tc:SAML:2.0:consent:unspecified"
end
module AuthnContext
module ClassRef
PASSWORD = "urn:oasis:names:tc:SAML:2.0:ac:classes:Password"
PASSWORD_PROTECTED = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
end
end
module Methods
BEARER = "urn:oasis:names:tc:SAML:2.0:cm:bearer"
end
module Formats
module Attr
URI = "urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
end
module NameId
EMAIL_ADDRESS = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
TRANSIENT = "urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
PERSISTENT = "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
end
end
end
class Document < Nokogiri::XML::Document
def signed?
!!xpath("//ds:Signature", ds: signature_namespace).first
end
def valid_signature?(fingerprint)
signed? &&
signed_document.validate(fingerprint, :soft)
end
def signed_document
SamlIdp::XMLSecurity::SignedDocument.new(to_xml)
end
def signature_namespace
Namespaces::SIGNATURE
end
def to_xml
super(
save_with: Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
).strip
end
end
end
end