001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/portal/standard/security/control/SecurityRequestDispatcher.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2008 by: 006 EXSE, Department of Geography, University of Bonn 007 http://www.giub.uni-bonn.de/deegree/ 008 lat/lon GmbH 009 http://www.lat-lon.de 010 011 This library is free software; you can redistribute it and/or 012 modify it under the terms of the GNU Lesser General Public 013 License as published by the Free Software Foundation; either 014 version 2.1 of the License, or (at your option) any later version. 015 016 This library is distributed in the hope that it will be useful, 017 but WITHOUT ANY WARRANTY; without even the implied warranty of 018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 Lesser General Public License for more details. 020 021 You should have received a copy of the GNU Lesser General Public 022 License along with this library; if not, write to the Free Software 023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 024 025 Contact: 026 027 Andreas Poth 028 lat/lon GmbH 029 Aennchenstr. 19 030 53177 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Prof. Dr. Klaus Greve 035 Department of Geography 036 University of Bonn 037 Meckenheimer Allee 166 038 53115 Bonn 039 Germany 040 E-Mail: greve@giub.uni-bonn.de 041 042 ---------------------------------------------------------------------------*/ 043 package org.deegree.portal.standard.security.control; 044 045 import java.io.File; 046 import java.io.InputStreamReader; 047 import java.io.Reader; 048 import java.net.URI; 049 import java.net.URL; 050 import java.util.Properties; 051 052 import javax.servlet.ServletConfig; 053 import javax.servlet.ServletException; 054 055 import org.deegree.enterprise.control.RequestDispatcher; 056 import org.deegree.framework.xml.NamespaceContext; 057 import org.deegree.framework.xml.XMLTools; 058 import org.deegree.i18n.Messages; 059 import org.deegree.io.IODocument; 060 import org.deegree.io.JDBCConnection; 061 import org.deegree.security.drm.SecurityAccessManager; 062 import org.w3c.dom.Document; 063 import org.w3c.dom.Element; 064 065 /** 066 * 067 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 068 * @author last edited by: $Author: apoth $ 069 * 070 * @version $Revision: 9346 $, $Date: 2007-12-27 17:39:07 +0100 (Do, 27 Dez 2007) $ 071 */ 072 public class SecurityRequestDispatcher extends RequestDispatcher { 073 074 private static String SECURITY_CONFIG = "Security.configFile"; 075 076 /** 077 * This method initializes the servlet. 078 * 079 * @param cfg 080 * the servlet configuration 081 * @throws ServletException 082 * an exception 083 */ 084 @Override 085 public void init( ServletConfig cfg ) 086 throws ServletException { 087 super.init( cfg ); 088 089 try { 090 // config file -> DOM 091 String s = getInitParameter( SECURITY_CONFIG ); 092 File file = new File( s ); 093 if ( !file.isAbsolute() ) { 094 file = new File( getServletContext().getRealPath( s ) ); 095 } 096 URL url = file.toURL(); 097 Reader reader = new InputStreamReader( url.openStream() ); 098 Document doc = XMLTools.parse( reader ); 099 Element element = doc.getDocumentElement(); 100 reader.close(); 101 102 // extract configuration information from DOM 103 String readWriteTimeoutString = XMLTools.getStringValue( "readWriteTimeout", null, 104 element, "600" ); 105 int readWriteTimeout = Integer.parseInt( readWriteTimeoutString ); 106 107 String registryClass = XMLTools.getRequiredStringValue( "registryClass", null, element ); 108 Element registryConfig = (Element) XMLTools.getRequiredNode( element, "registryConfig", 109 null ); 110 111 // required: <connection> 112 NamespaceContext nsc = new NamespaceContext(); 113 nsc.addNamespace( "jdbc", new URI( "http://www.deegree.org/jdbc" ) ); 114 element = (Element) XMLTools.getRequiredNode( registryConfig, "jdbc:JDBCConnection", 115 nsc ); 116 IODocument xml = new IODocument( element ); 117 JDBCConnection jdbc = xml.parseJDBCConnection(); 118 119 Properties properties = new Properties(); 120 121 // required: <driver> 122 properties.put( "driver", jdbc.getDriver() ); 123 // required: <logon> 124 properties.put( "url", jdbc.getURL() ); 125 // required: <user> 126 properties.put( "user", jdbc.getUser() ); 127 // required: <password> 128 properties.put( "password", jdbc.getPassword() ); 129 130 if ( !SecurityAccessManager.isInitialized() ) { 131 SecurityAccessManager.initialize( registryClass, properties, 132 readWriteTimeout * 1000 ); 133 } 134 135 } catch ( Exception e ) { 136 throw new ServletException( Messages.getMessage( "IGEO_STD_SEC_FAIL_INIT_SEC_DISPATCHER", 137 e.getMessage() ) ); 138 } 139 140 } 141 }