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