001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wass/was/operation/DescribeUserHandler.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003     This file is part of deegree.
004     Copyright (C) 2001-2006 by:
005     Department of Geography, University of Bonn
006     http://www.giub.uni-bonn.de/deegree/
007     lat/lon GmbH
008     http://www.lat-lon.de
009     This library is free software; you can redistribute it and/or
010     modify it under the terms of the GNU Lesser General Public
011     License as published by the Free Software Foundation; either
012     version 2.1 of the License, or (at your option) any later version.
013     This library is distributed in the hope that it will be useful,
014     but WITHOUT ANY WARRANTY; without even the implied warranty of
015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016     Lesser General Public License for more details.
017     You should have received a copy of the GNU Lesser General Public
018     License along with this library; if not, write to the Free Software
019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020     Contact:
021     Andreas Poth
022     lat/lon GmbH
023     Aennchenstraße 19
024     53177 Bonn
025     Germany
026     E-Mail: poth@lat-lon.de
027     Jens Fitzke
028     lat/lon GmbH
029     Aennchenstraße 19
030     53177 Bonn
031     Germany
032     E-Mail: jens.fitzke@uni-bonn.de
033     ---------------------------------------------------------------------------*/
034    package org.deegree.ogcwebservices.wass.was.operation;
035    
036    import java.io.IOException;
037    
038    import org.deegree.framework.log.ILogger;
039    import org.deegree.framework.log.LoggerFactory;
040    import org.deegree.framework.xml.XMLParsingException;
041    import org.deegree.i18n.Messages;
042    import org.deegree.ogcwebservices.OGCWebServiceException;
043    import org.deegree.ogcwebservices.wass.common.WASSSecurityManager;
044    import org.deegree.security.GeneralSecurityException;
045    import org.deegree.security.drm.SecurityAccessManager;
046    import org.deegree.security.drm.model.User;
047    import org.deegree.security.session.MemoryBasedSessionManager;
048    import org.deegree.security.session.Session;
049    import org.deegree.security.session.SessionStatusException;
050    import org.xml.sax.SAXException;
051    
052    /**
053     * <code>DescribeUserHandler</code> is the handler class for the deegree specific DescribeUser
054     * operation.
055     * 
056     * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
057     * @author last edited by: $Author: aschmitz $
058     * 
059     * @version 2.0, $Revision: 7341 $, $Date: 2007-05-29 14:03:14 +0200 (Di, 29 Mai 2007) $
060     * 
061     * @since 2.0
062     */
063    
064    public class DescribeUserHandler {
065    
066        private WASSSecurityManager manager;
067        
068        private MemoryBasedSessionManager sessionManager;
069        
070        private static final ILogger LOG = LoggerFactory.getLogger( DescribeUserHandler.class );
071        
072        /**
073         * Constructs new handler with the specified manager as its data source.
074         * 
075         * @param manager the source of the user data
076         */
077        public DescribeUserHandler( WASSSecurityManager manager ) {
078            this.manager = manager;
079            this.sessionManager = MemoryBasedSessionManager.getInstance();
080        }
081        
082        /**
083         * Handles a DescribeUser request.
084         * 
085         * @param request the request to handle
086         * @throws OGCWebServiceException
087         * @throws GeneralSecurityException 
088         * @return an XML document containing the requested information
089         */
090        public DescribeUserResponse handleRequest( DescribeUser request )
091                                     throws OGCWebServiceException, GeneralSecurityException {
092            SecurityAccessManager sam = manager.getSecurityAccessManager();
093            Session session = null;
094            try {
095                session = sessionManager.getSessionByID( request.getSessionID() );
096            } catch ( SessionStatusException e ) {
097                LOG.logError( e.getLocalizedMessage(), e );
098                throw new OGCWebServiceException( "DescribeUserHandler: ", Messages.getMessage( "WASS_ERROR_INVALID_SESSION", "WASS" ) );
099            }
100            
101            if( session == null ) throw new OGCWebServiceException( "DescribeUserHandler: ",
102                                                                    Messages.getMessage( "WASS_ERROR_INVALID_SESSION", "WASS" ) );
103            
104            if( ! session.isAlive() ) throw new OGCWebServiceException( "DescribeUserHandler: ",
105                                                                        Messages.getMessage( "WASS_ERROR_SESSION_EXPIRED", "WASS" ) );
106            
107            String username = session.getUser();
108            
109            User user = sam.getUserByName( username );
110    
111            DescribeUserResponse response = null;
112            
113            try{
114                response = new DescribeUserResponse( user, request.getSessionID() );
115            } catch ( SAXException saxe ) {
116                LOG.logError( saxe.getLocalizedMessage(), saxe );
117                throw new OGCWebServiceException( "DescribeUserHandler: ",
118                                                  Messages.getMessage( "WASS_" +
119                                                                   "ERROR_RESOURCE_WRONG_FORMAT",
120                                                                   DescribeUserResponse.XML_TEMPLATE ) );
121            } catch ( IOException ioe ) {
122                LOG.logError( ioe.getLocalizedMessage(), ioe );
123                throw new OGCWebServiceException( "DescribeUserHandler: ",
124                                                  Messages.getMessage( "WASS_" +
125                                                                   "ERROR_RESOURCE_NOT_FOUND",
126                                                                   DescribeUserResponse.XML_TEMPLATE ) );
127            } catch ( XMLParsingException xmlpe ) {
128                LOG.logError( xmlpe.getLocalizedMessage(), xmlpe );
129                throw new OGCWebServiceException( "DescribeUserHandler: ",
130                                                  Messages.getMessage( "WASS_" +
131                                                                   "ERROR_RESOURCE_WRONG_FORMAT",
132                                                                   DescribeUserResponse.XML_TEMPLATE ) );
133            }
134            
135            return response;
136        }
137        
138    }