シングルサインオン認証のコンフィギュレーション
このタスクについて
Guidewire では、次のコンフィギュレーションが基本的な例として用意されています。この例に基づいて、エラー理由などに応じて異なるエラーページにユーザーを転送する機能のような、より複雑な認証機能を開発できます。
手順
-
カスタムの Gosu クラス CustomAuthServlet.gs を作成します。
- ClaimCenter Guidewire Studio™ を開きます。
- Studio の[Project]ウィンドウで [configuration] > [gsrc]を展開します。
- [gsrc]を右クリックして、[新規作成] > [パッケージ]をクリックします。
-
アップグレード用のパッケージ名を入力します。
例えば、companyName.auth などの名前を入力します。
- 新しいパッケージを右クリックして、[新規] > [Gosu クラス]の順にクリックします。
- クラス名を「CustomAuthServlet」 と入力して、[OK] をクリックします。
-
次のクラス定義を入力します。
package companyName.auth uses com.guidewire.pl.system.dependency.PLDependencies uses com.guidewire.pl.system.service.context.ServiceToken uses com.guidewire.pl.system.server.Version uses com.guidewire.pl.web.controller.WebServlet uses javax.servlet.http.HttpServletResponse uses javax.servlet.http.HttpServletRequest uses javax.servlet.http.HttpServlet uses gw.servlet.ServletUtils uses javax.security.auth.login.LoginException uses gw.servlet.Servlet uses gw.plugin.Plugins uses gw.plugin.baseurlbuilder.IBaseURLBuilder @Servlet( \ path : String ->path.matches( "/ssosaml" ) ) class CustomAuthServlet extends HttpServlet { override function doPost(req: HttpServletRequest, resp: HttpServletResponse) { var user:User = ServletUtils.getAuthenticatedUser(req, true); if (user != null) { redirectToIndex(req, resp); return; } // try to login try { PLDependencies.LoginManager.login(req); } catch (e : LoginException) { respondUnauthorized(req,resp); return; } var serviceToken:ServiceToken = PLDependencies.CommonDependencies.ServiceToken; if (serviceToken == null || !serviceToken.AuthenticatedUser) { respondUnauthorized(req,resp); } else { // store token req.getSession(false).setAttribute(WebServlet.SERVICE_TOKEN_SESSION_ATTR, serviceToken); redirectToIndex(req, resp); } return; } private function respondUnauthorized(req:HttpServletRequest, resp:HttpServletResponse) { print("User is unauthorized") redirectToError(req, resp); } private function redirectToIndex(req:HttpServletRequest, resp:HttpServletResponse) { print("User is authorized. Send to index page.") var plugin:IBaseURLBuilder = (IBaseURLBuilder) Plugins.get("BaseURLBuilderPlugin"); var ccStartupPageEP = "ClaimCenterStartupPageEP" resp.sendRedirect(plugin.getApplicationBaseURL(req) + "/" + ccStartupPageEP + ".do"); } private function redirectToError(req:HttpServletRequest, resp:HttpServletResponse) { print("User is unauthorized. Send to Default Failure page.") var plugin:IBaseURLBuilder = (IBaseURLBuilder) Plugins.get("BaseURLBuilderPlugin"); var defaultFailureEP = "DefaultFailureEP" resp.sendRedirect(plugin.getApplicationBaseURL(req) + "/" + defaultFailureEP + ".do"); } }
-
カスタムサーブレットを有効な ClaimCenter サーブレットのリストに追加します。
- [configuration] > [コンフィギュレーション] > [サーブレット]を展開します。
- servlets.xml を開きます。
-
カスタムサーブレットの名前をリストに追加します。次に例を示します。
<servlet class="companyName.auth.CustomAuthServlet"/>
-
カスタムの Gosu クラス AuthServicePlugin.gs を作成し、カスタム認証パッケージに配置します。例えば、次のように記述します。
package companyName.auth uses gw.plugin.security.AuthenticationServicePlugin uses gw.plugin.security.AuthenticationServicePluginCallbackHandler uses gw.plugin.security.AuthenticationSource uses gw.plugin.security.UserNamePasswordAuthenticationSource uses java.lang.IllegalArgumentException uses javax.security.auth.login.FailedLoginException class AuthServicePlugin implements AuthenticationServicePlugin { var _handler: AuthenticationServicePluginCallbackHandler; override function authenticate(p0: AuthenticationSource): String { if (p0 typeis UserNamePasswordAuthenticationSource == false) { throw new IllegalArgumentException("Authentication source type " + p0.getClass().getName() + "is not known to this plugin"); } var uNameSource:UserNamePasswordAuthenticationSource = (UserNamePasswordAuthenticationSource) p0 ; var username = uNameSource.Username; var userPublicId = _handler.findUser(username); if (userPublicId == null) { throw new FailedLoginException("Bad user name " + username);} return userPublicId; } override function setCallback(p0: AuthenticationServicePluginCallbackHandler) { _handler = p0; } }
-
カスタムの Gosu クラス AuthSourceCreator.gs を作成し、カスタム認証パッケージに配置します。例えば、次のように記述します。
package companyName.auth uses gw.plugin.security.AuthenticationSourceCreatorPlugin uses gw.plugin.security.AuthenticationSource uses javax.servlet.http.HttpServletRequest uses gw.plugin.security.UserNamePasswordAuthenticationSource class AuthSourceCreator implements AuthenticationSourceCreatorPlugin { override function createSourceFromHTTPRequest(p0: HttpServletRequest): AuthenticationSource { var source:AuthenticationSource; var userName:String = p0.getParameter ("username"); var password:String = p0.getParameter("password"); print("userName\t" + userName) print("password\t" + password) source = new UserNamePasswordAuthenticationSource(userName, password); return source; } }
コード内で、エラーチェックを行い、エラーがある場合は InvalidAuthenticationSourceData をスローします。
-
カスタムの AuthServicePlugin クラスを AuthenticationServicePlugin プラグインに関連付けます。
- [configuration] > [コンフィギュレーション] > [プラグイン] > [レジストリ]を展開します。
- AuthenticationServicePlugin.gwp を開きます。
- デフォルトのプラグインを削除するには、[プラグインの削除] をクリックします。
- [プラグインの追加] をクリックして、[Gosu プラグインの追加]を選択します。
- [Gosu クラス]に、完全修飾パッケージ名を含めた AuthServicePlugin.gs クラスを入力します。
-
カスタムの AuthSourceCreator クラスを AuthenticationSourceCreatorPlugin プラグインに関連付けます。
- AuthenticationSourceCreatorPlugin.gwp を開きます。
- デフォルトのプラグインを削除するには、[プラグインの削除] をクリックします。
- [プラグインの追加] をクリックして、[Gosu プラグインの追加]を選択します。
- [Gosu クラス]に、完全修飾パッケージ名を含めた AuthSourceCreator.gs クラスを入力します。
-
ClaimCenter エントリページのエントリポイントを作成します。
- [configuration] > [コンフィギュレーション] > [ページコンフィギュレーション] > [PCF]の順に展開し、[entrypoints]を右クリックして、[新規作成] > [PCF ファイル]をクリックします。
- ファイル名に「ClaimCenterStartupPageEP」と入力します。
- ファイルの種類で[エントリポイント]を選択して、[OK]をクリックします。
- エントリポイントを選択します。
-
[location]を
ClaimCenter
StartupPage()
に設定します。 -
[authenticationRequired] を
false
に設定します。
-
デフォルトのエラーページのエントリポイントを作成します。
- [entrypoints]を右クリックして、[新規作成] > [PCF ファイル]をクリックします。
- ファイル名を「DefaultFailureEP」と入力します。
- ファイルの種類で[エントリポイント]を選択して、[OK]をクリックします。
- エントリポイントを選択します。
- [location]を DefaultFailurePage() に設定します。
- [authenticationRequired] を false に設定します。
-
BaseURLBuilderPlugin プラグイン実装を作成します。
- [configuration] > [コンフィギュレーション] > [プラグイン] > [レジストリ]を右クリックして、[新規] > [プラグイン]をクリックします。
- 名前を「BaseURLBuilderPlugin」と入力します。
- インターフェイスを「IBaseURLBuilder」 と入力して、[OK] をクリックします。
- [プラグインの追加] をクリックして、[JAVA プラグインの追加]を選択します。
- [Java クラス]に「com.guidewire.pl.web.render.html.BaseURLBuilderImpl」と入力します。
-
作業内容をテストします。
- ClaimCenter のローカルサーバーでテスト用の HTML ページを作成します。
-
HTML ページに次のフォームを含めます。
<form name="input" action="http://localhost:8080/cc/service/ssosaml" method="post"> Username: <input type="text" name="username"> Password: <input type="text" name="password"> <input type="submit" value="Submit"> </form>