001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wass/was/operation/DescribeUserHandler.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    package org.deegree.ogcwebservices.wass.was.operation;
037    
038    import java.io.IOException;
039    
040    import org.deegree.framework.log.ILogger;
041    import org.deegree.framework.log.LoggerFactory;
042    import org.deegree.framework.xml.XMLParsingException;
043    import org.deegree.i18n.Messages;
044    import org.deegree.ogcwebservices.OGCWebServiceException;
045    import org.deegree.ogcwebservices.wass.common.WASSSecurityManager;
046    import org.deegree.security.GeneralSecurityException;
047    import org.deegree.security.drm.SecurityAccessManager;
048    import org.deegree.security.drm.model.User;
049    import org.deegree.security.session.MemoryBasedSessionManager;
050    import org.deegree.security.session.Session;
051    import org.deegree.security.session.SessionStatusException;
052    import org.xml.sax.SAXException;
053    
054    /**
055     * <code>DescribeUserHandler</code> is the handler class for the deegree specific DescribeUser
056     * operation.
057     *
058     * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
059     * @author last edited by: $Author: mschneider $
060     *
061     * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
062     *
063     * @since 2.0
064     */
065    
066    public class DescribeUserHandler {
067    
068        private WASSSecurityManager manager;
069    
070        private MemoryBasedSessionManager sessionManager;
071    
072        private static final ILogger LOG = LoggerFactory.getLogger( DescribeUserHandler.class );
073    
074        /**
075         * Constructs new handler with the specified manager as its data source.
076         *
077         * @param manager the source of the user data
078         */
079        public DescribeUserHandler( WASSSecurityManager manager ) {
080            this.manager = manager;
081            this.sessionManager = MemoryBasedSessionManager.getInstance();
082        }
083    
084        /**
085         * Handles a DescribeUser request.
086         *
087         * @param request the request to handle
088         * @throws OGCWebServiceException
089         * @throws GeneralSecurityException
090         * @return an XML document containing the requested information
091         */
092        public DescribeUserResponse handleRequest( DescribeUser request )
093                                     throws OGCWebServiceException, GeneralSecurityException {
094            SecurityAccessManager sam = manager.getSecurityAccessManager();
095            Session session = null;
096            try {
097                session = sessionManager.getSessionByID( request.getSessionID() );
098            } catch ( SessionStatusException e ) {
099                LOG.logError( e.getLocalizedMessage(), e );
100                throw new OGCWebServiceException( "DescribeUserHandler: ", Messages.getMessage( "WASS_ERROR_INVALID_SESSION", "WASS" ) );
101            }
102    
103            if( session == null ) throw new OGCWebServiceException( "DescribeUserHandler: ",
104                                                                    Messages.getMessage( "WASS_ERROR_INVALID_SESSION", "WASS" ) );
105    
106            if( ! session.isAlive() ) throw new OGCWebServiceException( "DescribeUserHandler: ",
107                                                                        Messages.getMessage( "WASS_ERROR_SESSION_EXPIRED", "WASS" ) );
108    
109            String username = session.getUser();
110    
111            User user = sam.getUserByName( username );
112    
113            DescribeUserResponse response = null;
114    
115            try{
116                response = new DescribeUserResponse( user, request.getSessionID() );
117            } catch ( SAXException saxe ) {
118                LOG.logError( saxe.getLocalizedMessage(), saxe );
119                throw new OGCWebServiceException( "DescribeUserHandler: ",
120                                                  Messages.getMessage( "WASS_" +
121                                                                   "ERROR_RESOURCE_WRONG_FORMAT",
122                                                                   DescribeUserResponse.XML_TEMPLATE ) );
123            } catch ( IOException ioe ) {
124                LOG.logError( ioe.getLocalizedMessage(), ioe );
125                throw new OGCWebServiceException( "DescribeUserHandler: ",
126                                                  Messages.getMessage( "WASS_" +
127                                                                   "ERROR_RESOURCE_NOT_FOUND",
128                                                                   DescribeUserResponse.XML_TEMPLATE ) );
129            } catch ( XMLParsingException xmlpe ) {
130                LOG.logError( xmlpe.getLocalizedMessage(), xmlpe );
131                throw new OGCWebServiceException( "DescribeUserHandler: ",
132                                                  Messages.getMessage( "WASS_" +
133                                                                   "ERROR_RESOURCE_WRONG_FORMAT",
134                                                                   DescribeUserResponse.XML_TEMPLATE ) );
135            }
136    
137            return response;
138        }
139    
140    }