Create: 2014/02/22
LastUpdate: 2014/02/22
≪ メニューに戻るLastUpdate: 2014/02/22
ここでは、OpenAMのテスト環境を構築したときの手順の一部を紹介します。
テスト環境の概要は、メニューを参照してください。
OpenAMにログイン(SSO)することで、「テスト用WEBサイト」も認証済みとなり、ヒトがログイン操作しなくてもページを参照できるようにようにします。
リバースプロキシサーバには、OpenAMのPolicyAgentを導入して、OpenAMと連携して動くようにします。
PolicyAgentがOpenAMに問い合わせを行い、認証済みであれば、WEBサーバのアクセスを許可し、未認証であれば、OpenAMのログイン画面を表示します。
システム構成のイメージは以下のとおり。
OpenAMサーバは CentIS6.4 + Tomcat6 + OpenAM とします。

ユーザ端末:192.168.1.91
OpenAMサーバ:192.168.1.92
リバースプロキシサーバ:192.168.1.93
WEBサーバ:192.168.1.94
環境構築と動作確認の手順は、以下のとおり。
- OpenAMサーバの構築( CentIS6.4 + Tomcat6 + OpenAM)
- OpenAMの設定
- リバースプロキシサーバにOpenAMのPolicyAgentを導入
- 動作確認
3.リバースプロキシサーバにOpenAMのPolicyAgent を導入
「http://www.la-j.com/tech-blog/?p=703」の手順を参考にして、リバースプロキシサーバに Tomcat6 用のPolicyAgent をインストールしようとしたのですが、CentOS6 の yum でインストールした Tomcat6 にはインストールできませんでした。
Apache のサイトからダウンロードした Tomcat6 には、PolicyAgent をインストールできたので、CentOS6のTomcat6 に PlicyAgent を導入したい場合は、何か小細工が必要なようです。
今回は、CentOS6のTomcat6 を使いたいのですが、調べるのが面倒なので、CentOS6のTomcat6 にPolicyAgent を導入するのはあきらめて、ApcheとTomcat6 を連携するようにして、ApacheにOpenAMのPolicyAgent を導入することにしました。
3.1.Apache + Tomcat の連携
リバースプロキシサーバに Apache をインストールして、Apacheで受けたリクエストをTomcat6 に流すようにします。
リバースプロキシサーバの Tomcat6 は、80ポートでリクエストを受け付けるように iptables で NAT するよう設定していましたが、Apache と連携するので NATするのをやめます。
# service iptables stop # service iptables save # chkconfig iptables offApache をインストールします。
# yum install httpdTomcat と連携するために mod_proxy_ajp モジュールを使用します。このモジュールはデフォルトで使用できるようになっているので、Apacheの80ポートで受けたリクエストをTomcatの8009ポートに渡す設定をします。
Apache の設定ファイル /etc/httpd/conf.d/tomcat.conf を新規作成して、以下の内容を記述します。
<Location /> ProxyPass ajp://localhost:8009/ </Location>Tomcatの8080ポートは、今回のOpenAMの動作確認には、影響しないので、そのまま使用可能にしておきます。
Tomcat の8080 ポートを使用不可にしたい場合は、/etc/tomcat6/server.xml の8080ポート設定部分を以下のようにコメントアウトします。
<!-- <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" proxyPort="80" /> -->Apache を起動して、自動起動/停止を設定します。
# service httpd start # chkconfig httpd onリバースプロキシサーバ上で動作確認します。
curl コマンドで apache にアクセスして、以下のようなレスポンスがあればOKです。
# curl http://localhost <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>DEMO TOP</title> </head> <body> <h1>DEMO TOP</h1> <ul> <li><a href="demo1/">BASIC認証ページ</a> <li><a href="demo2/">フォーム認証ページ</a> </ul> </body> </html>
3.2.Apache2.2用のPolicyAgent 導入
OpenAMのPolicyAgent(Apache2.2用) をインストールします。
PolicyAgent のインストールには、Oracle JDK1.6 が必要です。OpracleJDK1.6 はインストール済みなので、root ユーザの環境変数を変更して、Oracle JDK1.6 を使用するようにします。
/root/.bashrc に以下を追加します。
# JAVA JAVA_HOME=/usr/java/default PATH=${JAVA_HOME}/bin:${PATH}変更内容を反映して、java のバージョンを確認します。
# . ~/.bashrc # java -version java version "1.6.0_45" Java(TM) SE Runtime Environment (build 1.6.0_45-b06) Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)PolicyAgentインストール時に、OpenAMサーバにFQDNでアクセスしますが、今回はDNSを用意していないので、/etc/hosts に、OpenAMサーバを追加しておきます。
OpenAMサーバにアクセスできない場合は、警告メッセージがでますが、PolicyAgent のインストールはできるようです。
192.168.1.92 exam01.example.com次は、ForgeRock 社のコミュニティサイトからPolicyAgent をダウンロードします。
ブラウザで以下のURLにアクセスします。
下図の画面が表示されたら、[AgentType]は “Apache2.2" 、[Operating System Type]は、”Linux"、[32/64 bits ] は、”32 bits" (※OS)を選択して [Download]ボタンをクリックします。

