001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/portal/standard/security/control/RemoveServiceListener.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.portal.standard.security.control;
037
038 import static org.deegree.framework.log.LoggerFactory.getLogger;
039 import static org.deegree.framework.util.StringTools.stackTraceToString;
040 import static org.deegree.i18n.Messages.get;
041 import static org.deegree.portal.standard.security.control.ClientHelper.TYPE_FEATURETYPE;
042 import static org.deegree.portal.standard.security.control.ClientHelper.TYPE_LAYER;
043 import static org.deegree.portal.standard.security.control.SecurityHelper.acquireTransaction;
044 import static org.deegree.portal.standard.security.control.SecurityHelper.checkForAdminRole;
045 import static org.deegree.security.drm.SecurityAccessManager.getInstance;
046
047 import java.util.LinkedList;
048
049 import javax.servlet.ServletRequest;
050
051 import org.deegree.enterprise.control.AbstractListener;
052 import org.deegree.enterprise.control.FormEvent;
053 import org.deegree.enterprise.control.RPCParameter;
054 import org.deegree.enterprise.control.RPCWebEvent;
055 import org.deegree.framework.log.ILogger;
056 import org.deegree.framework.util.StringPair;
057 import org.deegree.security.GeneralSecurityException;
058 import org.deegree.security.drm.SecurityAccessManager;
059 import org.deegree.security.drm.SecurityTransaction;
060 import org.deegree.security.drm.model.Service;
061
062 /**
063 * <code>RemoveServiceListener</code>
064 *
065 * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
066 * @author last edited by: $Author: mschneider $
067 *
068 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
069 */
070 public class RemoveServiceListener extends AbstractListener {
071
072 private static final ILogger LOG = getLogger( RemoveServiceListener.class );
073
074 @Override
075 public void actionPerformed( FormEvent event ) {
076 RPCParameter[] params = ( (RPCWebEvent) event ).getRPCMethodCall().getParameters();
077
078 ServletRequest request = getRequest();
079
080 SecurityTransaction transaction = null;
081 SecurityAccessManager manager = null;
082
083 try {
084 // perform access check
085 manager = getInstance();
086 transaction = acquireTransaction( this );
087 checkForAdminRole( transaction );
088
089 String address = params[0].getValue().toString();
090
091 Service service = transaction.getServiceByAddress( address );
092
093 String type = service.getServiceType().equalsIgnoreCase( "wms" ) ? TYPE_LAYER : TYPE_FEATURETYPE;
094 for ( StringPair pair : service.getObjects() ) {
095 transaction.deregisterSecuredObject( transaction.getSecuredObjectByName( "[" + address + "]:"
096 + pair.first, type ) );
097 }
098
099 transaction.deregisterService( service );
100
101 manager.commitTransaction( transaction );
102
103 LinkedList<Service> services = transaction.getAllServices();
104 request.setAttribute( "SERVICES", services );
105
106 } catch ( GeneralSecurityException e ) {
107 getRequest().setAttribute( "SOURCE", this.getClass().getName() );
108 getRequest().setAttribute( "MESSAGE", get( "IGEO_STD_SEC_ERROR_REMOVE_SERVICE", e.getMessage() ) );
109 setNextPage( "error.jsp" );
110 LOG.logError( e.getMessage(), e );
111 try {
112 if ( manager != null ) {
113 manager.abortTransaction( transaction );
114 }
115 } catch ( GeneralSecurityException e1 ) {
116 LOG.logError( "Unknown error", e1 );
117 getRequest().setAttribute( "SOURCE", this.getClass().getName() );
118 getRequest().setAttribute( "MESSAGE", get( "IGEO_STD_SEC_ERROR_REMOVE_SERVICE", e1.getMessage() ) );
119 setNextPage( "error.jsp" );
120 }
121 } catch ( Exception e ) {
122 LOG.logError( get( "IGEO_STD_SEC_ERROR_UNKNOWN", stackTraceToString( e ) ) );
123 try {
124 if ( manager != null ) {
125 manager.abortTransaction( transaction );
126 }
127 } catch ( GeneralSecurityException e1 ) {
128 LOG.logError( "Unknown error", e1 );
129 getRequest().setAttribute( "SOURCE", this.getClass().getName() );
130 getRequest().setAttribute( "MESSAGE", get( "IGEO_STD_SEC_ERROR_REMOVE_SERVICE", e1.getMessage() ) );
131 setNextPage( "error.jsp" );
132 return;
133 }
134 getRequest().setAttribute( "SOURCE", this.getClass().getName() );
135 getRequest().setAttribute( "MESSAGE", get( "IGEO_STD_SEC_ERROR_REMOVE_SERVICE", e.getMessage() ) );
136 setNextPage( "error.jsp" );
137 }
138 }
139
140 }