diff --git a/openbis/resource/server/web.xml b/openbis/resource/server/web.xml index f4ec7405524ec84ea6fb0671fd60f16e243d2497..4ad7842f17e12e136fa769a4834c1e6dafd45158 100644 --- a/openbis/resource/server/web.xml +++ b/openbis/resource/server/web.xml @@ -11,7 +11,7 @@ &common; <listener> - <listener-class>ch.systemsx.cisd.openbis.generic.client.web.server.LogHttpSessionListener</listener-class> + <listener-class>ch.systemsx.cisd.openbis.generic.client.web.server.GenericHttpSessionListener</listener-class> </listener> <!-- Trying kind of extension (i.e., '*.do') here as 'url-pattern' does not work. --> diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Application.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Application.java index 198261bee7696f076c89d93356358bece32f5f31..48667c4cdfea96ba8267445aceed59219e69a881 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Application.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Application.java @@ -16,8 +16,10 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application; +import com.extjs.gxt.ui.client.event.ComponentEvent; +import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.widget.LayoutContainer; -import com.extjs.gxt.ui.client.widget.Text; +import com.extjs.gxt.ui.client.widget.button.Button; /** * @@ -36,6 +38,21 @@ public class Application extends LayoutContainer private void createGUI() { - add(new Text(viewContext.getModel().getApplicationInfo().getVersion())); + SelectionListener<ComponentEvent> listener = new SelectionListener<ComponentEvent>() + { + @Override + public void componentSelected(ComponentEvent ce) + { + viewContext.getService().logout(new AbstractAsyncCallback<Void>(viewContext) + { + public void onSuccess(Void result) + { + viewContext.getPageController().reload(); + } + }); + } + + }; + add(new Button("logout", listener)); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/GenericClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/GenericClientService.java index 91c2c8c95ae92564f9b55ff92e55bf195afc0ee4..566d0f6c187eae64e3ad95210d78e7c64696418e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/GenericClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/GenericClientService.java @@ -41,7 +41,8 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.Session; */ public class GenericClientService implements IGenericClientService { - private static final String SESSION_KEY = "openbis-session"; + static final String SESSION_KEY = "openbis-session"; + static final String SERVER_KEY = "openbis-generic-server"; private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, GenericClientService.class); @@ -133,6 +134,7 @@ public class GenericClientService implements IGenericClientService // Expiration time of httpSession is 10 seconds less than of session httpSession.setMaxInactiveInterval(session.getSessionExpirationTime() / 1000 - 10); httpSession.setAttribute(SESSION_KEY, session); + httpSession.setAttribute(SERVER_KEY, server); return createSessionContext(session); } @@ -143,6 +145,7 @@ public class GenericClientService implements IGenericClientService { Session session = getSession(httpSession); httpSession.removeAttribute(SESSION_KEY); + httpSession.removeAttribute(SERVER_KEY); httpSession.invalidate(); server.logout(session.getSessionToken()); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/GenericHttpSessionListener.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/GenericHttpSessionListener.java new file mode 100644 index 0000000000000000000000000000000000000000..7c93bb0e6dd84c370ea931e48d4f89cb6ccd062d --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/GenericHttpSessionListener.java @@ -0,0 +1,55 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.server; + +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionEvent; +import javax.servlet.http.HttpSessionListener; + +import ch.systemsx.cisd.openbis.generic.shared.IGenericServer; +import ch.systemsx.cisd.openbis.generic.shared.dto.Session; + + +/** + * Implements {@link HttpSessionListener} and allows to perform chosen actions when session is being + * created or destroyed + * + * @author Izabela Adamczyk + */ +public final class GenericHttpSessionListener implements HttpSessionListener +{ + + public final void sessionCreated(final HttpSessionEvent sessionEvent) + { + } + + public final void sessionDestroyed(final HttpSessionEvent sessionEvent) + { + final HttpSession httpSession = sessionEvent.getSession(); + final Session session = + (Session) httpSession.getAttribute(GenericClientService.SESSION_KEY); + if (session != null) + { + final IGenericServer server = + (IGenericServer) httpSession.getAttribute(GenericClientService.SERVER_KEY); + if (server != null) + { + server.logout(session.getSessionToken()); + } + } + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/LogHttpSessionListener.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/LogHttpSessionListener.java deleted file mode 100644 index 0a66c885a107ddbc38016eed6aed0995478401b8..0000000000000000000000000000000000000000 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/LogHttpSessionListener.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008 ETH Zuerich, CISD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package ch.systemsx.cisd.openbis.generic.client.web.server; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpSessionEvent; -import javax.servlet.http.HttpSessionListener; - -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; - -import ch.systemsx.cisd.common.servlet.IActionLog; - -/** - * Implementation which logs logouts caused by timeouts. - * - * @author Franz-Josef Elmer - */ -public class LogHttpSessionListener implements HttpSessionListener -{ - - public void sessionCreated(HttpSessionEvent event) - { - } - - public void sessionDestroyed(HttpSessionEvent event) - { - HttpSession session = event.getSession(); - if (session != null) - { - ServletContext servletContext = session.getServletContext(); - WebApplicationContext applicationContext = - WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); - IActionLog actionLog = - (IActionLog) applicationContext.getBean("action-log", IActionLog.class); - actionLog.logLogout(session); - } - } - -}