001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wass/common/WASSSecurityManager.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.common;
038    
039    import static org.deegree.i18n.Messages.getMessage;
040    
041    import java.util.Properties;
042    
043    import org.deegree.framework.log.ILogger;
044    import org.deegree.framework.log.LoggerFactory;
045    import org.deegree.i18n.Messages;
046    import org.deegree.io.JDBCConnection;
047    import org.deegree.security.GeneralSecurityException;
048    import org.deegree.security.drm.SecurityAccessManager;
049    
050    /**
051     * This class will hold the SecurityAccessManager Instance and will be able to parse the user/password key for the
052     * security database.
053     *
054     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
055     * @author last edited by: $Author: mschneider $
056     *
057     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
058     */
059    
060    public class WASSSecurityManager {
061    
062        private JDBCConnection databaseInfo = null;
063    
064        private SecurityAccessManager securityAccessManager = null;
065    
066        private static final ILogger LOG = LoggerFactory.getLogger( WASSSecurityManager.class );
067    
068        /**
069         * This constructor initializes the connection to the security database.
070         *
071         * @param dbInfo
072         *            a database information object
073         *
074         * @throws GeneralSecurityException
075         */
076        public WASSSecurityManager( JDBCConnection dbInfo ) throws GeneralSecurityException {
077            databaseInfo = dbInfo;
078            initializeSecurityAccessManager();
079        }
080    
081        /**
082         * Loads the deegree SecurityAccesManager if no instance is present jet.
083         *
084         * @throws GeneralSecurityException
085         *             if the no instance of the deegree securitymanager could be touched.
086         */
087        private void initializeSecurityAccessManager()
088                                throws GeneralSecurityException {
089    
090            if ( databaseInfo == null ) {
091                LOG.logError( Messages.getMessage( "WASS_ERROR_SECURITYACCESSMANAGER_NO_DBINFO" ) );
092                return;
093            }
094            Properties properties = new Properties();
095            properties.setProperty( "driver", databaseInfo.getDriver() );
096            properties.setProperty( "url", databaseInfo.getURL() );
097            properties.setProperty( "user", databaseInfo.getUser() );
098            properties.setProperty( "password", databaseInfo.getPassword() );
099            try {
100                securityAccessManager = SecurityAccessManager.getInstance();
101            } catch ( GeneralSecurityException gse ) {
102                try {
103                    SecurityAccessManager.initialize( "org.deegree.security.drm.SQLRegistry", properties, 60 * 1000 );
104                    securityAccessManager = SecurityAccessManager.getInstance();
105                } catch ( GeneralSecurityException gse2 ) {
106                    LOG.logError( Messages.getMessage( "WASS_ERROR_SECURITYACCESSMANAGER" ) );
107                    LOG.logError( gse2.getLocalizedMessage(), gse2 );
108                    throw new GeneralSecurityException( getMessage( "WASS_ERROR_SECURITYACCESSMANAGER" ) );
109                }
110            }
111    
112        }
113    
114        /**
115         * @return Returns the deegree securityAccessManager.
116         * @throws GeneralSecurityException
117         */
118        public SecurityAccessManager getSecurityAccessManager()
119                                throws GeneralSecurityException {
120    
121            if ( securityAccessManager == null ) {
122                throw new GeneralSecurityException( getMessage( "WASS_ERROR_SECURITYACCESSMANAGER_NO_INIT" ) );
123            }
124    
125            return securityAccessManager;
126        }
127    
128    }