| Conditions | 8 |
| Paths | 128 |
| Total Lines | 93 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 45 | public function asArray() |
||
| 46 | { |
||
| 47 | $conf = []; |
||
| 48 | |||
| 49 | $conf['strict'] = $this->config()->get('strict'); |
||
| 50 | $conf['debug'] = $this->config()->get('debug'); |
||
| 51 | |||
| 52 | // SERVICE PROVIDER SECTION |
||
| 53 | $sp = $this->config()->get('SP'); |
||
| 54 | |||
| 55 | // Set baseurl for SAML messages coming back to the SP |
||
| 56 | $conf['baseurl'] = sprintf('%s/saml', $sp['entityId']); |
||
| 57 | |||
| 58 | $spCertPath = Director::is_absolute($sp['x509cert']) ? $sp['x509cert'] : sprintf('%s/%s', BASE_PATH, $sp['x509cert']); |
||
| 59 | $spKeyPath = Director::is_absolute($sp['privateKey']) ? $sp['privateKey'] : sprintf('%s/%s', BASE_PATH, $sp['privateKey']); |
||
| 60 | $conf['sp']['entityId'] = $sp['entityId']; |
||
| 61 | $conf['sp']['assertionConsumerService'] = [ |
||
| 62 | 'url' => $sp['entityId'] . '/saml/acs', |
||
| 63 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_POST |
||
| 64 | ]; |
||
| 65 | $conf['sp']['NameIDFormat'] = isset($sp['nameIdFormat']) ? $sp['nameIdFormat'] : OneLogin_Saml2_Constants::NAMEID_TRANSIENT; |
||
| 66 | $conf['sp']['x509cert'] = file_get_contents($spCertPath); |
||
| 67 | $conf['sp']['privateKey'] = file_get_contents($spKeyPath); |
||
| 68 | |||
| 69 | // IDENTITY PROVIDER SECTION |
||
| 70 | $idp = $this->config()->get('IdP'); |
||
| 71 | $conf['idp']['entityId'] = $idp['entityId']; |
||
| 72 | $conf['idp']['singleSignOnService'] = [ |
||
| 73 | 'url' => $idp['singleSignOnService'], |
||
| 74 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT, |
||
| 75 | ]; |
||
| 76 | if (isset($idp['singleLogoutService'])) { |
||
| 77 | $conf['idp']['singleLogoutService'] = [ |
||
| 78 | 'url' => $idp['singleLogoutService'], |
||
| 79 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT, |
||
| 80 | ]; |
||
| 81 | } |
||
| 82 | |||
| 83 | $idpCertPath = Director::is_absolute($idp['x509cert']) ? $idp['x509cert'] : sprintf('%s/%s', BASE_PATH, $idp['x509cert']); |
||
| 84 | $conf['idp']['x509cert'] = file_get_contents($idpCertPath); |
||
| 85 | |||
| 86 | $conf['security'] = [ |
||
| 87 | /** signatures and encryptions offered */ |
||
| 88 | // Indicates that the nameID of the <samlp:logoutRequest> sent by this SP will be encrypted. |
||
| 89 | 'nameIdEncrypted' => true, |
||
| 90 | // Indicates whether the <samlp:AuthnRequest> messages sent by this SP will be signed. [Metadata of the SP will offer this info] |
||
| 91 | 'authnRequestsSigned' => true, |
||
| 92 | // Indicates whether the <samlp:logoutRequest> messages sent by this SP will be signed. |
||
| 93 | 'logoutRequestSigned' => true, |
||
| 94 | // Indicates whether the <samlp:logoutResponse> messages sent by this SP will be signed. |
||
| 95 | 'logoutResponseSigned' => true, |
||
| 96 | 'signMetadata' => false, |
||
| 97 | /** signatures and encryptions required **/ |
||
| 98 | // Indicates a requirement for the <samlp:Response>, <samlp:LogoutRequest> |
||
| 99 | // and <samlp:LogoutResponse> elements received by this SP to be signed. |
||
| 100 | 'wantMessagesSigned' => false, |
||
| 101 | // Indicates a requirement for the <saml:Assertion> elements received by |
||
| 102 | // this SP to be signed. [Metadata of the SP will offer this info] |
||
| 103 | 'wantAssertionsSigned' => true, |
||
| 104 | // Indicates a requirement for the NameID received by |
||
| 105 | // this SP to be encrypted. |
||
| 106 | 'wantNameIdEncrypted' => false, |
||
| 107 | // Authentication context. |
||
| 108 | // Set to false and no AuthContext will be sent in the AuthNRequest, |
||
| 109 | // Set true or don't present thi parameter and you will get an AuthContext 'exact' 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport' |
||
| 110 | // Set an array with the possible auth context values: array ('urn:oasis:names:tc:SAML:2.0:ac:classes:Password', 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509'), |
||
| 111 | 'requestedAuthnContext' => $this->getRequestedAuthnContext(), |
||
| 112 | // Indicates if the SP will validate all received xmls. |
||
| 113 | // (In order to validate the xml, 'strict' and 'wantXMLValidation' must be true). |
||
| 114 | 'wantXMLValidation' => true, |
||
| 115 | ]; |
||
| 116 | |||
| 117 | $security = $this->config()->get('Security'); |
||
| 118 | |||
| 119 | if (isset($security['signatureAlgorithm'])) { |
||
| 120 | // Algorithm that the toolkit will use on signing process. Options: |
||
| 121 | // - 'http://www.w3.org/2000/09/xmldsig#rsa-sha1' |
||
| 122 | // - 'http://www.w3.org/2000/09/xmldsig#dsa-sha1' |
||
| 123 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256' |
||
| 124 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384' |
||
| 125 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512' |
||
| 126 | $conf['security']['signatureAlgorithm'] = $security['signatureAlgorithm']; |
||
| 127 | } |
||
| 128 | |||
| 129 | if (isset($security['requestedAuthnContextComparison'])) { |
||
| 130 | // Allows the authn comparison parameter to be set, defaults to 'exact' if |
||
| 131 | // the setting is not present. |
||
| 132 | // better | exact | maximum | minimum |
||
| 133 | $conf['security']['requestedAuthnContextComparison'] = $security['requestedAuthnContextComparison']; |
||
| 134 | } |
||
| 135 | |||
| 136 | return $conf; |
||
| 137 | } |
||
| 138 | |||
| 180 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.