001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wass/common/WASSSecurityManager.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2004 by:
006     EXSE, Department of Geography, University of Bonn
007     http://www.giub.uni-bonn.de/exse/
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     Meckenheimer Allee 176
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.common;
045    
046    import java.util.Properties;
047    
048    import org.deegree.framework.log.ILogger;
049    import org.deegree.framework.log.LoggerFactory;
050    import org.deegree.i18n.Messages;
051    import org.deegree.io.JDBCConnection;
052    import org.deegree.security.GeneralSecurityException;
053    import org.deegree.security.drm.SecurityAccessManager;
054    
055    /**
056     * This class will hold the SecurityAccessManager Instance and will be able to parse the
057     * user/password key for the security database.
058     * 
059     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
060     * @author last edited by: $Author: aschmitz $
061     * 
062     * @version $Revision: 7866 $, $Date: 2007-07-31 16:04:32 +0200 (Di, 31 Jul 2007) $
063     */
064    
065    public class WASSSecurityManager {
066    
067        private JDBCConnection databaseInfo = null;
068        
069        private SecurityAccessManager securityAccessManager = null;
070    
071        private static final ILogger LOG = LoggerFactory.getLogger( WASSSecurityManager.class );
072    
073        /**
074         * This constructor initializes the connection to the security database.
075         * 
076         * @param dbInfo a database information object
077         * 
078         * @throws GeneralSecurityException
079         */
080        public WASSSecurityManager( JDBCConnection dbInfo ) throws GeneralSecurityException {
081            databaseInfo = dbInfo;
082            initializeSecurityAccessManager();
083        }
084    
085        /**
086         * Loads the deegree SecurityAccesManager if no instance is present jet.
087         * 
088         * @throws GeneralSecurityException
089         *             if the no instance of the deegree securitymanager could be touched.
090         */
091        private void initializeSecurityAccessManager()
092                                throws GeneralSecurityException {
093            LOG.entering();
094            if( databaseInfo == null ) {
095                LOG.logError( Messages.getMessage( "WASS_ERROR_SECURITYACCESSMANAGER_NO_DBINFO" ) );
096                return;
097            }
098            Properties properties = new Properties();
099            properties.setProperty( "driver", databaseInfo.getDriver() );
100            properties.setProperty( "url", databaseInfo.getURL() );
101            properties.setProperty( "user", databaseInfo.getUser() );
102            properties.setProperty( "password", databaseInfo.getPassword() );
103            try {
104                securityAccessManager = SecurityAccessManager.getInstance();
105            } catch ( GeneralSecurityException gse ) {
106                try {
107                    SecurityAccessManager.initialize( "org.deegree.security.drm.SQLRegistry",
108                                                      properties, 60 * 1000 );
109                    securityAccessManager = SecurityAccessManager.getInstance();
110                } catch ( GeneralSecurityException gse2 ) {
111                    LOG.logError( Messages.getMessage( "WASS_ERROR_SECURITYACCESSMANAGER" ) );
112                    LOG.logError( gse2.getLocalizedMessage(), gse2 );
113                    throw new GeneralSecurityException(
114                                                       Messages.getMessage( "WASS_ERROR_SECURITYACCESSMANAGER" ) );
115                }
116            }
117            LOG.exiting();
118        }
119    
120        /**
121         * @return Returns the deegree securityAccessManager.
122         * @throws GeneralSecurityException
123         */
124        public SecurityAccessManager getSecurityAccessManager()
125                                throws GeneralSecurityException {
126            LOG.entering();
127            if ( securityAccessManager == null ) {
128                throw new GeneralSecurityException(
129                                                    Messages.getMessage( "WASS_ERROR_SECURITYACCESSMANAGER_NO_INIT" ) );
130            }
131            LOG.exiting();
132            return securityAccessManager;
133        }
134    
135    }