001    //$HeadURL: svn+ssh://developername@svn.wald.intevation.org/deegree/base/trunk/resources/eclipse/files_template.xml $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005     - Department of Geography, University of Bonn -
006     and
007     - lat/lon GmbH -
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035     ----------------------------------------------------------------------------*/
036    package org.deegree.portal.cataloguemanager.servlet;
037    
038    import java.io.FileInputStream;
039    
040    import java.io.IOException;
041    import java.util.Properties;
042    
043    import javax.servlet.Filter;
044    import javax.servlet.FilterChain;
045    import javax.servlet.FilterConfig;
046    import javax.servlet.ServletContext;
047    import javax.servlet.ServletException;
048    import javax.servlet.ServletRequest;
049    import javax.servlet.ServletResponse;
050    import javax.servlet.http.HttpServletRequest;
051    
052    import org.deegree.framework.log.ILogger;
053    import org.deegree.framework.log.LoggerFactory;
054    
055    /**
056     * TODO add class documentation here
057     * 
058     * @author <a href="mailto:name@deegree.org">Andreas Poth</a>
059     * @author last edited by: $Author: admin $
060     * 
061     * @version $Revision: $, $Date: $
062     */
063    public class CSWInitFilter implements Filter {
064    
065        private static ILogger LOG = LoggerFactory.getLogger( CSWInitFilter.class );
066    
067        /*
068         * (non-Javadoc)
069         * 
070         * @see javax.servlet.Filter#destroy()
071         */
072        public void destroy() {
073            // TODO Auto-generated method stub
074        }
075    
076        /*
077         * (non-Javadoc)
078         * 
079         * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
080         */
081        public void init( FilterConfig config )
082                                throws ServletException {
083            // TODO Auto-generated method stub
084        }
085    
086        /*
087         * (non-Javadoc)
088         * 
089         * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
090         * javax.servlet.FilterChain)
091         */
092        public void doFilter( ServletRequest req, ServletResponse res, FilterChain chain )
093                                throws IOException, ServletException {
094            ServletContext sc = ( (HttpServletRequest) req ).getSession().getServletContext();
095    
096            String userName = null;
097            if ( ( (HttpServletRequest) req ).getUserPrincipal() != null ) {
098                userName = ( (HttpServletRequest) req ).getUserPrincipal().getName();
099            }
100    
101            String s = sc.getRealPath( "WEB-INF/conf/setup/catalogueManager_config.properties" );
102            Properties p = new Properties();
103            p.load( new FileInputStream( s ) );
104            String tmp = ( (HttpServletRequest) req ).getRequestURI();
105            if ( tmp.indexOf( "cswsetup.jsp" ) > -1 && !( "cmAdmin".equals( userName ) ) ) {
106                req.setAttribute( "javax.servlet.jsp.jspException",
107                                  new ServletException( "user: " + userName + " is not allowed to setup catalogueManager" ) );
108                req.getRequestDispatcher( "error.jsp" ).forward( req, res );
109            } else {
110                if ( tmp.indexOf( "oracle" ) > -1 && tmp.endsWith( ".html" ) ) {
111                    chain.doFilter( req, res );
112                } else if ( !new Boolean( p.getProperty( "configured" ) ) ) {
113                    req.getRequestDispatcher( "cswsetup.jsp" ).forward( req, res );
114                } else {
115                    if ( tmp.indexOf( "md_editor.jsp" ) > -1 && !new Boolean( p.getProperty( "editor" ) ) ) {
116                        req.getRequestDispatcher( "error.jsp" ).forward( req, res );
117                        LOG.logInfo( "editor is not configured to be available" );
118                    } else if ( tmp.indexOf( "md_editor.jsp" ) > -1 && !( "cmEditor".equals( userName ) ) ) {
119                        req.setAttribute( "javax.servlet.jsp.jspException",
120                                          new ServletException( "user: " + userName + " is not allowed to edit metadata" ) );
121                        req.getRequestDispatcher( "error.jsp" ).forward( req, res );
122                    } else if ( tmp.indexOf( "md_search." ) > -1 && !new Boolean( p.getProperty( "searchClient" ) ) ) {
123                        req.getRequestDispatcher( "error.jsp" ).forward( req, res );
124                        LOG.logInfo( "search client is not configured to be available" );
125                    } else {
126                        chain.doFilter( req, res );
127                    }
128                }
129            }
130    
131        }
132    }