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