30
30
31
31
$ saml2auth = new \auth_saml2 \auth ();
32
32
33
- $ cert = file_get_contents ($ saml2auth ->certcrt );
34
- $ cert = preg_replace ('~(-----(BEGIN|END) CERTIFICATE-----)|\n~ ' , '' , $ cert );
35
- $ baseurl = $ CFG ->wwwroot . '/auth/saml2/idp ' ;
33
+ if ($ saml2auth ->config ->moodleidpenabled ) {
34
+ $ download = optional_param ('download ' , '' , PARAM_RAW );
35
+ if ($ download ) {
36
+ header ('Content-Disposition: attachment; filename= ' . $ saml2auth ->spname . '.xml ' );
37
+ }
36
38
37
- $ xml = <<<EOF
38
- <md:EntityDescriptor entityID=" {$ baseurl }/metadata.php" xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata">
39
- <md:IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol" WantAuthnRequestsSigned="false">
40
- <md:KeyDescriptor>
41
- <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
42
- <X509Data><X509Certificate> {$ cert }</X509Certificate></X509Data>
43
- </KeyInfo>
44
- </md:KeyDescriptor>
45
- <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
46
- Location=" {$ baseurl }/slo.php" />
47
- <md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</md:NameIDFormat>
48
- <md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
49
- Location=" {$ baseurl }/sso.php" />
50
- </md:IDPSSODescriptor>
51
- </md:EntityDescriptor>
52
- EOF ;
39
+ $ cert = file_get_contents ($ saml2auth ->certcrt );
40
+ $ cert = preg_replace ('~(-----(BEGIN|END) CERTIFICATE-----)|\n~ ' , '' , $ cert );
41
+ $ baseurl = $ CFG ->wwwroot . '/auth/saml2/idp ' ;
53
42
54
- header ('Content-Type: text/xml ' );
55
- echo ($ xml );
43
+ $ xml = <<<EOF
44
+ <md:EntityDescriptor entityID=" {$ baseurl }/metadata.php" xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata">
45
+ <md:IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol" WantAuthnRequestsSigned="false">
46
+ <md:KeyDescriptor>
47
+ <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
48
+ <X509Data><X509Certificate> {$ cert }</X509Certificate></X509Data>
49
+ </KeyInfo>
50
+ </md:KeyDescriptor>
51
+ <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
52
+ Location=" {$ baseurl }/slo.php" />
53
+ <md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</md:NameIDFormat>
54
+ <md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
55
+ Location=" {$ baseurl }/sso.php" />
56
+ </md:IDPSSODescriptor>
57
+ </md:EntityDescriptor>
58
+ EOF ;
59
+
60
+ header ('Content-Type: text/xml ' );
61
+ echo ($ xml );
62
+ } else {
63
+ throw new saml2_exception ('idp_enabled_error ' , get_string ('moodleidpenabled_error ' , 'auth_saml2 ' ));
64
+ }
0 commit comments