Axis2 は WS-Security への対応を、
WSS4Jを利用した
rampartモジュール により実現しています。
モジュールとすることで、WEBサービスのビジネスロジック内でWS-Securityの実装を
行うのではなく、モジュールの関連付け(エンゲージ)によりWS-Securityへの対応を
実現できるよう考えられています。
今回は、Axis2 1.0 の Standard Distribution に含まれる
WS-Securityを使ったサンプルを動かしてみます。
手順は axis2-std-1.0-bin.zipの中の、samples\security\README.txt
に従っています。
●サーバー側
1.Tomcatで環境構築
(Tomcat)/webapps/ にaxis2.war をコピーしてTomcatを再起動し、
Axis2の環境を作成しておきます。
2.rampart-1.0.marをダウンロード
Axis2のダウンロードサイトからダウンロードし、
(Tomcat)/webapps/axis2/WEB-INF/modules/ にコピーします。
3.rampartモジュールのエンゲージ
(Tomcat)/webapps/axis2/WEB-INF/conf/axis2.xmlを編集し、
<module ref="addressing"/> の下あたりに、
<module ref="rampart"/> を追加します。
4.サンプルのWEBサービスのデプロイ
axis2-std-1.0-bin.zipに含まれるsamples\security\SecureService.aar
を(Tomcat)/webapps/axis2/WEB-INF/services/ にコピーします。
このSecureService.aarの中身は次のような構造になってます。
SecureService/
|-META-INF/
| |-services.xml
|-sample/
| |-security/
| |-Client.class
| |-PWCallback.class パスワードコールバッククラス
| |-Service.class サーバー側サービスクラス
|-sec.jksキーストア
|-sec.properties キーについての情報定義
5.サーバー側で必要な jar をコピー
axis2-std-1.0-bin.zipに含まれるsamples\security\lib\ にある
secUtil.jar以外のjarを(Tomcat)/webapps/axis2/WEB-INF/lib/ にコピーします。
6.Tomcatを再起動
http://localhost:8080/axis2/services/listServices に
SecureServiceサービスが表示されていることを確認します。
●クライアント側
1.axis2-std-1.0-bin.zip を解凍しておきます。
ちなみにクライアント側はsecUtil.jarに含まれていて、以下のような構造になっています。
secUtil/
|-META-INF/
|-sample/
| |-security/
| |-Client.class クライアント側クラス
| |-PWCallback.class パスワードコールバッククラス
|-sec.jksキーストア
|-sec.properties キーについての情報定義
2.モジュールのコピー
サーバー側の設定で用意した
(Tomcat)/webapps/axis2/WEB-INF/modules/ にある
rampart-1.0.marとaddressing-1.0.marを、
samples\security\client_repo\modules\ にコピーします。
3.コマンドプロンプトを起動
samples\security に CD します。
環境変数 JAVA_HOME と ANT_HOME が設定されていることを確認します。
set JAVA_HOME=C:\j2sdk1.4.2_04
set ANT_HOME=C:\work\apache-ant-1.6.5
4.クライアントを実行
%ANT_HOME%\bin\ant とコマンドプロンプトから実行します。
C:\work\axis2-std-1.0-bin\samples\security>%ANT_HOME%\bin\ant
Buildfile: build.xml
securitySample:
[java] log4j:WARN No appenders could be found for logger (org.apache.axiom.om.impl.builder.StAXOMBuilder).
[java] log4j:WARN Please initialize the log4j system properly.
[java] Response: <example1:echo
xmlns:example1="http://example1.org/example1"
xmlns:tns="http://ws.apache.org/axis2"
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
xmlns:wsa="http://www.w3.org/2005/08/addressing"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<example1:Text>Axis2 Echo String </example1:Text></example1:echo>
[java] SecureService Invocation successful :-)
BUILD SUCCESSFUL
Total time: 10 seconds
C:\work\axis2-std-1.0-bin\samples\security>
という具合に呼び出しが成功しています:-)
サーバーからのレスポンスとして "Axis2 Echo String" の文字列が返ってきてますね。
●SOAPメッセージを覗いて見る
呼び出しが成功してるのは分かるのですが、どんなやり取りがなされたのか
全く分からないので TCPMON を使ってSOAPメッセージを覗いて見ます。
参考:
TCPMON 1.01.samples\security\build.xmlの変更(8080 → 8081)
クライアントのメッセージ送信先ポートを8081に変更します。
2.TCPMONを起動します。
リスンポートは8081にしておきます。

