|
36 |
from subprocess import call |
36 |
from subprocess import call |
37 |
from time import sleep |
37 |
from time import sleep |
38 |
from urlparse import urlparse |
38 |
from urlparse import urlparse |
|
|
39 |
from xml.etree import ElementTree |
39 |
workaround = set() |
40 |
workaround = set() |
40 |
|
41 |
|
41 |
|
42 |
|
|
49 |
workaround.add(True) |
50 |
workaround.add(True) |
50 |
cleanup() |
51 |
cleanup() |
51 |
metadata_download_failed = [] |
52 |
metadata_download_failed = [] |
|
|
53 |
metadata_validation_failed = [] |
52 |
saml_idp = config_registry.get('umc/saml/idp-server') |
54 |
saml_idp = config_registry.get('umc/saml/idp-server') |
53 |
if saml_idp and not download_idp_metadata(saml_idp): |
55 |
if saml_idp and not download_idp_metadata(saml_idp): |
54 |
metadata_download_failed.append(saml_idp) |
56 |
metadata_download_failed.append(saml_idp) |
|
|
57 |
elif not valid_metadata(saml_idp): |
58 |
metadata_validation_failed.append(saml_idp) |
55 |
reload_webserver() |
59 |
reload_webserver() |
56 |
if not rewrite_sasl_configuration(): |
60 |
if not rewrite_sasl_configuration(): |
57 |
raise SystemExit('Could not rewrite SASL configuration for UMC.') |
61 |
raise SystemExit('Could not rewrite SASL configuration for UMC.') |
58 |
if metadata_download_failed: |
62 |
if metadata_download_failed: |
59 |
raise SystemExit('Could not download IDP metadata for %s' % (', '.join(metadata_download_failed),)) |
63 |
raise SystemExit('Could not download IDP metadata for %s' % (', '.join(metadata_download_failed),)) |
|
|
64 |
if metadata_validation_failed: |
65 |
raise SystemExit('IDP metadata not valid for %s' % (', '.join(metadata_validation_failed),)) |
60 |
|
66 |
|
61 |
|
67 |
|
62 |
def cleanup(): |
68 |
def cleanup(): |
|
64 |
os.remove(metadata) |
70 |
os.remove(metadata) |
65 |
|
71 |
|
66 |
|
72 |
|
|
|
73 |
def valid_metadata(saml_idp): |
74 |
idp = bytes(urlparse(saml_idp).netloc) |
75 |
filename = '/usr/share/univention-management-console/saml/idp/%s.xml' % (idp,) |
76 |
try: |
77 |
ElementTree.parse(filename) |
78 |
except ElementTree.ParseError: |
79 |
os.remove(filename) |
80 |
return False |
81 |
return True |
82 |
|
83 |
|
67 |
def download_idp_metadata(metadata): |
84 |
def download_idp_metadata(metadata): |
68 |
idp = bytes(urlparse(metadata).netloc) |
85 |
idp = bytes(urlparse(metadata).netloc) |
69 |
filename = '/usr/share/univention-management-console/saml/idp/%s.xml' % (idp,) |
86 |
filename = '/usr/share/univention-management-console/saml/idp/%s.xml' % (idp,) |
|
71 |
print 'Try to download idp metadata (%s/60)' % (i + 1) |
88 |
print 'Try to download idp metadata (%s/60)' % (i + 1) |
72 |
rc = call([ |
89 |
rc = call([ |
73 |
'/usr/bin/curl', |
90 |
'/usr/bin/curl', |
|
|
91 |
'--fail', |
74 |
'--cacert', '/etc/univention/ssl/ucsCA/CAcert.pem', |
92 |
'--cacert', '/etc/univention/ssl/ucsCA/CAcert.pem', |
75 |
'-o', filename, |
93 |
'-o', filename, |
76 |
metadata, |
94 |
metadata, |