Conditions | 7 |
Paths | 64 |
Total Lines | 90 |
Code Lines | 43 |
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 |
||
38 | public function asArray() |
||
39 | { |
||
40 | $conf = []; |
||
41 | |||
42 | $conf['strict'] = $this->config()->get('strict'); |
||
43 | $conf['debug'] = $this->config()->get('debug'); |
||
44 | |||
45 | // SERVICE PROVIDER SECTION |
||
46 | $sp = $this->config()->get('SP'); |
||
47 | |||
48 | // set baseurl for SAML messages coming back to the SP |
||
49 | $conf['baseurl'] = $sp['entityId']; |
||
50 | |||
51 | $spCertPath = Director::is_absolute($sp['x509cert']) ? $sp['x509cert'] : sprintf('%s/%s', BASE_PATH, $sp['x509cert']); |
||
52 | $spKeyPath = Director::is_absolute($sp['privateKey']) ? $sp['privateKey'] : sprintf('%s/%s', BASE_PATH, $sp['privateKey']); |
||
53 | $conf['sp']['entityId'] = $sp['entityId']; |
||
54 | $conf['sp']['assertionConsumerService'] = [ |
||
55 | 'url' => $sp['entityId'] . '/saml/acs', |
||
56 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_POST |
||
57 | ]; |
||
58 | $conf['sp']['NameIDFormat'] = isset($sp['nameIdFormat']) ? $sp['nameIdFormat'] : OneLogin_Saml2_Constants::NAMEID_TRANSIENT; |
||
59 | $conf['sp']['x509cert'] = file_get_contents($spCertPath); |
||
60 | $conf['sp']['privateKey'] = file_get_contents($spKeyPath); |
||
61 | |||
62 | // IDENTITY PROVIDER SECTION |
||
63 | $idp = $this->config()->get('IdP'); |
||
64 | $conf['idp']['entityId'] = $idp['entityId']; |
||
65 | $conf['idp']['singleSignOnService'] = [ |
||
66 | 'url' => $idp['singleSignOnService'], |
||
67 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT, |
||
68 | ]; |
||
69 | if (isset($idp['singleLogoutService'])) { |
||
70 | $conf['idp']['singleLogoutService'] = [ |
||
71 | 'url' => $idp['singleLogoutService'], |
||
72 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT, |
||
73 | ]; |
||
74 | } |
||
75 | |||
76 | $idpCertPath = Director::is_absolute($idp['x509cert']) ? $idp['x509cert'] : sprintf('%s/%s', BASE_PATH, $idp['x509cert']); |
||
77 | $conf['idp']['x509cert'] = file_get_contents($idpCertPath); |
||
78 | |||
79 | // SECURITY SECTION |
||
80 | $security = $this->config()->get('Security'); |
||
81 | $signatureAlgorithm = $security['signatureAlgorithm']; |
||
82 | $requestedAuthnContextComparison = $security['requestedAuthnContextComparison'] ?: 'exact'; |
||
83 | |||
84 | $conf['security'] = [ |
||
85 | /** signatures and encryptions offered */ |
||
86 | // Indicates that the nameID of the <samlp:logoutRequest> sent by this SP will be encrypted. |
||
87 | 'nameIdEncrypted' => true, |
||
88 | // Indicates whether the <samlp:AuthnRequest> messages sent by this SP will be signed. [Metadata of the SP will offer this info] |
||
89 | 'authnRequestsSigned' => true, |
||
90 | // Indicates whether the <samlp:logoutRequest> messages sent by this SP will be signed. |
||
91 | 'logoutRequestSigned' => true, |
||
92 | // Indicates whether the <samlp:logoutResponse> messages sent by this SP will be signed. |
||
93 | 'logoutResponseSigned' => true, |
||
94 | 'signMetadata' => false, |
||
95 | /** signatures and encryptions required **/ |
||
96 | // Indicates a requirement for the <samlp:Response>, <samlp:LogoutRequest> |
||
97 | // and <samlp:LogoutResponse> elements received by this SP to be signed. |
||
98 | 'wantMessagesSigned' => false, |
||
99 | // Indicates a requirement for the <saml:Assertion> elements received by |
||
100 | // this SP to be signed. [Metadata of the SP will offer this info] |
||
101 | 'wantAssertionsSigned' => true, |
||
102 | // Indicates a requirement for the NameID received by |
||
103 | // this SP to be encrypted. |
||
104 | 'wantNameIdEncrypted' => false, |
||
105 | // Algorithm that the toolkit will use on signing process. Options: |
||
106 | // - 'http://www.w3.org/2000/09/xmldsig#rsa-sha1' |
||
107 | // - 'http://www.w3.org/2000/09/xmldsig#dsa-sha1' |
||
108 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256' |
||
109 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384' |
||
110 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512' |
||
111 | 'signatureAlgorithm' => $signatureAlgorithm, |
||
112 | // Authentication context. |
||
113 | // Set to false and no AuthContext will be sent in the AuthNRequest, |
||
114 | // 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' |
||
115 | // 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'), |
||
116 | 'requestedAuthnContext' => $this->getrequestedAuthnContext(), |
||
117 | // Allows the authn comparison parameter to be set, defaults to 'exact' if |
||
118 | // the setting is not present. |
||
119 | // better | exact | maximum | minimum |
||
120 | 'requestedAuthnContextComparison' => $requestedAuthnContextComparison, |
||
121 | // Indicates if the SP will validate all received xmls. |
||
122 | // (In order to validate the xml, 'strict' and 'wantXMLValidation' must be true). |
||
123 | 'wantXMLValidation' => true, |
||
124 | ]; |
||
125 | |||
126 | return $conf; |
||
127 | } |
||
128 | |||
166 |
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.