9
9
import requests
10
10
import six
11
11
from hashlib import sha1
12
- from os .path import isfile , join
13
- from saml2 .httpbase import HTTPBase
14
- from saml2 .extension .idpdisc import BINDING_DISCO
15
- from saml2 .extension .idpdisc import DiscoveryResponse
16
- from saml2 .md import EntitiesDescriptor
17
- from saml2 .mdie import to_dict
12
+ from os .path import isfile
13
+ from os .path import join
14
+
18
15
from saml2 import md
16
+ from saml2 import saml
19
17
from saml2 import samlp
18
+ from saml2 import xmldsig
19
+ from saml2 import xmlenc
20
20
from saml2 import SAMLError
21
21
from saml2 import BINDING_HTTP_REDIRECT
22
22
from saml2 import BINDING_HTTP_POST
23
23
from saml2 import BINDING_SOAP
24
+
25
+ from saml2 .httpbase import HTTPBase
26
+ from saml2 .extension .idpdisc import BINDING_DISCO
27
+ from saml2 .extension .idpdisc import DiscoveryResponse
28
+ from saml2 .md import EntitiesDescriptor
29
+ from saml2 .mdie import to_dict
24
30
from saml2 .s_utils import UnsupportedBinding
25
31
from saml2 .s_utils import UnknownSystemEntity
26
32
from saml2 .sigver import split_len
@@ -83,6 +89,24 @@ def load_extensions():
83
89
return ext_map
84
90
85
91
92
+ def load_metadata_modules ():
93
+ mods = {
94
+ saml .NAMESPACE : saml ,
95
+ md .NAMESPACE : md ,
96
+ xmldsig .NAMESPACE : xmldsig ,
97
+ xmlenc .NAMESPACE : xmlenc
98
+ }
99
+
100
+ mods .update (load_extensions ())
101
+ return mods
102
+
103
+
104
+ def metadata_modules ():
105
+ _res = [saml , md , xmldsig , xmlenc ]
106
+ _res .extend (list (load_extensions ().values ()))
107
+ return _res
108
+
109
+
86
110
def destinations (srvs ):
87
111
return [s ["location" ] for s in srvs ]
88
112
@@ -129,14 +153,16 @@ def repack_cert(cert):
129
153
130
154
131
155
class MetaData (object ):
132
- def __init__ (self , onts , attrc , metadata = '' , node_name = None ,
156
+ def __init__ (self , attrc , metadata = '' , node_name = None ,
133
157
check_validity = True , security = None , ** kwargs ):
134
- self .onts = onts
135
158
self .attrc = attrc
136
159
self .metadata = metadata
137
160
self .entity = None
138
161
self .cert = None
139
162
self .to_old = []
163
+ self .node_name = node_name
164
+ self .check_validity = check_validity
165
+ self .security = security
140
166
141
167
def items (self ):
142
168
'''
@@ -369,9 +395,9 @@ def extract_certs(srvs):
369
395
370
396
371
397
class InMemoryMetaData (MetaData ):
372
- def __init__ (self , onts , attrc , metadata = "" , node_name = None ,
398
+ def __init__ (self , attrc , metadata = "" , node_name = None ,
373
399
check_validity = True , security = None , ** kwargs ):
374
- super (InMemoryMetaData , self ).__init__ (onts , attrc , metadata = metadata )
400
+ super (InMemoryMetaData , self ).__init__ (attrc , metadata = metadata )
375
401
self .entity = {}
376
402
self .security = security
377
403
self .node_name = node_name
@@ -424,7 +450,7 @@ def do_entity_descriptor(self, entity_descr):
424
450
entity_descr .entity_id , file = sys .stderr )
425
451
return
426
452
427
- _ent = to_dict (entity_descr , self . onts )
453
+ _ent = to_dict (entity_descr , metadata_modules () )
428
454
flag = 0
429
455
# verify support for SAML2
430
456
for descr in ["spsso" , "idpsso" , "role" , "authn_authority" ,
@@ -597,8 +623,8 @@ class MetaDataFile(InMemoryMetaData):
597
623
the SAML Metadata format.
598
624
"""
599
625
600
- def __init__ (self , onts , attrc , filename = None , cert = None , ** kwargs ):
601
- super (MetaDataFile , self ).__init__ (onts , attrc , ** kwargs )
626
+ def __init__ (self , attrc , filename = None , cert = None , ** kwargs ):
627
+ super (MetaDataFile , self ).__init__ (attrc , ** kwargs )
602
628
if not filename :
603
629
raise SAMLError ('No file specified.' )
604
630
self .filename = filename
@@ -618,9 +644,9 @@ class MetaDataLoader(MetaDataFile):
618
644
The format of the file is the SAML Metadata format.
619
645
"""
620
646
621
- def __init__ (self , onts , attrc , loader_callable , cert = None ,
647
+ def __init__ (self , attrc , loader_callable , cert = None ,
622
648
security = None , ** kwargs ):
623
- super (MetaDataLoader , self ).__init__ (onts , attrc , ** kwargs )
649
+ super (MetaDataLoader , self ).__init__ (attrc , ** kwargs )
624
650
self .metadata_provider_callable = self .get_metadata_loader (
625
651
loader_callable )
626
652
self .cert = cert
@@ -662,17 +688,16 @@ class MetaDataExtern(InMemoryMetaData):
662
688
Accessible but HTTP GET.
663
689
"""
664
690
665
- def __init__ (self , onts , attrc , url = None , security = None , cert = None ,
691
+ def __init__ (self , attrc , url = None , security = None , cert = None ,
666
692
http = None , ** kwargs ):
667
693
"""
668
- :params onts:
669
694
:params attrc:
670
695
:params url: Location of the metadata
671
696
:params security: SecurityContext()
672
697
:params cert: CertificMDloaderate used to sign the metadata
673
698
:params http:
674
699
"""
675
- super (MetaDataExtern , self ).__init__ (onts , attrc , ** kwargs )
700
+ super (MetaDataExtern , self ).__init__ (attrc , ** kwargs )
676
701
if not url :
677
702
raise SAMLError ('URL not specified.' )
678
703
else :
@@ -704,8 +729,8 @@ class MetaDataMD(InMemoryMetaData):
704
729
of the Python representation of the metadata.
705
730
"""
706
731
707
- def __init__ (self , onts , attrc , filename , ** kwargs ):
708
- super (MetaDataMD , self ).__init__ (onts , attrc , ** kwargs )
732
+ def __init__ (self , attrc , filename , ** kwargs ):
733
+ super (MetaDataMD , self ).__init__ (attrc , ** kwargs )
709
734
self .filename = filename
710
735
711
736
def load (self ):
@@ -771,18 +796,16 @@ def single_sign_on_service(self, entity_id, binding=None, typ="idpsso"):
771
796
772
797
773
798
class MetadataStore (MetaData ):
774
- def __init__ (self , onts , attrc , config , ca_certs = None ,
799
+ def __init__ (self , attrc , config , ca_certs = None ,
775
800
check_validity = True ,
776
801
disable_ssl_certificate_validation = False ,
777
802
filter = None ):
778
803
"""
779
- :params onts:
780
804
:params attrc:
781
805
:params config: Config()
782
806
:params ca_certs:
783
807
:params disable_ssl_certificate_validation:
784
808
"""
785
- self .onts = onts
786
809
self .attrc = attrc
787
810
788
811
if disable_ssl_certificate_validation :
@@ -810,18 +833,18 @@ def load(self, typ, *args, **kwargs):
810
833
files = [f for f in os .listdir (key ) if isfile (join (key , f ))]
811
834
for fil in files :
812
835
_fil = join (key , fil )
813
- _md = MetaDataFile (self .onts , self . attrc , _fil , ** _args )
836
+ _md = MetaDataFile (self .attrc , _fil , ** _args )
814
837
_md .load ()
815
838
self .metadata [_fil ] = _md
816
839
return
817
840
else :
818
841
# else it's just a plain old file so read it
819
- _md = MetaDataFile (self .onts , self . attrc , key , ** _args )
842
+ _md = MetaDataFile (self .attrc , key , ** _args )
820
843
elif typ == "inline" :
821
844
self .ii += 1
822
845
key = self .ii
823
846
kwargs .update (_args )
824
- _md = InMemoryMetaData (self .onts , self . attrc , args [0 ])
847
+ _md = InMemoryMetaData (self .attrc , args [0 ])
825
848
elif typ == "remote" :
826
849
key = kwargs ["url" ]
827
850
for _key in ["node_name" , "check_validity" ]:
@@ -833,15 +856,15 @@ def load(self, typ, *args, **kwargs):
833
856
if "cert" not in kwargs :
834
857
kwargs ["cert" ] = ""
835
858
836
- _md = MetaDataExtern (self .onts , self . attrc ,
859
+ _md = MetaDataExtern (self .attrc ,
837
860
kwargs ["url" ], self .security ,
838
861
kwargs ["cert" ], self .http , ** _args )
839
862
elif typ == "mdfile" :
840
863
key = args [0 ]
841
- _md = MetaDataMD (self .onts , self . attrc , args [0 ], ** _args )
864
+ _md = MetaDataMD (self .attrc , args [0 ], ** _args )
842
865
elif typ == "loader" :
843
866
key = args [0 ]
844
- _md = MetaDataLoader (self .onts , self . attrc , args [0 ], ** _args )
867
+ _md = MetaDataLoader (self .attrc , args [0 ], ** _args )
845
868
else :
846
869
raise SAMLError ("Unknown metadata type '%s'" % typ )
847
870
_md .load ()
@@ -891,7 +914,7 @@ def imp(self, spec):
891
914
isfile (join (key [0 ], f ))]
892
915
for fil in files :
893
916
_fil = join (key [0 ], fil )
894
- _md = MetaDataFile (self .onts , self . attrc , _fil )
917
+ _md = MetaDataFile (self .attrc , _fil )
895
918
_md .load ()
896
919
self .metadata [_fil ] = _md
897
920
if _md .to_old :
@@ -901,7 +924,7 @@ def imp(self, spec):
901
924
if len (key ) == 2 :
902
925
kwargs ["cert" ] = key [1 ]
903
926
904
- _md = MDloader (self .onts , self . attrc , key [0 ], ** kwargs )
927
+ _md = MDloader (self .attrc , key [0 ], ** kwargs )
905
928
_md .load ()
906
929
self .metadata [key [0 ]] = _md
907
930
if _md .to_old :
0 commit comments