cando['external'] = true; // Assumes redirect already happened. $this->cando['logout'] = false; // Logout happens elsewhere. } public function trustExternal($user, $pass, $sticky = false) { // We assume $user is ALWAYS nil and overwrite with header value. $data = $this->getUserData($user); if ($data) { return $this->fillGlobals($data); } return false; } private function fillGlobals($data) { global $USERINFO; $USERINFO['name'] = $data['user']; $USERINFO['mail'] = $data['mail']; $USERINFO['grps'] = $data['groups']; $_SERVER['REMOTE_USER'] = $data['user']; $_SESSION[DOKU_COOKIE]['auth']['user'] = $data['user']; $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO; return true; } public function getUserData($user, $requireGroups = true) { // If no user is provided, no auth was done. Admin will // need to fix their ForwardAuth in the reverse proxy. // For example, setting the ForwardAuth middleware. // I do not believe there is a course of action we can // perform here as we don't know the middleware path. $user = $this->getAuthUser(); if (empty($user)) { return false; } $data = array(); $data['user'] = $user; $data['name'] = $this->getAuthName(); $data['mail'] = $this->getAuthMail(); $data['groups'] = $this->getAuthGroups(); return $data; } /* Extract header values from HTTP Request. */ private function getAuthUser() { return sane_lookup($this->getAuthUserHeader()); } private function getAuthMail() { return sane_lookup($this->getAuthMailHeader()); } private function getAuthName() { $name = sane_lookup($this->getAuthNameHeader()); if (empty($name)) { return $this->getAuthUser(); } return $name; } private function getAuthGroups() { $groups = sane_lookup($this->getAuthGroupsHeader()); return explode(',', $groups); } /* Generate PHP HTTP Header names from Config values. */ private function getAuthUserHeader() { return header_to_php_name( plugin_conf('userHeader', self::USER_HEADER) ); } private function getAuthNameHeader() { return header_to_php_name( plugin_conf('nameHeader', self::NAME_HEADER) ); } private function getAuthMailHeader() { return header_to_php_name( plugin_conf('mailHeader', self::MAIL_HEADER) ); } private function getAuthGroupsHeader() { return header_to_php_name( plugin_conf('groupsHeader', self::GRPS_HEADER) ); } } function plugin_conf($name, $default="") { global $conf; if (!array_key_exists('plugin', $conf)) { return $default; } if (!array_key_exists('forwardauth', $conf['plugin'])) { return $default; } if (!array_key_exists($name, $conf['plugin']['forwardauth'])) { return $default; } return $conf['plugin']['forwardauth'][$name]; } function sane_lookup($header) { // Simplify header lookup by making sure it is set. return ($header === '') ? "" : $_SERVER[$header]; } function header_to_php_name($header) { // Headers are all uppercase, and all '-' must be underscores. return ($header === '') ? "" : "HTTP_" . strtoupper(str_replace('-', '_', $header)); }