ダウンロードしたファイルをリバースプロキシサーバの/opt にアップして、解凍します。
# cd /opt # unzip apache_v22_Linux_agent_304.zipPolicyAgent に設定するパスワードをテキストファイルに格納します。
このパスワードは、OpenAM管理画面で設定したものです。
# echo -n "password" > /opt/pass.txtPolicyAgent のインストーラを起動します。
赤字部分が入力箇所です。
# cd /opt/web_agents/apache22_agent/bin # ./agentadmin --install Please read the following License Agreement carefully: [Press <Enter> to continue...] or [Enter n To Finish] n Do you completely agree with all the terms and conditions of this License Agreement (yes/no): [no]: yes ************************************************************************ Welcome to the OpenSSO Policy Agent for Apache Server. ************************************************************************ Enter the complete path to the directory which is used by Apache Server to store its configuration Files. This directory uniquely identifies the Apache Server instance that is secured by this Agent. [ ? : Help, ! : Exit ] Enter the Apache Server Config Directory Path [/opt/apache22/conf]: /etc/httpd/conf Enter the URL where the OpenSSO server is running. Please include the deployment URI also as shown below: (http://opensso.sample.com:58080/opensso) [ ? : Help, < : Back, ! : Exit ] OpenSSO server URL: http://exam01.example.com:8080/openam Enter the Agent URL as shown below: (http://agent1.sample.com:1234) [ ? : Help, < : Back, ! : Exit ] Agent URL: http://exig01.example.com:80 Enter the Agent profile name [ ? : Help, < : Back, ! : Exit ] Enter the Agent Profile name: apache22-exig01 Enter the path to a file that contains the password to be used for identifying the Agent. [ ? : Help, < : Back, ! : Exit ] Enter the path to the password file: /opt/pass.txt WARNING: Agent profile/User: apache22-exig01 does not exist in OpenSSO server! Either "Hit the Back button, and re-enter the correct agent profile name/user name", or "Create this agent profile when asked(available only in custom-install)", or "Continue without validating it because agent profile is in sub realm", or "Continue without validating/creating it, and manually validate/create it in OpenSSO server after installation". ----------------------------------------------- SUMMARY OF YOUR RESPONSES ----------------------------------------------- Apache Server Config Directory : /etc/httpd/conf OpenSSO server URL : http://exam01.example.com:8080/openam Agent URL : http://exig01.example.com:80 Agent Profile name : apache22-exig01 Agent Profile Password file name : /opt/pass.txt Verify your settings above and decide from the choices below. 1. Continue with Installation 2. Back to the last interaction 3. Start Over 4. Exit Please make your selection [1]: <ENTER> Creating directory layout and configuring Agent file for Agent_001 instance ...DONE. Reading data from file /opt/pass.txt and encrypting it ...DONE. Generating audit log file name ...DONE. Creating tag swapped OpenSSOAgentBootstrap.properties file for instance Agent_001 ...DONE. Creating a backup for file /etc/httpd/conf/httpd.conf ...DONE. Adding Agent parameters to /opt/web_agents/apache22_agent/Agent_001/config/dsame.conf file ...DONE. Adding Agent parameters to /etc/httpd/conf/httpd.conf file ...DONE. SUMMARY OF AGENT INSTALLATION ----------------------------- Agent instance name: Agent_001 Agent Bootstrap file location: /opt/web_agents/apache22_agent/Agent_001/config/OpenSSOAgentBootstrap.properties Agent Configuration Tag file location /opt/web_agents/apache22_agent/Agent_001/config/OpenSSOAgentConfiguration.properties Agent Audit directory location: /opt/web_agents/apache22_agent/Agent_001/logs/audit Agent Debug directory location: /opt/web_agents/apache22_agent/Agent_001/logs/debug Install log file location: /opt/web_agents/apache22_agent/installer-logs/audit/install.log Thank you for using OpenSSO Policy Agent以上で /opt/web_agents/apache22_agent/Agent_001 にPolicyAgent がインストールされます。
このディレクトリに設定ファイル、ログファイルが格納されます。
デフォルトでは、最上位のレルムを使用するように設定されているので、レルムの “test01” を使用するように、PolicyAgent の設定ファイル /opt/web_agents/apache22_agent/Agent_001/config/OpenSSOAgentBootstrap.propertiesを修正します。
com.sun.identity.agents.config.organization.name = test01apache を再起動します。
# service httpd restartPolicyAgent のログには以下のように表示されます。
# tail /opt/web_agents/apache22_agent/Agent_001/logs/debug/amAgent 2014-02-09 13:14:26.011 -1 16516:2341320 all: ======================================= 2014-02-09 13:14:26.011 -1 16516:2341320 all: Version: 3.0-04 2014-02-09 13:14:26.011 -1 16516:2341320 all: 2014-02-09 13:14:26.012 -1 16516:2341320 all: Build Date: Fri Jul 29 00:02:11 BST 2011 2014-02-09 13:14:26.012 -1 16516:2341320 all: Build Machine: constable.internal.forgerock.com 2014-02-09 13:14:26.012 -1 16516:2341320 all: =======================================
■補足
- PolicyAgentをアンインストールしたい場合は、"./agentadmin –uninstall" を実行します。
- PolicyAgent のインストールをCtrl+Cで中止すると、ロックファイルが残留して、再実行したときにエラーになります。
- ロックファイルは、/opt/web_agents/apache22_agent ディレクトリに作成されるので、ロックファイルを削除すれば再実行できるようになります。
3.3.PolicyAgent+OpenIGの連携
OpenIGの設定を変更して、HTTPヘッダからユーザIDとパスワードを取得するように設定します。
また、HTTPヘッダのpwd1 に設定されているパスワードは暗号化されているので、複合化するように設定します。
/usr/share/tomcat6/.ForgeRock/OpenIG/config/json を以下のように修正します。(赤字部分)
{ "heap": { "objects": [ { "name": "HandlerServlet", "type": "HandlerServlet", "config": { "handler": "DispatchHandler", "baseURI": "http://192.168.1.94:80" } }, { "name": "DispatchHandler", "type": "DispatchHandler", "config": { "bindings": [ { "condition": "${matches(exchange.request.uri.path,'^/demo1/.*') != null}", "handler": "LoginChain1", }, { "condition": "${exchange.request.uri.path == '/demo2/logon.php'}", "handler": "LoginChain2", }, { "handler": "OutgoingChain", } ] } }, { "name": "CryptoHeaderFilter", "type": "CryptoHeaderFilter", "config": { "messageType":"REQUEST", "operation":"DECRYPT", "algorithm":"DES/ECB/NoPadding", "key":"nYnQ9E/BlIo=", "keyType":"DES", "charSet":"utf-8", "headers": ["pwd1"], } }, { "name": "LoginChain1", "type": "Chain", "config": { "filters": ["CryptoHeaderFilter","ApacheAuthenticator"], "handler": "OutgoingChain" } }, { "name": "ApacheAuthenticator", "type": "HttpBasicAuthFilter", "config": { "username": "${exchange.request.headers['username'][0]}", "password": "${exchange.request.headers['pwd1'][0]}", "failureHandler": "OutgoingChain" } }, { "name": "LoginChain2", "type": "Chain", "config": { "filters": ["LoginRequestFilter2"], "handler": "OutgoingChain" } }, { "name": "LoginRequestFilter2", "type": "StaticRequestFilter", "config": { "method": "POST", "uri": "http://192.168.1.94:80/demo2/logon.php", "form": { "id": ["${exchange.request.headers['username'][0]}"], "pwd": ["${exchange.request.headers['pwd2'][0]}"], "login": ["login"], } } }, { "name": "OutgoingChain", "type": "Chain", "config": { "filters": ["CaptureFilter"], "handler": "ClientHandler" } }, { "name": "CaptureFilter", "type": "CaptureFilter", "config": { "captureEntity": true, "file": "/tmp/gateway.log" } }, { "name": "ClientHandler", "type": "ClientHandler", "config": { } } ] }, "servletObject": "HandlerServlet" }新しく、"CryptoHeaderFilter" を作成してHTTPヘッダ(pwd1) を複合化しています。パラメータのkey で設定しているのが上記2.8で設定した複合化キーです。
BASIC認証用の"ApacheAuthenticator" の前に、"CryptoHeaderFilter" を実施するように設定しています。
設定ファイルの修正が完了したら OpenIG を再起動します。
# service tomcat6 restart
■参考URL