3.クライアントを実行してみます。
%ANT_HOME%\bin\ant
以下にリクエストとレスポンスのSOAPメッセージを示しますが、
SOAPヘッダー部分にセキュリティ関連の設定が含まれていることが分かります。
また、SOAPボディ部分が暗号化されていることが分かります。
・クライアントからのリクエストSOAPメッセージ
POST /axis2/services/SecureService HTTP/1.1
User-Agent: Axis/2.0
SOAPAction: urn:echo
Host: 127.0.0.1:8081
Transfer-Encoding: chunked
Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_62141C0BB72B68471611508916102811; type="application/xop+xml"; start="<0.urn:uuid:62141C0BB72B68471611508916102812@apache.org>"; start-info="text/xml"; charset=UTF-814b9--MIMEBoundaryurn_uuid_62141C0BB72B68471611508916102811content-type:application/xop+xml; charset=UTF-8; type="text/xml";content-transfer-encoding:binarycontent-id:
<0.urn:uuid:62141C0BB72B68471611508916102812@apache.org>
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<xenc:EncryptedKey Id="EncKeyId-9236202">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<wsse:SecurityTokenReference>
<wsse:KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier">Xeg55vRyK3ZhAEhEf+YT0z986L0=</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>j1lAMU9UCNlXOIHDQnI9ZOFdL39uil/gU2P3uZ8QjHzMmVHstrKyHbk80B7JpPBIFq+9t2A0TRjNFOTDzuSMqPsSwxd/NkKPRvIRTRjmDVlUFf3GwJl8b/DDqbMCPZnzmTnLOuvXSSt/b3KrKV6Da/XNeCEPAK9sgyqR3P2eNSc=</xenc:CipherValue>
</xenc:CipherData>
<xenc:ReferenceList>
<xenc:DataReference URI="#EncDataId-25254907" />
</xenc:ReferenceList>
</xenc:EncryptedKey>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="Signature-21307627">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#id-31365828">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>muLjiccep2ghfc9iDo2HVvAezhY=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#id-3686501">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>G2lJ0fUSEn+JOpQ/AmWVUszqrIU=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#id-17547166">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>+Ez0KNpYfSAgi/IPnsI0m74e75Q=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#Timestamp-4171180">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>BS3UmmNGyMsyx9Cy92sf+N2dCTs=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>OJiUcNsn/XIo1MzJQ2NS2W56QkNxG9BxgPIdoghHyxJATE38dgDi79MeWhPBxIXzH5ESSQw96jGaabJjZhMr+/sGkPi2DApb3EVDb9xCNQ+7b8m48y5kbpbwEcyAFK85Y4TI2J2qtwoGTuvuIIZBJmFn42llae1pAuE8U/OrS+E=</ds:SignatureValue>
<ds:KeyInfo Id="KeyId-23886295">
<wsse:SecurityTokenReference xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="STRId-23894119">
<wsse:KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier">CuJdE1B2dUFd1dkLZSzQ5vj6MYg=</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-4171180">
<wsu:Created>2006-06-21T12:06:48.390Z</wsu:Created>
<wsu:Expires>2006-06-21T12:11:48.390Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
<wsa:To xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-31365828">http://127.0.0.1:8081/axis2/services/SecureService</wsa:To>
<wsa:ReplyTo xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-3686501">
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
</wsa:ReplyTo>
<wsa:MessageID xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-17547166">urn:uuid:9645345AB9855D312C11508916079681</wsa:MessageID>
<wsa:Action>urn:echo</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<xenc:EncryptedData Id="EncDataId-25254907" Type="http://www.w3.org/2001/04/xmlenc#Content">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
<xenc:CipherData>
<xenc:CipherValue>EAwlUCWHg/itojJR315mhFKHAAi/hYvapRpOCsbl97sDiBREiLo9u+qPkTApE7BsyhUFs1TI9SAfo+6Gd5oyNd7pdkrKPDLLrUri+vsuMZk7AMMDnFBeYwErhAfpWc1l8hP7Rbt5bgbK1wswlFkl+vXRepRn0Z7sDgA+H+8sR60NP7Yh3Po54ztTqngRhYOnPtLh9NAl7UtudskBTaco1pz51zZp4qzi5pegeCK0NO3LDR4mYZitbEPM8RubkIRnR4p105CrHMHSGbqyZVwPsUsoOwGQIHhKwpzHI94K9T4VVKImO9OJScJENSZ2ewwbvPRSTxKV//Li4JshU3EEU/JUWU5CKJW4fkMtj00hiSDFhazqsk8XJVcUJ/G3leTZ0mQuW4UmmZV8IUkS5xjCwA==</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</soapenv:Body>
</soapenv:Envelope>3b--MIMEBoundaryurn_uuid_62141C0BB72B68471611508916102811--0
・サーバーからのレスポンスSOAPメッセージ
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=41E0A292084EA259747115B436920BA6; Path=/axis2
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 21 Jun 2006 12:06:50 GMT
Server: Apache-Coyote/1.1
143a
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<xenc:EncryptedKey Id="EncKeyId-2720472">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<wsse:SecurityTokenReference>
<wsse:KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier">CuJdE1B2dUFd1dkLZSzQ5vj6MYg=</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>aCfsWLSM5v2Pp1ZQs1U8XjoBIeYA7pWtGzQji7WlNOUXgxDEnLYt+gwpIAgKnSWhMTr3pIcrhK0U997NgRqWXLLyQmdk5hkFcQnr+gCFqmtnClgqvtvgNKF7iH30C4pP2bFcTm5LHCVP4RivNlyLR1WCYTiBz5iHVnyFD/bWb9k=</xenc:CipherValue>
</xenc:CipherData>
<xenc:ReferenceList>
<xenc:DataReference URI="#EncDataId-11604324" />
</xenc:ReferenceList>
</xenc:EncryptedKey>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="Signature-3259592">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#id-11604324">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>7TWvalebulcK10+Ag3mbEfKcKgQ=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#SigConf-22348634">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>56RKyV+SYa3L/bzrJyQBRB83Ttw=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>WQiLLBaxk29Edg2ndFQXu6svLzy5kNXvZA0JJHlPvMMRSSNE7jMp6ltY+vGT0oSNK3W11k0+mdWdBV6gWR+UE7jqY3OIt2bqHb8MIotUfudPOwax1QcxuHHzvZGyXe/tbWdbq/EOQwxNqlvFCdii877eYbmjGXUx8dfQpbSwOgI=</ds:SignatureValue>
<ds:KeyInfo Id="KeyId-23131583">
<wsse:SecurityTokenReference xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="STRId-10879377">
<wsse:KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier">Xeg55vRyK3ZhAEhEf+YT0z986L0=</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-5192610">
<wsu:Created>2006-06-21T12:06:50.796Z</wsu:Created>
<wsu:Expires>2006-06-21T12:11:50.796Z</wsu:Expires>
</wsu:Timestamp>
<wsse11:SignatureConfirmation xmlns:wsse11="http://docs.oasis-open.org/wss/2005/xx/oasis-2005xx-wss-wssecurity-secext-1.1.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" Value="OJiUcNsn/XIo1MzJQ2NS2W56QkNxG9BxgPIdoghHyxJATE38dgDi79MeWhPBxIXzH5ESSQw96jGaabJjZhMr+/sGkPi2DApb3EVDb9xCNQ+7b8m48y5kbpbwEcyAFK85Y4TI2J2qtwoGTuvuIIZBJmFn42llae1pAuE8U/OrS+E=" wsu:Id="SigConf-22348634" />
</wsse:Security>
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
</wsa:ReplyTo>
<wsa:From>
<wsa:Address>http://127.0.0.1:8081/axis2/services/SecureService</wsa:Address>
</wsa:From>
<wsa:FaultTo>
<wsa:Address>http://127.0.0.1:8081/axis2/services/SecureService</wsa:Address>
</wsa:FaultTo>
<wsa:MessageID>urn:uuid:B81F7243AB23762B9211508916107968</wsa:MessageID>
<wsa:Action>urn:echo</wsa:Action>
<wsa:RelatesTo wsa:RelationshipType="wsa:Reply">urn:uuid:9645345AB9855D312C11508916079681</wsa:RelatesTo>
</soapenv:Header>
<soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-11604324">
<xenc:EncryptedData Id="EncDataId-11604324" Type="http://www.w3.org/2001/04/xmlenc#Content">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
<xenc:CipherData>
<xenc:CipherValue>57kPXg4KURpGiGelxDitmxMp4uci5odCg8z8A5I7Jzcc2nf1S0hocm0qhexpZP/jfCuP0hvmvEIDfkBOH84V2CkpjomrKWe0QdsMl51qH9Q94IsFy0L+IBMmZQx/FIx9rmtNEY7KD3O1qtGLSkc8F2+0JC0qHgHaYBqZVCKwFQcikomlbCa/1b88zoJt5VhjcCMuX6E5M/qtudVBedVhp1EFDuD7VgZ9VdrvSGhfifb9Jga4M4z1APf7TZFCkDQUoVYFrkGtty+wZ8JEcUx0Lr8bj++b0Z9MYGAcl7h31xPSjwMzsbfsO8F6+SAwVbWB+GbBzfhJcgzv3ETT48H26sAw/mAXCPiQJ+OOz7DXjNsmvTykRImnUo/kYwRhW+7+E8LLqv4l1e/ntuA0UZXs10AOLm82oigDlujhYtYa0pjoIFxpMzGc9Pa98cF8er6qzdXtDl3x2T8Fuo6XPTAu6wchITWfqyZwwKn5Kmr+rvUcyMaWN+ImU3T6CU5U8xvA7JX6t2IrT8J/Hey5VIdBqz2/59usbNGww3BcCPCijlGqXTovw67vPzCluGdHONJF</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</soapenv:Body>
</soapenv:Envelope>0
今回はサンプルを動かして見ただけなので、もう少し掘り下げが必要です。