phpCAS::forceAuthentication PHP 메소드

forceAuthentication() 공개 정적인 메소드

This method is called to force authentication if the user was not already authenticated. If the user is not authenticated, halt by redirecting to the CAS server.
public static forceAuthentication ( ) : boolean
리턴 boolean Authentication
    public static function forceAuthentication()
    {
        phpCAS::traceBegin();
        phpCAS::_validateClientExists();
        $auth = self::$_PHPCAS_CLIENT->forceAuthentication();
        // store where the authentication has been checked and the result
        self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
        /*      if (!$auth) {
                 phpCAS :: trace('user is not authenticated, redirecting to the CAS server');
                self::$_PHPCAS_CLIENT->forceAuthentication();
                } else {
                phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)');
                }*/
        phpCAS::traceEnd();
        return $auth;
    }

Usage Example

예제 #1
0
function checkAndSetUserSession()
{
    // store session data
    if (!isset($_SESSION['user'])) {
        $_SESSION['user'] = null;
    }
    if (isset($_REQUEST['login']) or isset($_REQUEST['logout'])) {
        // initialize phpCAS
        phpCAS::client(CAS_VERSION_2_0, 'login.kth.se', 443, '');
        //phpCAS::proxy(CAS_VERSION_2_0,'login.kth.se',443,'');
        phpCAS::setNoCasServerValidation();
        // If you want the redirect back from the login server to enter your application by some
        // specfic URL rather than just back to the current request URI, call setFixedCallbackURL.
        //phpCAS::setFixedCallbackURL('http://xml.csc.kth.se/~wiiala/DM2517/project/php/index.php');
        // force CAS authentication
        phpCAS::forceAuthentication();
        // at this step, the user has been authenticated by the CAS server
        // and the user's login name can be read with phpCAS::getUser().
        $_SESSION['user'] = phpCAS::getUser();
        //Logga ut och redirecta till vår standardsida
        if (isset($_REQUEST['logout'])) {
            unset($_SESSION['user']);
            phpCAS::logoutWithRedirectService('http://kth.kribba.com/');
        }
    }
}
All Usage Examples Of phpCAS::forceAuthentication