ClientConfiguratorFilter.java revision 4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1c
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: ClientConfiguratorFilter.java,v 1.7 2009/12/05 02:33:36 222713 Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This filter brings user to a configuration page when client sample WAR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is not configured yeti, it will set the configuration properties if
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the WAR is already configured.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic final class ClientConfiguratorFilter implements Filter {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // see if the configure.jsp page is executed
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static boolean isConfigured = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String SETUP_URI = "/Configurator.jsp";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private boolean passThrough = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Redirects request to configuration page if the product is not yet
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * configured.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param request Servlet Request.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param response Servlet Response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param filterChain Filter Chain.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws ServletException if there are errors in the servlet space.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster HttpServletRequest httpRequest = (HttpServletRequest) request;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster HttpServletResponse httpResponse = (HttpServletResponse) response ;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // pass through on Configurator page
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (httpRequest.getRequestURI().endsWith(SETUP_URI)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster filterChain.doFilter(httpRequest, httpResponse);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster filterChain.doFilter(httpRequest, httpResponse);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (!isConfigured) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster filterChain.doFilter(httpRequest, httpResponse);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ServletException("ClientConfiguratorFilter.doFilter", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Destroy the filter config on sever shutdowm
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void destroy() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Initializes the filter.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param filterConfig Filter Configuration.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void init(FilterConfig filterConfig) throws ServletException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster configFile = System.getProperty("openssoclient.config.folder");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (configFile == null || configFile.length() == 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupClientWARSamples.CLIENT_WAR_CONFIG_TOP_DIR + File.separator +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupClientWARSamples.getNormalizedRealPath(servletCtx) +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Initializes the filter configuration.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param fconfig Filter Configuration.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setFilterConfig(FilterConfig fconfig) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets properties from AMConfig.properties
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param configFile path to the AMConfig.properties file
throws ServletException {
isConfigured = true;