| Conditions | 17 |
| Paths | 588 |
| Total Lines | 73 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 60 | public function authenticate() { |
||
| 61 | \core\common\Entity::intoThePotatoes(); |
||
| 62 | $loggerInstance = new \core\common\Logging(); |
||
| 63 | $authSimple = new \SimpleSAML\Auth\Simple(\config\Master::AUTHENTICATION['ssp-authsource']); |
||
| 64 | if (!$authSimple->isAuthenticated()) { |
||
| 65 | $_SESSION['saveLog'] = true; |
||
| 66 | } |
||
| 67 | $authSimple->requireAuth(); |
||
| 68 | $admininfo = $authSimple->getAttributes(); |
||
| 69 | \core\common\Logging::debug_s(4, $admininfo, "SAML ATTR0:\n", "\n"); |
||
| 70 | if (isset($admininfo['uniqueIdentifier'])) { |
||
| 71 | $idps = explode('##########', $admininfo['uniqueIdentifier']); |
||
| 72 | $idpsNo = count($idps); |
||
| 73 | if ($idpsNo > 2) { |
||
| 74 | \core\common\Logging::debug_s(3, $idps, "PROXIED IDP:\n", "\n"); |
||
| 75 | } |
||
| 76 | $authorizingAuthority = $idps[count($idps)-2]; |
||
| 77 | \core\common\Logging::debug_s(3, $authorizingAuthority, "IDP:\n", "\n"); |
||
| 78 | $_SESSION['authorizing_authority'] = $authorizingAuthority; |
||
| 79 | |||
| 80 | } |
||
| 81 | if (isset($_SESSION['saveLog']) && $_SESSION['saveLog'] == true) { |
||
| 82 | $saveLog = true; |
||
| 83 | } else { |
||
| 84 | $saveLog = false; |
||
| 85 | } |
||
| 86 | unset($_SESSION['saveLog']); |
||
| 87 | $session = \SimpleSAML\Session::getSessionFromRequest(); |
||
| 88 | $session->cleanup(); |
||
| 89 | if (!isset($admininfo[\config\Master::AUTHENTICATION['ssp-attrib-identifier']][0])) { |
||
| 90 | $failtext = "FATAL ERROR: we did not receive a unique user identifier from the authentication source!"; |
||
| 91 | echo $failtext; |
||
| 92 | throw new Exception($failtext); |
||
| 93 | } |
||
| 94 | $user = $admininfo[\config\Master::AUTHENTICATION['ssp-attrib-identifier']][0]; |
||
| 95 | if ($saveLog) { |
||
| 96 | $loggerInstance->debug(4, "Writing log\n"); |
||
| 97 | $this->logLoginTime($user); |
||
| 98 | } |
||
| 99 | $_SESSION['user'] = $user; |
||
| 100 | $_SESSION['name'] = $admininfo[\config\Master::AUTHENTICATION['ssp-attrib-name']][0] ?? _("Unnamed User"); |
||
| 101 | $_SESSION['auth_email'] = $admininfo[\config\Master::AUTHENTICATION['ssp-attrib-email']][0] ?? _(""); |
||
| 102 | if (isset($admininfo[\config\Master::AUTHENTICATION['ssp-entitlement']])) { |
||
| 103 | $_SESSION['entitlement'] = $admininfo[\config\Master::AUTHENTICATION['ssp-entitlement']]; |
||
| 104 | } |
||
| 105 | /* |
||
| 106 | * This is a nice pathological test case for a user ID. |
||
| 107 | * |
||
| 108 | * */ |
||
| 109 | //$_SESSION['user'] = "<saml:NameID xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" NameQualifier=\"https://idp.jisc.ac.uk/idp/shibboleth\" SPNameQualifier=\"https://cat-beta.govroam.uk/simplesaml/module.php/saml/sp/metadata.php/default-sp\" Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:persistent\">XXXXXXXXXXXXXXXX</saml:NameID>"; |
||
| 110 | |||
| 111 | $newNameReceived = FALSE; |
||
| 112 | $userObject = new \core\User($user); |
||
| 113 | $attribMapping = [ |
||
| 114 | "ssp-attrib-name" => "user:realname", |
||
| 115 | "ssp-attrib-email" => "user:email"]; |
||
| 116 | foreach ($attribMapping as $SSPside => $CATside) { |
||
| 117 | if (isset($admininfo[\config\Master::AUTHENTICATION[$SSPside]][0]) && (count($userObject->getAttributes($CATside)) == 0) && \config\Master::DB['USER']['readonly'] === FALSE) { |
||
| 118 | $name = $admininfo[\config\Master::AUTHENTICATION[$SSPside]][0]; |
||
| 119 | $userObject->addAttribute($CATside, NULL, $name); |
||
| 120 | $loggerInstance->writeAudit($_SESSION['user'], "NEW", "User - added $CATside from external auth source"); |
||
| 121 | if ($CATside == "user:realname") { |
||
| 122 | $newNameReceived = TRUE; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | if (count($userObject->getAttributes('user:realname')) > 0 || $newNameReceived) { // we have a real name in the DB. We trust this more than a session one, so set it |
||
| 127 | $nameArray = $userObject->getAttributes("user:realname"); |
||
| 128 | if (!empty($nameArray[0])) { |
||
| 129 | $_SESSION['name'] = $nameArray[0]['value']; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | \core\common\Entity::outOfThePotatoes(); |
||
| 133 | } |
||
| 170 |