LoginSignup
7
6

More than 5 years have passed since last update.

CASサーバを設定する

Posted at

調査したけどお蔵入りになったので、他の人のために書いとく。

CASとは

CASとはシングルサインオンの実装の一つである。SAMLはXMLを使い、認証されたサイトを示すが、CASはブラウザのCookieを使って認証を行う。おおむね、認証を実行するCAS Serverと認証の対象であるCAS Clientに役割が分かれる。CAS ClientはClientとは言えほとんどの場合アプリケーションサーバであると思う。

  • 利点
    • SAML実装がなくてもシングルサインオンできる
    • 複数アプリケーションのログイン処理をまとめられる

2つ目の用途に関してはJOSSOという別のライブラリもある

シーケンス

  • CAS Clientはブラウザから認証要求があるとCAS Serverにユーザーをリダイレクトする
    • この際CAS ClientのURLをserviceというクエリでCAS Serverに送る
  • ユーザーはCAS Serverでid/passを打ち込み認証する
    • この時CAS Serverが使うユーザー情報はJDBCやLDAPから取得できる(設定はXML)
  • CAS Serverが認証OKならば、もう一度ユーザーはリダイレクトされ、対象のCAS Clientに送られる

前提としてCAS ClientはCAS Serverの位置を知っておかなければならない
ここまでの話は名古屋大学の方が公開しているスライドが詳しい

CAS 3.6.0でCASサーバを立ててみる

構成は以下のドキュメントを参考にした

個人ブログでは以下が参考になった

CASのサーバアプリ自体はビルド済みのもの cas-server-webapp をMavenで取得し、ユーザー情報(ID/Pass)についてはJDBCでデータベース(MySQL)を見に行くというものだ。

ディレクトリ構成とファイル

pom.xml
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd ">

    <modelVersion>4.0.0</modelVersion>
    <groupId>j.guile.hangedman</groupId>
    <artifactId>cas</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cas.version>3.6.0</cas.version>
        <jetty.version>9.3.6.v20151106</jetty.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <warName>${artifactId}</warName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <webApp>
                        <contextPath>/cas</contextPath>
                    </webApp>
                    <httpConnector>
                        <port>8080</port>
                    </httpConnector>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.2</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.jasig.cas</groupId>
            <artifactId>cas-server-support-generic</artifactId>
            <version>${cas.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.jasig.cas</groupId>
            <artifactId>cas-server-support-jdbc</artifactId>
            <version>${cas.version}</version>
            <scope>runtime</scope>
        </dependency>
           <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.6.6</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.6.6</version>
            </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.18</version>
        </dependency>
        <dependency>
            <groupId>org.jasig.cas</groupId>
            <artifactId>cas-server-webapp</artifactId>
            <version>${cas.version}</version>
            <scope>runtime</scope>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>mvnrepository</id>
            <url>https://mvnrepository.com/artifact/</url>
        </repository>
    </repositories>
</project>

とりあえず上記だけでも動くCASサーバが構築できるので、あとは下の構成のように
cas.propertiesdeployerConfigContext.xml を設定するとよい。

$ tree
.
├── pom.xml
├── README.md
└── src
    └── main
        └── webapp
            └── WEB-INF
                ├── cas.properties
                └── deployerConfigContext.xml

4 directories, 4 files
  • deployerConfigContext.xml のサンプル
  <!-- MySQL connector -->
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    p:driverClass="com.mysql.jdbc.Driver"
    p:jdbcUrl="jdbc:mysql://localhost:3306/myschema"
    p:user="scott"
    p:password="password"/>
  • cas.properties は上書きしたい場合は作成すること

  • ビルドして実行

$ mvn package
$ mvn jetty:run
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6