Liberty でのセキュリティー入門
<quickStartSecurity> エレメントを使用して、Liberty の単純な (1 ユーザーの) セキュリティー・セットアップを迅速に使用可能にすることができます。
このタスクについて
基本的ないくつかの構成手順に従うことによって、保護された Liberty サーバーおよび Web アプリケーションをセットアップすることができます。Liberty 内での構成アクションは動的です。つまり、サーバーを再始動しなくても、構成の更新は有効になります。
手順
- サーバーを作成および始動します。
Windows システムの場合:
server.bat create MyNewServer server.bat start MyNewServer
Windows システム以外のすべてのシステムの場合:
server create MyNewServer server start MyNewServer
- server.xml ファイルで appSecurity-2.0 フィーチャーおよび servlet-3.0 フィーチャーを組み込みます。
server.xml ファイルは myNewServer のサーバー・ディレクトリーにあります (例えば、wlp¥usr¥servers¥myNewServer¥server.xml)。
<featureManager> <feature>appSecurity-2.0</feature> <feature>servlet-3.0</feature> </featureManager>
- サーバー管理アクティビティーのための Administrator ロールを付与するユーザー名およびパスワードを定義します。
<quickStartSecurity userName="Bob" userPassword="bobpwd" />
注: 自分にとって意味のあるユーザー名およびパスワードを選択してください。ご使用のアプリケーションで、例で示された名前およびパスワードを使用しないでください。 - Web リソースを保護するために関連セキュリティー制約を使用してデプロイメント記述子を構成します。例えば、<auth-constraint> エレメントおよび <role-name> エレメントを使用して、Web リソースにアクセスできるロールを定義します。 以下の web.xml ファイルの例では、アプリケーション内のすべての URI へのアクセスが、testing ロールで保護されています。
<?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 id="myWebApp"> <!-- SERVLET DEFINITIONS --> <servlet id="Default"> <servlet-name>myWebApp</servlet-name> <servlet-class>com.web.app.MyWebAppServlet</servlet-class> <load-on-startup/> </servlet> <!-- SERVLET MAPPINGS --> <servlet-mapping id="ServletMapping_Default"> <servlet-name>myWebApp</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <!-- SECURITY ROLES --> <security-role> <role-name>testing</role-name> </security-role> <!-- SECURITY CONSTRAINTS --> <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>testing</role-name> </auth-constraint> </security-constraint> <!-- AUTHENTICATION METHOD: Basic authentication --> <login-config> <auth-method>BASIC</auth-method> </login-config> </web-app>
- アプリケーションを server.xml ファイルで構成してください。 以下の例では、ユーザー Bob は、アプリケーションの testing ロールにマップされます。
<application type="war" id="myWebApp" name="myWebApp" location="${server.config.dir}/apps/myWebApp.war"> <application-bnd> <security-role name="testing"> <user name="Bob" /> </security-role> </application-bnd> </application>
- アプリケーションにアクセスして、ユーザー名 Bob でログインします。 myWebApp アプリケーションのデフォルト URL は http://localhost:9080/myWebApp です。
タスクの結果
サブトピック
- セキュリティーの簡単な概要
Liberty でのセキュリティーの基本的なワークフローを理解するために、例を使用しながら、いくつかの一般的なセキュリティー用語について説明します。 - 例: Liberty での BasicRegistry およびロール・マッピングの使用
基本ユーザー・レジストリーを使用してユーザーを認証および許可するように Liberty を構成できます。
親トピック: Liberty およびそのアプリケーションの保護

ファイル名: twlp_sec_quickstart.html