シングルサインオン認証のコンフィギュレーション

このタスクについて

Guidewire では、次のコンフィギュレーションが基本的な例として用意されています。この例に基づいて、エラー理由などに応じて異なるエラーページにユーザーを転送する機能のような、より複雑な認証機能を開発できます。

手順

  1. カスタムの Gosu クラス CustomAuthServlet.gs を作成します。
    1. ClaimCenter Guidewire Studio™ を開きます。
    2. Studio の[Project]ウィンドウで [configuration] > [gsrc]を展開します。
    3. [gsrc]を右クリックして、[新規作成] > [パッケージ]をクリックします。
    4. アップグレード用のパッケージ名を入力します。
      例えば、companyName.auth などの名前を入力します。
    5. 新しいパッケージを右クリックして、[新規] > [Gosu クラス]の順にクリックします。
    6. クラス名を「CustomAuthServlet」 と入力して、[OK] をクリックします。
    7. 次のクラス定義を入力します。
      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");
        }
      }
  2. カスタムサーブレットを有効な ClaimCenter サーブレットのリストに追加します。
    1. [configuration] > [コンフィギュレーション] > [サーブレット]を展開します。
    2. servlets.xml を開きます。
    3. カスタムサーブレットの名前をリストに追加します。
      次に例を示します。
      <servlet class="companyName.auth.CustomAuthServlet"/>
  3. カスタムの 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;
      }
    }
  4. カスタムの 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 をスローします。

  5. カスタムの AuthServicePlugin クラスを AuthenticationServicePlugin プラグインに関連付けます。
    1. [configuration] > [コンフィギュレーション] > [プラグイン] > [レジストリ]を展開します。
    2. AuthenticationServicePlugin.gwp を開きます。
    3. デフォルトのプラグインを削除するには、[プラグインの削除 をクリックします。
    4. プラグインの追加 をクリックして、[Gosu プラグインの追加]を選択します。
    5. Gosu クラス]に、完全修飾パッケージ名を含めた AuthServicePlugin.gs クラスを入力します。
  6. カスタムの AuthSourceCreator クラスを AuthenticationSourceCreatorPlugin プラグインに関連付けます。
    1. AuthenticationSourceCreatorPlugin.gwp を開きます。
    2. デフォルトのプラグインを削除するには、[プラグインの削除 をクリックします。
    3. プラグインの追加 をクリックして、[Gosu プラグインの追加]を選択します。
    4. [Gosu クラス]に、完全修飾パッケージ名を含めた AuthSourceCreator.gs クラスを入力します。
  7. ClaimCenter エントリページのエントリポイントを作成します。
    1. [configuration] > [コンフィギュレーション] > [ページコンフィギュレーション] > [PCF]の順に展開し、[entrypoints]を右クリックして、[新規作成] > [PCF ファイル]をクリックします。
    2. ファイル名に「ClaimCenterStartupPageEP」と入力します。
    3. ファイルの種類で[エントリポイント]を選択して、[OK]をクリックします。
    4. エントリポイントを選択します。
    5. [location]ClaimCenterStartupPage() に設定します。
    6. [authenticationRequired]false に設定します。
  8. デフォルトのエラーページのエントリポイントを作成します。
    1. [entrypoints]を右クリックして、[新規作成] > [PCF ファイル]をクリックします。
    2. ファイル名を「DefaultFailureEP」と入力します。
    3. ファイルの種類で[エントリポイント]を選択して、[OK]をクリックします。
    4. エントリポイントを選択します。
    5. [location]DefaultFailurePage() に設定します。
    6. [authenticationRequired]false に設定します。
  9. BaseURLBuilderPlugin プラグイン実装を作成します。
    1. [configuration] > [コンフィギュレーション] > [プラグイン] > [レジストリ]を右クリックして、[新規] > [プラグイン]をクリックします。
    2. 名前を「BaseURLBuilderPlugin」と入力します。
    3. インターフェイスを「IBaseURLBuilder」 と入力して、[OK] をクリックします。
    4. プラグインの追加 をクリックして、[JAVA プラグインの追加]を選択します。
    5. [Java クラス]に「com.guidewire.pl.web.render.html.BaseURLBuilderImpl」と入力します。
  10. 作業内容をテストします。
    1. ClaimCenter のローカルサーバーでテスト用の HTML ページを作成します。
    2. 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>