Configure single sign-on authentication
About this task
Guidewire provides the following configuration as a basic example. Use this example to develop more complicated authentication features, such as redirecting users to different failure pages depending on the failure reason and so forth.
Procedure
-
Create custom Gosu class CustomAuthServlet.gs:
- Open Guidewire Studio™ for PolicyCenter.
- In the Studio Project window, expand .
- Right-click gsrc and click .
-
Enter a package name for upgrade purposes.
For example, enter something such as companyName.auth.
- Right-click the newly created package and click .
- Enter CustomAuthServlet as the name for the class and click OK.
-
Enter the following class definition:
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 pcStartupPageEP = "PolicyCenterStartupPageEP" resp.sendRedirect(plugin.getApplicationBaseURL(req) + "/" + pcStartupPageEP + ".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"); } }
-
Add your custom servlet to the list of valid PolicyCenter servlets:
- Expand .
- Open servlets.xml.
-
Add the name of your custom servlet to the list.
For example:
<servlet class="companyName.auth.CustomAuthServlet"/>
-
Create custom Gosu class AuthServicePlugin.gs and place the class in your custom authentication package.
For example:
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; } } -
Create custom Gosu class AuthSourceCreator.gs and place the class in your custom authentication package.
For example:
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; } }In your code, check for errors and throw InvalidAuthenticationSourceData if there are errors.
-
Associate your custom AuthServicePlugin class with the AuthenticationServicePlugin plugin.
- Expand :
- Open AuthenticationServicePlugin.gwp.
-
Click Remove Plugin
to remove the default plugin. -
Click Add Plugin
and select Add Gosu Plugin. - For Gosu Class, enter the AuthServicePlugin.gs class, including the fully qualified package.
-
Associate your custom AuthSourceCreator class with the AuthenticationSourceCreatorPlugin plugin.
- Open AuthenticationSourceCreatorPlugin.gwp.
-
Click Remove Plugin
to remove the default plugin. -
Click Add Plugin
and select Add Gosu Plugin. - For Gosu Class, enter the AuthSourceCreator.gs class, including the fully qualified package.
-
Create an entry point for the PolicyCenter entry page:
- Expand , right-click entrypoints and click .
- Enter PolicyCenterStartupPageEP for the file name.
- Select Entry Point for the file type and click OK.
- Select the entry point.
-
Set location to
PolicyCenterStartupPage(). -
Set authenticationRequired to
false.
-
Create an entry point for the default failure page.
- Right-click entrypoints and click .
- Enter DefaultFailureEP for the file name.
- Select Entry Point for the file type and click OK.
- Select the entry point.
- Set location to DefaultFailurePage().
- Set authenticationRequired to false.
-
Create a BaseURLBuilderPlugin plugin implementation:
- Right-click and click .
- Enter BaseURLBuilderPlugin for the name.
- Enter IBaseURLBuilder for the interface and click OK.
-
Click Add Plugin
and select Add Java Plugin. - Enter com.guidewire.pl.web.render.html.BaseURLBuilderImpl for the Java Class.
-
Test your work:
- Create a test HTML page on your local PolicyCenter server.
-
Include the following form on the HTML page:
<form name="input" action="http://localhost:8180/pc/service/ssosaml" method="post"> Username: <input type="text" name="username"> Password: <input type="text" name="password"> <input type="submit" value="Submit"> </form>
