| Conditions | 8 |
| Paths | 96 |
| Total Lines | 114 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 98 | public function asArray() |
||
| 99 | { |
||
| 100 | $conf = []; |
||
| 101 | |||
| 102 | $conf['strict'] = $this->config()->get('strict'); |
||
| 103 | $conf['debug'] = $this->config()->get('debug'); |
||
| 104 | |||
| 105 | // SERVICE PROVIDER SECTION |
||
| 106 | $sp = $this->config()->get('SP'); |
||
| 107 | |||
| 108 | $spX509Cert = Injector::inst()->convertServiceProperty($sp['x509cert']); |
||
| 109 | $spCertPath = Director::is_absolute($spX509Cert) |
||
| 110 | ? $spX509Cert |
||
| 111 | : sprintf('%s/%s', BASE_PATH, $spX509Cert); |
||
| 112 | $spPrivateKey = Injector::inst()->convertServiceProperty($sp['privateKey']); |
||
| 113 | $spKeyPath = Director::is_absolute($spPrivateKey) |
||
| 114 | ? $spPrivateKey |
||
| 115 | : sprintf('%s/%s', BASE_PATH, $spPrivateKey); |
||
| 116 | |||
| 117 | $conf['sp']['entityId'] = Injector::inst()->convertServiceProperty($sp['entityId']); |
||
| 118 | $conf['sp']['assertionConsumerService'] = [ |
||
| 119 | 'url' => Injector::inst()->convertServiceProperty($sp['entityId']) . '/saml/acs', |
||
| 120 | 'binding' => Constants::BINDING_HTTP_POST |
||
| 121 | ]; |
||
| 122 | $conf['sp']['NameIDFormat'] = isset($sp['nameIdFormat']) ? |
||
| 123 | $sp['nameIdFormat'] : Constants::NAMEID_TRANSIENT; |
||
| 124 | $conf['sp']['x509cert'] = file_get_contents($spCertPath); |
||
| 125 | $conf['sp']['privateKey'] = file_get_contents($spKeyPath); |
||
| 126 | |||
| 127 | // IDENTITY PROVIDER SECTION |
||
| 128 | $idp = $this->config()->get('IdP'); |
||
| 129 | $conf['idp']['entityId'] = Injector::inst()->convertServiceProperty($idp['entityId']); |
||
| 130 | $conf['idp']['singleSignOnService'] = [ |
||
| 131 | 'url' => Injector::inst()->convertServiceProperty($idp['singleSignOnService']), |
||
| 132 | 'binding' => Constants::BINDING_HTTP_REDIRECT, |
||
| 133 | ]; |
||
| 134 | if (isset($idp['singleLogoutService'])) { |
||
| 135 | $conf['idp']['singleLogoutService'] = [ |
||
| 136 | 'url' => Injector::inst()->convertServiceProperty($idp['singleLogoutService']), |
||
| 137 | 'binding' => Constants::BINDING_HTTP_REDIRECT, |
||
| 138 | ]; |
||
| 139 | } |
||
| 140 | |||
| 141 | $idpX509Cert = Injector::inst()->convertServiceProperty($idp['x509cert']); |
||
| 142 | $idpCertPath = Director::is_absolute($idpX509Cert) |
||
| 143 | ? $idpX509Cert |
||
| 144 | : sprintf('%s/%s', BASE_PATH, $idpX509Cert); |
||
| 145 | $conf['idp']['x509cert'] = file_get_contents($idpCertPath); |
||
| 146 | |||
| 147 | // SECURITY SECTION |
||
| 148 | $security = $this->config()->get('Security'); |
||
| 149 | $signatureAlgorithm = $security['signatureAlgorithm']; |
||
| 150 | |||
| 151 | $authnContexts = $this->config()->get('authn_contexts'); |
||
| 152 | $disableAuthnContexts = $this->config()->get('disable_authn_contexts'); |
||
| 153 | |||
| 154 | if ((bool)$disableAuthnContexts) { |
||
| 155 | $authnContexts = false; |
||
| 156 | } else { |
||
| 157 | if (!is_array($authnContexts)) { |
||
| 158 | // Fallback to default contexts if the supplied value isn't valid |
||
| 159 | $authnContexts = [ |
||
| 160 | 'urn:federation:authentication:windows', |
||
| 161 | 'urn:oasis:names:tc:SAML:2.0:ac:classes:Password', |
||
| 162 | 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509', |
||
| 163 | ]; |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | $conf['security'] = [ |
||
| 168 | /** signatures and encryptions offered */ |
||
| 169 | // Indicates that the nameID of the <samlp:logoutRequest> sent by this SP will be encrypted. |
||
| 170 | 'nameIdEncrypted' => true, |
||
| 171 | // Indicates whether the <samlp:AuthnRequest> messages sent by this SP will be signed. [Metadata of the |
||
| 172 | // SP will offer this info] |
||
| 173 | 'authnRequestsSigned' => true, |
||
| 174 | // Indicates whether the <samlp:logoutRequest> messages sent by this SP will be signed. |
||
| 175 | 'logoutRequestSigned' => true, |
||
| 176 | // Indicates whether the <samlp:logoutResponse> messages sent by this SP will be signed. |
||
| 177 | 'logoutResponseSigned' => true, |
||
| 178 | 'signMetadata' => false, |
||
| 179 | /** signatures and encryptions required **/ |
||
| 180 | // Indicates a requirement for the <samlp:Response>, <samlp:LogoutRequest> |
||
| 181 | // and <samlp:LogoutResponse> elements received by this SP to be signed. |
||
| 182 | 'wantMessagesSigned' => false, |
||
| 183 | // Indicates a requirement for the <saml:Assertion> elements received by |
||
| 184 | // this SP to be signed. [Metadata of the SP will offer this info] |
||
| 185 | 'wantAssertionsSigned' => true, |
||
| 186 | // Indicates a requirement for the NameID received by |
||
| 187 | // this SP to be encrypted. |
||
| 188 | 'wantNameIdEncrypted' => false, |
||
| 189 | |||
| 190 | // Algorithm that the toolkit will use on signing process. Options: |
||
| 191 | // - 'http://www.w3.org/2000/09/xmldsig#rsa-sha1' |
||
| 192 | // - 'http://www.w3.org/2000/09/xmldsig#dsa-sha1' |
||
| 193 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256' |
||
| 194 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384' |
||
| 195 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512' |
||
| 196 | 'signatureAlgorithm' => $signatureAlgorithm, |
||
| 197 | |||
| 198 | // Authentication context. |
||
| 199 | // Set to false and no AuthContext will be sent in the AuthNRequest, |
||
| 200 | // Set true or don't present thi parameter and you will get an AuthContext |
||
| 201 | // 'exact' 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport' |
||
| 202 | // Set an array with the possible auth context values: |
||
| 203 | // array ('urn:oasis:names:tc:SAML:2.0:ac:classes:Password', 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509'), |
||
| 204 | 'requestedAuthnContext' => $authnContexts, |
||
| 205 | |||
| 206 | // Indicates if the SP will validate all received xmls. |
||
| 207 | // (In order to validate the xml, 'strict' and 'wantXMLValidation' must be true). |
||
| 208 | 'wantXMLValidation' => true, |
||
| 209 | ]; |
||
| 210 | |||
| 211 | return $conf; |
||
| 212 | } |
||
| 214 |