|
| 1 | +<?php |
| 2 | + |
| 3 | +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 4 | +// The fields of the login form of the Test SP (sp.php) |
| 5 | +// |
| 6 | +// Each field is described once here. This description is used to: |
| 7 | +// - normalise the request parameters (normaliseParams()), so the rest of the code gets valid values |
| 8 | +// - render the field (renderField() in sp-utils.inc) |
| 9 | +// What a field does in the AuthnRequest is in sp-login.inc |
| 10 | +// |
| 11 | +// Field properties: |
| 12 | +// - type: 'select', 'text' or 'checkbox'. The value of a checked checkbox is 'true', of an unchecked one '' |
| 13 | +// - label: The label in front of the field |
| 14 | +// - help: Hover help text of the label (optional) |
| 15 | +// - options: select: value => display name |
| 16 | +// - default: The value when the parameter is missing. For a select with a default, an unknown value also |
| 17 | +// becomes the default. A select without a default keeps any value (e.g. idp: SimpleSAMLphp checks it) |
| 18 | +// - datalist: text: suggested values (optional) |
| 19 | +// - list: text: use the datalist of this other field (optional) |
| 20 | +// - id: HTML id of the field (optional, defaults to the field name) |
| 21 | +// |
| 22 | +// Requires $gIDPmap from sp-config.inc |
| 23 | + |
| 24 | +/** The signature algorithms for the AuthnRequest: 'signing' value => algorithm identifier ('' is not signed) */ |
| 25 | +const SP_SIGNING_ALGORITHMS = array( |
| 26 | + 'none' => '', |
| 27 | + 'rsa-sha1' => 'http://www.w3.org/2000/09/xmldsig#rsa-sha1', |
| 28 | + 'rsa-sha256' => 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256', |
| 29 | + 'rsa-sha384' => 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384', |
| 30 | + 'rsa-sha512' => 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512', |
| 31 | +); |
| 32 | + |
| 33 | +const SP_BINDING_REDIRECT = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'; |
| 34 | +const SP_BINDING_POST = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'; |
| 35 | + |
| 36 | +$gFormFields = array( |
| 37 | + 'idp' => array( |
| 38 | + 'type' => 'select', |
| 39 | + 'label' => 'Identity Provider:', |
| 40 | + 'help' => 'Select the IdP to authenticate to', |
| 41 | + 'options' => array_map(static fn (array $idp): string => $idp['name'], $gIDPmap), |
| 42 | + ), |
| 43 | + 'loa' => array( |
| 44 | + 'type' => 'select', |
| 45 | + 'label' => 'Request LOA:', |
| 46 | + 'help' => 'Select the level of assurance to include in the AuthnContextClassRef in the AuthnRequest. The value depends on the selected IdP and the selected LoA and is only added when the IdP supports it.', |
| 47 | + 'options' => array('' => 'None', '1' => '1', '1.5' => '1.5', '2' => '2', '3' => '3'), |
| 48 | + 'default' => '', |
| 49 | + ), |
| 50 | + 'sp' => array( |
| 51 | + 'type' => 'select', |
| 52 | + 'label' => 'Service Provider EntityID:', |
| 53 | + 'help' => 'Select the EntityID to use for this SP. This value goes into the Issuer in the AuthnRequest.', |
| 54 | + 'options' => array('default-sp' => 'default-sp', 'second-sp' => 'second-sp', 'third-sp' => 'third-sp', 'fourth-sp' => 'fourth-sp'), |
| 55 | + 'default' => 'default-sp', |
| 56 | + ), |
| 57 | + 'signing' => array( |
| 58 | + 'type' => 'select', |
| 59 | + 'label' => 'Signing:', |
| 60 | + 'help' => "Select the signing algorithm the SP must use to sign the AuthnRequest, select 'none' to disable signing.", |
| 61 | + 'options' => array_combine(array_keys(SP_SIGNING_ALGORITHMS), array_keys(SP_SIGNING_ALGORITHMS)), |
| 62 | + 'default' => 'rsa-sha256', |
| 63 | + ), |
| 64 | + 'key' => array( |
| 65 | + 'type' => 'select', |
| 66 | + 'label' => 'Signing key:', |
| 67 | + 'help' => 'Select the key the SP must use for signing the AuthnRequest. The default key is the key that is present in the SP metadata.', |
| 68 | + 'options' => array('default' => 'default', 'secondary' => 'secondary'), |
| 69 | + 'default' => 'default', |
| 70 | + ), |
| 71 | + 'nameidpolicy' => array( |
| 72 | + 'type' => 'select', |
| 73 | + 'label' => 'NameIDPolicy:', |
| 74 | + 'help' => "Select the NameID policy that the SP should request from the IdP. This value is put in the Format attribute of the NameIDPolicy in the AuthnRequest. 'None' uses the simpleSAMLphp default behaviour based on the SP and IdP metadata.", |
| 75 | + 'options' => array( |
| 76 | + '' => 'None', |
| 77 | + 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified' => 'unspecified', |
| 78 | + 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' => 'persistent', |
| 79 | + 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient' => 'transient', |
| 80 | + ), |
| 81 | + 'default' => '', |
| 82 | + ), |
| 83 | + 'ssobinding' => array( |
| 84 | + 'type' => 'select', |
| 85 | + 'label' => 'SSO Binding:', |
| 86 | + 'help' => 'Specify the SAML Binding that the SP must use to send the AuthnRequest to the IdP.', |
| 87 | + 'options' => array(SP_BINDING_REDIRECT => 'HTTP-Redirect', SP_BINDING_POST => 'HTTP-POST'), |
| 88 | + 'default' => SP_BINDING_REDIRECT, |
| 89 | + ), |
| 90 | + 'requesterid' => array( |
| 91 | + 'type' => 'text', |
| 92 | + 'label' => 'Scoping (RequesterID) 1:', |
| 93 | + 'help' => 'Specify up to two SP EntityIDs to put in RequesterID Scoping elements in the AuthnRequest. If left blank no elements are added.', |
| 94 | + 'datalist' => array('http://localhost/simplesaml/module.php/saml/sp/metadata.php/pieter-local-test-sp'), |
| 95 | + ), |
| 96 | + 'requesterid2' => array( |
| 97 | + 'type' => 'text', |
| 98 | + 'label' => '2:', |
| 99 | + 'list' => 'requesterid', |
| 100 | + ), |
| 101 | + 'scopingIDP' => array( |
| 102 | + 'type' => 'text', |
| 103 | + 'id' => 'scoping_idp', |
| 104 | + 'label' => 'Scoping (IDPList) 1:', |
| 105 | + 'help' => 'Specify up to two IdP EntityIDs to put in IDPList Scoping elements in the AuthnRequest. If left blank no elements are added.', |
| 106 | + 'datalist' => array('https://pieter.aai.surfnet.nl/simplesamlphp/saml2/idp/metadata.php', 'https://idp.surfnet.nl'), |
| 107 | + ), |
| 108 | + 'scopingIDP2' => array( |
| 109 | + 'type' => 'text', |
| 110 | + 'label' => '2:', |
| 111 | + 'list' => 'scopingIDP', |
| 112 | + ), |
| 113 | + 'subject' => array( |
| 114 | + 'type' => 'text', |
| 115 | + 'label' => 'Subject:', |
| 116 | + 'help' => "Specify the value of a NameID to put in a Subject element in the AuthnRequest. If specified a NameID of type 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified' is added to the AuthnRequest.", |
| 117 | + 'datalist' => array( |
| 118 | + 'urn:collab:person:dev.openconext.local:admin', |
| 119 | + 'urn:collab:person:institution-a.example.com:jane-a1', |
| 120 | + 'urn:collab:person:institution-a.example.com:joe-a1', |
| 121 | + 'urn:collab:person:institution-a.example.com:', |
| 122 | + 'urn:collab:person:institution-b.example.com:', |
| 123 | + 'urn:collab:person:institution-c.example.com:', |
| 124 | + 'urn:collab:person:institution-d.example.com:', |
| 125 | + 'urn:collab:person:Institution-D.EXAMPLE.COM:', |
| 126 | + 'urn:collab:person:institution-e.example.com:', |
| 127 | + 'urn:collab:person:institution-f.example.com:', |
| 128 | + ), |
| 129 | + ), |
| 130 | + 'forceauthn' => array( |
| 131 | + 'type' => 'checkbox', |
| 132 | + 'label' => 'Force authentication:', |
| 133 | + 'help' => 'If selected ForceAuthn is set to true in the AuthnRequest.', |
| 134 | + ), |
| 135 | + 'acsurl' => array( |
| 136 | + 'type' => 'text', |
| 137 | + 'label' => 'AssertionConsumerServiceURL:', |
| 138 | + // The help text and datalist need the URLs of SimpleSAMLphp: sp.php sets them |
| 139 | + 'help' => 'Optionally override the AssertionConsumerServiceURL to specify in the AuthnRequest. Leave blank to use the default ACS location that is generated by SimpleSAMLphp.', |
| 140 | + 'datalist' => array(), |
| 141 | + ), |
| 142 | + 'emulateadfs' => array( |
| 143 | + 'type' => 'checkbox', |
| 144 | + 'label' => 'Emulate SFO ADFS extension:', |
| 145 | + 'help' => "If selected two extra POST variables 'AuthMethod' and 'Context' are added to the AuthnRequest and the HTTP-POST binding is used. Note: Request LOA and Subject should be specified as well to make a valid SFO request to the Stepup-Gateway", |
| 146 | + ), |
| 147 | + 'email_extension' => array( |
| 148 | + 'type' => 'text', |
| 149 | + 'label' => 'Email Userinfo extension:', |
| 150 | + 'help' => 'Specify an email address. If left blank the email extension is not added.', |
| 151 | + ), |
| 152 | + 'sho_extension' => array( |
| 153 | + 'type' => 'text', |
| 154 | + 'label' => 'SHO Userinfo extension:', |
| 155 | + 'help' => 'Specify a domain. If left blank the schacHomeOrganization extension is not added.', |
| 156 | + 'datalist' => array( |
| 157 | + 'institution-a.example.com', |
| 158 | + 'institution-b.example.com', |
| 159 | + 'institution-c.example.com', |
| 160 | + 'institution-d.example.com', |
| 161 | + 'Institution-D.EXAMPLE.COM', |
| 162 | + 'institution-e.example.com', |
| 163 | + 'institution-f.example.com', |
| 164 | + ), |
| 165 | + ), |
| 166 | + 'mdui_displayname' => array( |
| 167 | + 'type' => 'text', |
| 168 | + 'label' => 'Service name (mdui:DisplayName) extension:', |
| 169 | + 'help' => 'Specify a service name. If left blank the mdui:UIInfo extension is not added.', |
| 170 | + ), |
| 171 | +); |
| 172 | + |
| 173 | + |
| 174 | +/** |
| 175 | + * The values of the form fields from request parameters: one string value for every field in $fields. |
| 176 | + * Missing parameters get the default, unknown select values the default (when the select has one). |
| 177 | + * Parameters that are not form fields (e.g. 'action') are not included. |
| 178 | + */ |
| 179 | +function normaliseParams(array $request, array $fields): array |
| 180 | +{ |
| 181 | + $params = array(); |
| 182 | + foreach ($fields as $name => $field) { |
| 183 | + $value = $request[$name] ?? null; |
| 184 | + if (!is_string($value)) { |
| 185 | + $value = null; // Missing, or not a single value (e.g. name[]=...) |
| 186 | + } |
| 187 | + switch ($field['type']) { |
| 188 | + case 'checkbox': |
| 189 | + $value = $value === 'true' ? 'true' : ''; |
| 190 | + break; |
| 191 | + case 'select': |
| 192 | + if (array_key_exists('default', $field) && ($value === null || !array_key_exists($value, $field['options']))) { |
| 193 | + $value = $field['default']; |
| 194 | + } |
| 195 | + break; |
| 196 | + } |
| 197 | + $params[$name] = $value ?? ($field['default'] ?? ''); |
| 198 | + } |
| 199 | + return $params; |
| 200 | +} |
0 commit comments