配置CAS客户端(php 客户端 )

来源:互联网 发布:福昕阅读器mac中文版 编辑:程序博客网 时间:2024/06/07 18:46
配置CAS客户端(php 客户端 )



Php客户端配置相当简单,你只需把php客户端包解压至服务器根目录下, cas 的php 客户端就配置好了。


phpCAS requirements


Webserver

Any webserver like Apache, IIS and others should work.

CURL (7.5+)

CURL libs must be present on your system, and they must have been compiled with SSL support.

PHP >= 5.0 (PHP >= 4.2.2 for 1.1.x)

phpCAS users must have PHP compiled with the following options:

  • --with-curl: CURL support, needed to access proxies.
  • --with-openssl: SSL support, needed for fopen('https://...'), to validate CAS tickets;
  • --with-dom: DOM support, to read the XML responses of the CAS server (PHP4);
  • --with-zlib: Zlib support, needed by DOM.

我们来测试一下这个php的cas 客户端是否起作用。
修改php客户端自带的一个示例:example_simple.php,并拷贝到根目录目录中。
(实例文件路径在/cas/docs/example/下,你也可以多试几个)
代码修改如下:

<?php
// phpCAS simple client
// import phpCAS lib

include_once(‘CAS.php’);
phpCAS::setDebug();

// initialize phpCAS

phpCAS::client(CAS_VERSION_2_0,’localhost’,8443,’cas’);

// 参数说明

//CAS_VERSION_2_0版本,一般不用变

// ‘localhost’ 可以改成你的服务器端域名,注意是cas服务器端

// 8443  服务器端 端口号
//cas   就是文件夹名,同样是服务器端那个,自行修改

// no SSL validation for the CAS server

phpCAS::setNoCasServerValidation();

// 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().
// logout if desired

if (isset($_REQUEST['logout'])) {
phpCAS::logout();
}
// for this test, simply print that the authentication was successfull
?>
<html>

<head>
<title>phpCAS simple client</title>
</head>
<body>
<h1>Successfull Authentication!</h1>
<p>the user’s login is <b><?php echo phpCAS::getUser(); ?></b>.</p>
<p>phpCAS version is <b><?php echo phpCAS::getVersion(); ?></b>.</p>
<p><a href=”?logout=”>Logout</a></p>
</body>
</html>

红色为修改添加部分。

测试:

1) 访问http://localhost/ example_simple.php

2) Cas检测到用户没有登录,转向:

https://localhost:8443/cas/login?service=http%3A%2F%2Flocalhost%2Fexample_simple.php 登录界面。

3) 在登录界面输入admin/admin 用户名和密码。(之前没有注释掉)

4) 登录成功,转回http://localhost/ example_simple.php,并显示有关信息。


原创粉丝点击