Yale Cas Client开发实例
2012-07-13 17:27:31   来源:我爱运维网   评论:0 点击:

本文基于基于2种web编程语言:PHP/Python(Django),阐述Yale CAS(耶鲁大学集中认证服务)的客户应用开发实例。 下述2种语言Django和PHP...
本文基于基于2种web编程语言:PHP/Python(Django),阐述Yale CAS(耶鲁大学集中认证服务)的客户应用开发实例。 下述2种语言Django和PHP已成功验证CAS集中认证通过,以下是针对这2种语言的迁移方式。
 
目录:
一. Django应用的迁移: 
二. PHP应用,比如Zabbix的迁移
三. Java Client的支持
四. 其他Client的支持,如.net参见文档
 
一. Django应用的迁移:
  1. 如果web server用的是apache,那么可以安装mod_auth_cas模块来支持CAS, 详细配置方法见:https://wiki.jasig.org/display/CASC/mod_auth_ca​s。Apache会将验证后的用户名放在REMOTE_USER环境变量中,在Django里这个环境变量可以通过request.META['REMOTE_USER']访问到。 因此只要将Django的用用户认证方式同配置成Remote User Authentication即可。详细步骤和文档可以参考:https://docs.djangoproject.com/en/1.3/howto/auth-remote-user/​。 
  2. 也可以采用第三方开源的Django CAS客户端来实现,比如Tools的Event Console,是通过django-cas这个client来实现的,详细的django配置和编码方法见http://code.google.com/p/django-cas/​
二. PHP应用,比如Zabbix的迁移:
    官方提供的PHP客户端是phpCAS, https://wiki.jasig.org/display/CASC/phpCAS
    phpCAS官方有个比较简单的实例Example_advanced.php,通过CAS登录,并从server获取用户的属性,(实际环境可以通过http://zabbix.pplive.cn/zabbix/example_advanced.php 访问) ,示例代码如下:
// Advanced example for SAML with attributes and single logout
 
include_once('conf/cas_config.php');
// Load the CAS lib
include_once($phpcas_path.'/CAS.php');
 
// Uncomment to enable debugging
phpCAS::setDebug();
    
// Initialize phpCAS
phpCAS::client(SAML_VERSION_1_1, $cas_host, $cas_port, $cas_context);
    
// For production use set the CA certificate that is the issuer of the cert 
// on the CAS server and uncomment the line below
//phpCAS::setCasServerCACert($cas_server_ca_cert_path);
 
// For quick testing you can disable SSL validation of the CAS server. 
// THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION. 
// VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL! 
phpCAS::setNoCasServerValidation();
 
// Handle SAML logout requests that emanate from the CAS host exclusively.
// Failure to restrict SAML logout requests to authorized hosts could
// allow denial of service attacks where at the least the server is
// tied up parsing bogus XML messages.
phpCAS::handleLogoutRequests(true, $cas_real_hosts);
 
// Force CAS authentication on any page that includes this file
phpCAS::forceAuthentication();
 
 
// logout if desired
if (isset($_REQUEST['logout'])) {
        phpCAS::logout();
}
 
?>
<h2>Secure Page</h2>
<?php include 'script_info.php' ?>
 
Authentication succeeded for user
<strong><?php echo phpCAS::getUser(); ?></strong>.
 
<h3>User Attributes</h3>
<ul>
<?php
foreach (phpCAS::getAttributes() as $key => $value) {
if (is_array($value)) {
echo '<li>', $key, ':<ol>';
foreach($value as $item) {
      echo '<li><strong>', $item, '</strong></li>';
    }
echo '</ol></li>';
} else {
    echo '<li>', $key, ': <strong>', $value, '</strong></li>';
  }
}
?>
</ul>
 <p><a href="?logout=">Logout</a></p>​
 
 
三. Java Client的支持
    Java Client的集成方法和PHP等类似。可以通过filter的配置实现集成。以下链接是一个Saml11TicketValidationFilter的实现。此实例演示了如何通过CAS登录同时获取用户信息。
    请注意文档是基于3.1.3版本的jasig,集成时请把cas-client-core-3.1.3.jar升级到最新版本。
 
 
四. 其他Client的支持
    如.net参见文档

相关热词搜索:Yale CAS Client 开发

上一篇:CAS Server的部署手记
下一篇:最后一页

分享到: 收藏
评论排行