15.4. HTTPS 設定による EJB3 RMI
手順15.5 HTTPS による EJB3 RMI 設定の概要
これは SSL で暗号化された HTTP に Remote Method Invocation トラフィックのトンネリングを設定する手順です。これにはトラフィックを暗号化し、RMI ポートをブロックするファイアウォールをトラバースできるという 2 つの効果があります。
- 暗号化キーと証明書の生成
- HTTPS Web コネクタによる RMI の設定
- サーブレットの設定
- HTTPS による RMI のセキュアなリモートコネクタの設定
- HTTPS トランスポートに対する EJB3 Bean の設定
- HTTPS による RMI に対するクライアントの設定
暗号化キーと証明書の生成については 「暗号化キーと証明書の生成」 で取り上げています。
手順15.6 HTTPS Web コネクタによる RMI の設定
これは 8443 ポートでリッスンし、クライアントから SSL 接続を受け入れる Web コネクタを作成する手順です。
- ファイル
jboss-as/server/$PROFILE/deploy/jbossweb.sar/server.xmlを編集し、HTTPS コネクタを非コメントします。<!-- SSL/TLS Connector configuration using the admin devl guide keystore --> <Connector protocol="HTTP/1.1" SSLEnabled="true" port="8443" address="${jboss.bind.address}" scheme="https" secure="true" clientAuth="false" keystoreFile="${jboss.server.home.dir}/conf/localhost.keystore" keystorePass="KEYSTORE_PASSWORD" sslProtocol = "TLS" />
結果
Web コネクタを作成し、SSL 接続を受け入れます。
手順15.7 サーブレットの設定
これは Web コネクタから
ServletServerInvoker に要求を渡すサーブレットを設定する手順です。
jboss-as/server/$PROFILE/deploy/にservlet-invoker.warという名前のディレクトリを作成します。servlet-invoker.warディレクトリ内にWEB-INFディレクトリを作成します。- その
WEB-INFディレクトリに次の内容を含むweb.xmlという名前のファイルを作成します。<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>ServerInvokerServlet</servlet-name> <description>The ServerInvokerServlet receives requests via HTTP protocol from within a web container and passes it onto the ServletServerInvoker for processing. </description> <servlet-class>org.jboss.remoting.transport.servlet.web.ServerInvokerServlet</servlet-class> <init-param> <param-name>locatorUrl</param-name> <param-value>servlet://${jboss.bind.address}:8080/servlet-invoker/ServerInvokerServlet</param-value> <description>The servlet server invoker</description> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>SSLServerInvokerServlet</servlet-name> <description>The ServerInvokerServlet receives requests via HTTPS protocol from within a web container and passes it onto the ServletServerInvoker for processing. </description> <servlet-class>org.jboss.remoting.transport.servlet.web.ServerInvokerServlet</servlet-class> <init-param> <param-name>locatorUrl</param-name> <param-value>sslservlet://${jboss.bind.address}:8443/servlet-invoker/SSLServerInvokerServlet</param-value> <description>The servlet server invoker</description> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ServerInvokerServlet</servlet-name> <url-pattern>/ServerInvokerServlet/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>SSLServerInvokerServlet</servlet-name> <url-pattern>/SSLServerInvokerServlet/*</url-pattern> </servlet-mapping> </web-app>結果サーブレットを作成し、Web コンテナからサーバー invoker に SSL 要求を転送します。
locatorUrl を使用して、手順15.8「HTTPS による RMI のセキュアなリモートコネクタの設定」 で定義するリモートコネクタの InvokerLocator 属性を通じてサーブレットをリモートコネクタに接続します。
手順15.8 HTTPS による RMI のセキュアなリモートコネクタの設定
これは RMI を実装する Server Invoker を作成する手順です。
jboss-as/server/$PROFILE/deploy/に次の内容を含むservlet-invoker-service.xmlという名前のファイルを作成します。<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.jboss.remoting.transport.Connector" name="jboss.remoting:service=connector,transport=servlet" display-name="Servlet transport Connector"> <attribute name="InvokerLocator">servlet://${jboss.bind.address}:8080/servlet-invoker/ServerInvokerServlet</attribute> <attribute name="Configuration"> <handlers> <handler subsystem="AOP">org.jboss.aspects.remoting.AOPRemotingInvocationHandler</handler> </handlers> </attribute> </mbean> <mbean code="org.jboss.remoting.transport.Connector" name="jboss.remoting:service=connector,transport=sslservlet" display-name="Servlet transport Connector"> <attribute name="InvokerLocator">sslservlet://${jboss.bind.address}:8443/servlet-invoker/SSLServerInvokerServlet</attribute> <attribute name="Configuration"> <handlers> <handler subsystem="AOP">org.jboss.aspects.remoting.AOPRemotingInvocationHandler</handler> </handlers> </attribute> </mbean> </server>
結果
サーブレットからの要求を受け入れ、EJB3 のメソッドを呼び出すことができるリモートコネクタを作成します。
手順15.9 HTTPS トランスポートに対する EJB3 Bean の設定
これは HTTPS トランスポートにバインドする EJB3 を設定する手順です。
- HTTPS により RMI を使用するために Bean をアノテートする
例15.5 HTTPS により RMI を使用するために EJB3 をアノテートする
// RMI tunneled over HTTPS @Stateless @RemoteBinding(clientBindUrl = "https://0.0.0.0:8443/servlet-invoker/SSLServerInvokerServlet") @Remote(Calculator.class) @SecurityDomain("other") public class CalculatorHttpsBean implements Calculator { ....結果これで HTTPS によるリモート呼び出しに EJB3 が使用可能になりました。
HTTP により RMI を使用するために Bean をアノテートする
オプションとして、HTTP による RMI での呼び出しに Bean をアノテートすることができます。これは RMI ポートをブロックするファイアウォールを通じて RMI 呼び出しをトンネルできるためテストに役立ちますが、セキュリティ設定の別のレイヤを削除します。
例15.6 HTTP により RMI を使用するために Bean をアノテートする
// RMI tunneled over HTTP
@Stateless
@RemoteBinding(clientBindUrl = "http://0.0.0.0:8080/servlet-invoker/ServerInvokerServlet")
@Remote(Calculator.class)
@SecurityDomain("other")
public class CalculatorHttpBean extends CalculatorImpl
{
....
HTTPS による RMI に対するクライアントの設定
Bean を検索する場合、EJB クライアントは JNDI ルックアップに次のプロパティを使用するべきです。
HTTP(S) による RMI へのクライアントアクセス
- HTTPS
Properties props = new Properties(); props.put("java.naming.factory.initial", "org.jboss.naming.HttpNamingContextFactory"); props.put("java.naming.provider.url", "https://localhost:8443/invoker/JNDIFactory"); props.put("java.naming.factory.url.pkgs", "org.jboss.naming"); Context ctx = new InitialContext(props); props.put(Context.SECURITY_PRINCIPAL, username); props.put(Context.SECURITY_CREDENTIALS, password); Calculator calculator = (Calculator) ctx.lookup(jndiName); // use the bean to do any operations- HTTP
Properties props = new Properties(); props.put("java.naming.factory.initial", "org.jboss.naming.HttpNamingContextFactory"); props.put("java.naming.provider.url", "http://localhost:8080/invoker/JNDIFactory"); props.put("java.naming.factory.url.pkgs", "org.jboss.naming"); Context ctx = new InitialContext(props); props.put(Context.SECURITY_PRINCIPAL, username); props.put(Context.SECURITY_CREDENTIALS, password); Calculator calculator = (Calculator) ctx.lookup(jndiName); // use the bean to do any operations
HTTP(S) による RMI へのクライアントアクセス では、user name と password の値は http-invoker をセキュアにするために使用するセキュリティドメインの有効なユーザー名とパスワードに一致します。このセキュリティドメインは
jboss-as/$PROFILE/deploy/http-invoker.sar/invoker.war/WEB-INF/jboss-web.xml で設定されます。