CAS単点登録テスト環境構築手順

7380 ワード

From:
http://wangyaodi.javaeye.com/blog/294172
実験の目的:
A.        casとphpアプリケーションクライアントの接続性を検証する
B.        casとjavaアプリケーションクライアントの接続性を検証する
C.        javaクライアントからphpクライアントに接続し、セッションの連続性を検証する。
1.       必要なソフトウェアをダウンロードします。
Tomcat:apache-tomcat-5.5.5.27 windowsインストールバッグ。Tomcatはapacheのサイトでダウンロードできます。
以下のCAS関連ソフトは行けます。http://www.ja-sig.org/products/cas/downloads/index.html ダウンロードします
CAS server端:cas-server-3.3-release.zip
CAS phpクライアント:CAS-1.0.1.tgz
CAS javaクライアント:cas-client-2.21.zip
2.       phpとtomcatの運行環境を構築します。
私はアプリServ V.2.50を使ってPHPの運行環境をインストールしています。この集積環境はとても便利で、使いやすいです。
Tomcatのインストールはもっと簡単で、直接解凍版を使って、jdkのインストールはもちろん必要です。ここで疲れません。
ここでは、読者が正常にphpとtomcatの運行環境をインストールできると仮定します。
3.       CASサーバーを設定します。
a.       CASサーバ側にHTTPS証明書を作成して登録します。
  次のスクリプトを実行します。
keytool -delete -alias tomcatsso -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -storepass changeit 

keytool -delete -alias tomcatsso -storepass changeit 

rem keytool -list -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -storepass changeit 

keytool -genkey -keyalg RSA -alias tomcatsso -dname "CN=localhost" -storepass changeit 

keytool -export -alias tomcatsso -file "%JAVA_HOME%/jre/lib/security/tomcatsso.crt" -storepass changeit 

keytool -import -alias tomcatsso -file "%JAVA_HOME%/jre/lib/security/tomcatsso.crt" -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -storepass changeit
説明:keyを生成する過程で、「CN=local host」のlocal hostはServer端のドメイン名である。もちろん他のものに変えてもいいです。あなたの応用によって違います。
b.       Tomcatを配置したHTTPSサービス
コピーC:\Dockments and Settings\Administrator\.keystorはtomcatのconfディレクトリの下にあります。
server.xmlを修正し、sslのコメントを削除し、次のような設定に変更します。
<Connector port="8443" maxHttpHeaderSize="8192" keystorePass="changeit" keystoreFile="conf/.keystore"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" disableUploadTimeout="true"
               acceptCount="100" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
注意: 
C:\Dcuments and Settings\Administra\.keystoteと%tomcat_を維持してください。home%\conf\.keystore一致
cas.warをwebappに拷問する  目次の中で、そしてtomcatを起動して、保証します。http://localhost:8080/cas アクセスできます
admin/adminで例示プログラムを登録し、ログイン成功を表示するとcasサーバの配置が成功したことを示します。
4.       PHP casクライアントテストプログラムを設定します。
CAS-1.0.1.tgzを解圧して、CASディレクトリとCAS.phpをC:\AppServ\www(AppServデフォルトのインストールテーブルの中のwwwディレクトリ)に拷問します。
これでcasのphpクライアントが配置されます。
このphpのcasクライアントが機能するかどうかをテストします。
phpクライアントが自分で持っている例を修正します。example_simple.phpをwwwディレクトリにコピーします。 
コードの修正は以下の通りです。
<?php
//
// phpCAS simple client
//

// import phpCAS lib
include_once('CAS.php');

phpCAS::setDebug();

// initialize phpCAS
phpCAS::client(CAS_VERSION_2_0,'localhost',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="http://localhost:8080/ssodemo/ssojavaclient.jsp"> java     </a></p>
    <p><a href="?logout=">Logout</a></p>
  </body>
</html>
赤は修正の追加部分です。
テスト:
1)       アクセスhttp://localhost/ example_シンプル.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と関連情報を表示します。
5.       casのJavaクライアントを設定します。
ssodemoのwebappアプリケーションを作成します。
そのweb.xmlを設定:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">
    <description>
      JSP 2.0 Examples.
    </description>
    <display-name>JSP 2.0 Examples</display-name>
<filter> <filter-name>CAS Filter</filter-name>
<filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class>   
<init-param>      
         <param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name>      
         <param-value>https://localhost:8443/cas/login</param-value>   
</init-param>  
 <init-param>      
 <param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name>      
 <param-value>https://localhost:8443/cas/serviceValidate</param-value>   
 </init-param>   
 <init-param>      
 <param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name>      
 <param-value>localhost:8080</param-value>   
 </init-param>
 </filter> 
<filter-mapping>   
          <filter-name>CAS Filter</filter-name>   
          <url-pattern>/*</url-pattern>
</filter-mapping>