PMA\libraries\plugins\auth\AuthenticationCookie::authSetUser PHP 메소드

authSetUser() 공개 메소드

Set the user and password after last checkings if required
public authSetUser ( ) : boolean
리턴 boolean always true
    public function authSetUser()
    {
        global $cfg;
        // Ensures valid authentication mode, 'only_db', bookmark database and
        // table names and relation table name are used
        if (!hash_equals($cfg['Server']['user'], $GLOBALS['PHP_AUTH_USER'])) {
            foreach ($cfg['Servers'] as $idx => $current) {
                if ($current['host'] == $cfg['Server']['host'] && $current['port'] == $cfg['Server']['port'] && $current['socket'] == $cfg['Server']['socket'] && $current['ssl'] == $cfg['Server']['ssl'] && $current['connect_type'] == $cfg['Server']['connect_type'] && hash_equals($current['user'], $GLOBALS['PHP_AUTH_USER'])) {
                    $GLOBALS['server'] = $idx;
                    $cfg['Server'] = $current;
                    break;
                }
            }
            // end foreach
        }
        // end if
        if ($GLOBALS['cfg']['AllowArbitraryServer'] && !empty($GLOBALS['pma_auth_server'])) {
            /* Allow to specify 'host port' */
            $parts = explode(' ', $GLOBALS['pma_auth_server']);
            if (count($parts) == 2) {
                $tmp_host = $parts[0];
                $tmp_port = $parts[1];
            } else {
                $tmp_host = $GLOBALS['pma_auth_server'];
                $tmp_port = '';
            }
            if ($cfg['Server']['host'] != $GLOBALS['pma_auth_server']) {
                $cfg['Server']['host'] = $tmp_host;
                if (!empty($tmp_port)) {
                    $cfg['Server']['port'] = $tmp_port;
                }
            }
            unset($tmp_host, $tmp_port, $parts);
        }
        $cfg['Server']['user'] = $GLOBALS['PHP_AUTH_USER'];
        $cfg['Server']['password'] = $GLOBALS['PHP_AUTH_PW'];
        // Avoid showing the password in phpinfo()'s output
        unset($GLOBALS['PHP_AUTH_PW']);
        unset($_SERVER['PHP_AUTH_PW']);
        $this->setSessionAccessTime();
    }

Usage Example

 /**
  * Test for PMA\libraries\plugins\auth\AuthenticationConfig::authSetUser (check for headers redirect)
  *
  * @return void
  */
 public function testAuthSetUserWithHeaders()
 {
     if (!defined('PMA_TEST_HEADERS')) {
         $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension');
     }
     $GLOBALS['PHP_AUTH_USER'] = '******';
     $arr = array('host' => 'a', 'port' => 1, 'socket' => true, 'ssl' => true, 'connect_type' => 'port', 'user' => 'pmaUser2');
     $GLOBALS['cfg']['Server'] = $arr;
     $GLOBALS['cfg']['Server']['host'] = 'b';
     $GLOBALS['cfg']['Server']['user'] = '******';
     $GLOBALS['cfg']['Servers'][1] = $arr;
     $GLOBALS['cfg']['AllowArbitraryServer'] = true;
     $GLOBALS['pma_auth_server'] = 'b 2';
     $GLOBALS['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW'] = 'testPW';
     $GLOBALS['server'] = 2;
     $GLOBALS['cfg']['LoginCookieStore'] = true;
     $GLOBALS['from_cookie'] = false;
     $GLOBALS['cfg']['PmaAbsoluteUri'] = 'http://phpmyadmin.net/';
     $GLOBALS['collation_connection'] = 'utf-8';
     $restoreInstance = PMA\libraries\Response::getInstance();
     $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('disable'))->getMock();
     $mockResponse->expects($this->at(0))->method('disable');
     $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance');
     $attrInstance->setAccessible(true);
     $attrInstance->setValue($mockResponse);
     $this->object->authSetUser();
     $this->object->storeUserCredentials();
     $this->assertTrue(isset($_COOKIE['pmaServer-2']));
     // target can be "phpunit" or "ide-phpunit.php",
     // depending on testing environment
     $this->assertStringStartsWith('Location: http://phpmyadmin.net/index.php?', $GLOBALS['header'][0]);
     $this->assertContains('&target=', $GLOBALS['header'][0]);
     $this->assertContains('&server=2&lang=en&collation_connection=utf-8&token=token&PHPSESSID=', $GLOBALS['header'][0]);
     $attrInstance->setValue($restoreInstance);
 }
All Usage Examples Of PMA\libraries\plugins\auth\AuthenticationCookie::authSetUser