isAuthenticated() public method

This method is called to check if the user is authenticated (previously or by tickets given in the URL).
public isAuthenticated ( boolean $renew = false ) : true
$renew boolean true to force the authentication with the CAS server
return true when the user is authenticated. Also may redirect to the same URL without the ticket.
示例#1
0
 /**
  * Verify that phpCAS will successfully fetch name-value-style attributes:
  *
  * @return void
  */
 public function testNameValueAttributes()
 {
     // Set up our response.
     $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/serviceValidate');
     $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n    <cas:authenticationSuccess>\n        <cas:user>jsmith</cas:user>\n\n        <cas:attribute name='attraStyle' value='Name-Value' />\n        <cas:attribute name='surname' value='Smith' />\n        <cas:attribute name='givenName' value='John' />\n        <cas:attribute name='memberOf' value='CN=Staff,OU=Groups,DC=example,DC=edu' />\n        <cas:attribute name='memberOf' value='CN=Spanish Department,OU=Departments,OU=Groups,DC=example,DC=edu' />\n\n        <cas:proxyGrantingTicket>PGTIOU-84678-8a9d2sfa23casd</cas:proxyGrantingTicket>\n    </cas:authenticationSuccess>\n</cas:serviceResponse>\n");
     CAS_TestHarness_DummyRequest::addResponse($response);
     $this->object->setTicket('ST-123456-asdfasdfasgww2323radf3');
     $this->object->isAuthenticated();
     // Verify that we have attributes from this response
     $attras = $this->object->getAttributes();
     $this->assertTrue($this->object->hasAttribute('attraStyle'), "Should have an attraStyle attribute");
     // direct access
     $this->assertEquals('Name-Value', $this->object->getAttribute('attraStyle'));
     // array access
     $this->assertArrayHasKey('attraStyle', $attras);
     $this->assertEquals('Name-Value', $attras['attraStyle']);
     $this->validateUserAttributes();
 }
示例#2
0
文件: CAS.php 项目: DCUnit711/Demeter
 /**
  * This method is called to check if the user is authenticated (previously or by
  * tickets given in the URL).
  *
  * @return true when the user is authenticated.
  */
 public static function isAuthenticated()
 {
     phpCAS::traceBegin();
     phpCAS::_validateClientExists();
     // call the isAuthenticated method of the $_PHPCAS_CLIENT object
     $auth = self::$_PHPCAS_CLIENT->isAuthenticated();
     // store where the authentication has been checked and the result
     self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
     phpCAS::traceEnd($auth);
     return $auth;
 }