001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wass/was/WAService.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2008 by: 006 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 044 package org.deegree.ogcwebservices.wass.was; 045 046 import java.util.ArrayList; 047 048 import org.deegree.framework.log.ILogger; 049 import org.deegree.framework.log.LoggerFactory; 050 import org.deegree.framework.trigger.TriggerProvider; 051 import org.deegree.i18n.Messages; 052 import org.deegree.ogcwebservices.OGCWebService; 053 import org.deegree.ogcwebservices.OGCWebServiceException; 054 import org.deegree.ogcwebservices.OGCWebServiceRequest; 055 import org.deegree.ogcwebservices.getcapabilities.OGCCapabilities; 056 import org.deegree.ogcwebservices.wass.common.CloseSession; 057 import org.deegree.ogcwebservices.wass.common.CloseSessionHandler; 058 import org.deegree.ogcwebservices.wass.common.GetSession; 059 import org.deegree.ogcwebservices.wass.common.GetSessionAnonymousHandler; 060 import org.deegree.ogcwebservices.wass.common.GetSessionDispatcher; 061 import org.deegree.ogcwebservices.wass.common.GetSessionHandler; 062 import org.deegree.ogcwebservices.wass.common.GetSessionPasswordHandler; 063 import org.deegree.ogcwebservices.wass.common.Operation_1_0; 064 import org.deegree.ogcwebservices.wass.common.WASSSecurityManager; 065 import org.deegree.ogcwebservices.wass.was.configuration.WASConfiguration; 066 import org.deegree.ogcwebservices.wass.was.configuration.WASDeegreeParams; 067 import org.deegree.ogcwebservices.wass.was.operation.DescribeUser; 068 import org.deegree.ogcwebservices.wass.was.operation.DescribeUserHandler; 069 import org.deegree.ogcwebservices.wass.was.operation.WASGetCapabilities; 070 import org.deegree.security.GeneralSecurityException; 071 import org.deegree.security.session.SessionStatusException; 072 073 /** 074 * This is the main WAService class that implements a WAS according to the GDI NRW spec V1.0. 075 * 076 * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a> 077 * @author last edited by: $Author: apoth $ 078 * 079 * @version $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $ 080 */ 081 public class WAService implements OGCWebService { 082 083 private WASConfiguration configuration = null; 084 085 private static final ILogger LOG = LoggerFactory.getLogger( WAService.class ); 086 087 private static final TriggerProvider TP = TriggerProvider.create( WAService.class ); 088 089 private GetSessionHandler getSessionHandler = null; 090 091 private CloseSessionHandler closeSessionHandler = null; 092 093 private DescribeUserHandler describeUserHandler = null; 094 095 /** 096 * Creates a new service according to the given configuration. 097 * 098 * @param configuration 099 * the config 100 * @throws OGCWebServiceException 101 */ 102 public WAService( WASConfiguration configuration ) throws OGCWebServiceException { 103 104 this.configuration = configuration; 105 106 // setup GetSession/CloseSession handler(s) 107 WASDeegreeParams dgParams = configuration.getDeegreeParams(); 108 if ( configuration.isSessionAuthenticationSupported() ) { 109 for ( Operation_1_0 operation : configuration.getOperationsMetadata().getAllOperations() ) { 110 if ( "GetSession".equals( operation.getName() ) ) { 111 try { 112 ArrayList<GetSessionHandler> handlers = new ArrayList<GetSessionHandler>( 4 ); 113 int lifetime = dgParams.getSessionLifetime(); 114 if ( configuration.isPasswordAuthenticationSupported() ) { 115 WASSSecurityManager secManager = new WASSSecurityManager( dgParams.getDatabaseConnection() ); 116 handlers.add( new GetSessionPasswordHandler( secManager, lifetime ) ); 117 } 118 if ( configuration.isAnonymousAuthenticationSupported() ) { 119 handlers.add( new GetSessionAnonymousHandler( lifetime ) ); 120 } 121 if ( handlers.size() == 0 ) 122 throw new OGCWebServiceException( Messages.getMessage( "WASS_ERROR_NO_AUTHMETHOD_HANDLER", 123 "WAS" ) ); 124 getSessionHandler = new GetSessionDispatcher( handlers ); 125 126 } catch ( GeneralSecurityException e ) { 127 LOG.logError( e.getLocalizedMessage(), e ); 128 throw new OGCWebServiceException( e.getLocalizedMessage() ); 129 } 130 } else if ( "CloseSession".equals( operation.getName() ) ) { 131 closeSessionHandler = new CloseSessionHandler(); 132 } else if ( "DescribeUser".equals( operation.getName() ) ) { 133 try { 134 WASSSecurityManager secManager = new WASSSecurityManager( dgParams.getDatabaseConnection() ); 135 describeUserHandler = new DescribeUserHandler( secManager ); 136 } catch ( GeneralSecurityException e ) { 137 LOG.logError( e.getLocalizedMessage(), e ); 138 throw new OGCWebServiceException( e.getLocalizedMessage() ); 139 } 140 } 141 } 142 } 143 144 } 145 146 /* 147 * (non-Javadoc) 148 * 149 * @see org.deegree.ogcwebservices.OGCWebService#getCapabilities() 150 */ 151 public OGCCapabilities getCapabilities() { 152 return configuration; 153 } 154 155 /* 156 * (non-Javadoc) 157 * 158 * @see org.deegree.ogcwebservices.OGCWebService#doService(org.deegree.ogcwebservices.OGCWebServiceRequest) 159 */ 160 public Object doService( OGCWebServiceRequest request ) 161 throws OGCWebServiceException { 162 163 request = (OGCWebServiceRequest) TP.doPreTrigger( this, request )[0]; 164 165 Object response = null; 166 167 // TODO exception handling: throw e after each different occasion with descriptive msg 168 try { 169 if ( request instanceof WASGetCapabilities ) { 170 response = configuration; 171 } else if ( ( getSessionHandler != null ) && ( request instanceof GetSession ) ) { 172 response = getSessionHandler.handleRequest( (GetSession) request ); 173 } else if ( ( closeSessionHandler != null ) && ( request instanceof CloseSession ) ) { 174 closeSessionHandler.handleRequest( (CloseSession) request ); 175 } else if ( ( describeUserHandler != null ) && ( request instanceof DescribeUser ) ) { 176 response = describeUserHandler.handleRequest( (DescribeUser) request ); 177 } else { 178 throw new OGCWebServiceException( Messages.getMessage( "WASS_ERROR_UNKNOWN_REQUEST", 179 new Object[] { getClass().getName(), 180 request.getClass().getName() } ) ); 181 } 182 } catch ( SessionStatusException e ) { 183 LOG.logError( e.getLocalizedMessage(), e ); 184 // TODO Check if this particular message is needed for the GDI NRW spec V1.0. 185 // Otherwise delete it and use e.getMessage() instead. 186 // response = new OGCWebServiceException( Messages.getMessage( 187 // "WASS_ERROR_INVALID_SESSION", "WAService" ) ); 188 response = new OGCWebServiceException( e.getLocalizedMessage() ); 189 } catch ( GeneralSecurityException e ) { 190 LOG.logError( e.getLocalizedMessage(), e ); 191 // TODO Check if this particular message is needed for the GDI NRW spec V1.0. 192 // Otherwise delete it and use e.getMessage() instead. 193 // throw new OGCWebServiceException( Messages.getMessage( 194 // "WASS_ERROR_SECURITY_SYSTEM", "WAService" ) ); 195 throw new OGCWebServiceException( e.getLocalizedMessage() ); 196 } 197 198 return TP.doPostTrigger( this, response )[0]; 199 } 200 201 }