From fabdac9df24b2175cc2defb7e2feda3e9b9fe92c Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Thu, 4 Jul 2013 14:41:58 +0000 Subject: [PATCH] SP-745, BIS-476: Allow to add session token as a parameter to URL for URL resolving. SVN: 29520 --- .../client/web/client/IClientService.java | 7 +++-- .../web/client/IClientServiceAsync.java | 5 ++-- .../client/web/client/application/Client.java | 17 ++++++----- .../application/locator/OpenViewAction.java | 8 +++-- .../application/locator/ViewLocator.java | 29 ++++++++++++++----- .../web/server/AbstractClientService.java | 7 +++-- 6 files changed, 46 insertions(+), 27 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/IClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/IClientService.java index 98a659de34e..7c6ce795a3a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/IClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/IClientService.java @@ -53,8 +53,9 @@ public interface IClientService extends RemoteService * Tries to return the current session context. If failed <code>null</code> is returned. * * @param anonymous whether the session is expected to be anonymous or not + * @param sessionIdOrNull id of the session or <code>null</code>. */ - public SessionContext tryToGetCurrentSessionContext(boolean anonymous); + public SessionContext tryToGetCurrentSessionContext(boolean anonymous, String sessionIdOrNull); /** * Tries to login with specified user ID and password. If failed <code>null</code> is returned. @@ -81,8 +82,8 @@ public interface IClientService extends RemoteService /** * Resets display settings of the logged user to the default settings. * <p> - * NOTE: this changes user display settings only on the DB level. Old settings are still in the - * session and needs to be updated with the settings returned by this function. + * NOTE: this changes user display settings only on the DB level. Old settings are still in the session and needs to be updated with the settings + * returned by this function. * * @return default display settings */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/IClientServiceAsync.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/IClientServiceAsync.java index 6bf3120743a..8e3c9b2c5fc 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/IClientServiceAsync.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/IClientServiceAsync.java @@ -39,9 +39,8 @@ public interface IClientServiceAsync /** @see IClientService#getCustomImports */ public void getCustomImports(AsyncCallback<List<CustomImport>> callback); - /** @see IClientService#tryToGetCurrentSessionContext(boolean anonymous) */ - public void tryToGetCurrentSessionContext(boolean anonymous, - AsyncCallback<SessionContext> callback); + /** @see IClientService#tryToGetCurrentSessionContext(boolean, String) */ + public void tryToGetCurrentSessionContext(boolean anonymous, String sessionIdOrNull, AsyncCallback<SessionContext> callback); /** @see IClientService#tryToLogin(String, String) */ public void tryToLogin(String userID, String password, AsyncCallback<SessionContext> callback); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java index eea6ad2f011..542ecb4e52e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java @@ -45,6 +45,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.Ho import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.MaterialLocatorResolver; import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.MetaprojectBrowserLocatorResolver; import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.MetaprojectLocatorResolver; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.OpenViewAction; import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.PermlinkLocatorResolver; import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.ProjectLocatorResolver; import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.SampleRegistrationLocatorResolver; @@ -223,10 +224,12 @@ public class Client implements EntryPoint, ValueChangeHandler<String> model.setAnonymousAllowed(anonymous); // the callback sets the SessionContext and redirects to the login page or the // initial page and may additionaly open an initial tab + OpenViewAction action = UrlParamsHelper.createNavigateToCurrentUrlAction(viewContext); SessionContextCallback sessionContextCallback = new SessionContextCallback((CommonViewContext) viewContext, - UrlParamsHelper.createNavigateToCurrentUrlAction(viewContext)); - service.tryToGetCurrentSessionContext(anonymous, sessionContextCallback); + action); + String sessionId = action.getViewLocator().getSessionId(); + service.tryToGetCurrentSessionContext(anonymous, sessionId, sessionContextCallback); } private ViewMode findViewMode(ApplicationInfo info) @@ -277,8 +280,7 @@ public class Client implements EntryPoint, ValueChangeHandler<String> } /** - * A version of onModuleLoad specifically for tests. Ignore the state in the session and go - * directly to the login page. + * A version of onModuleLoad specifically for tests. Ignore the state in the session and go directly to the login page. */ public final void onModuleLoadTest() { @@ -308,8 +310,7 @@ public class Client implements EntryPoint, ValueChangeHandler<String> } /** - * Callback class which handles return value - * {@link ICommonClientService#tryToGetCurrentSessionContext()}. + * Callback class which handles return value {@link ICommonClientService#tryToGetCurrentSessionContext()}. * * @author Franz-Josef Elmer */ @@ -426,8 +427,8 @@ public class Client implements EntryPoint, ValueChangeHandler<String> * Register any handlers for locators specified in the openBIS URL. * * @param handlerRegistry The handler registry to initialize - * @param context The ViewContext which may be needed by resolvers. Can't use the viewContext - * instance variable since it may not have been initialized yet. + * @param context The ViewContext which may be needed by resolvers. Can't use the viewContext instance variable since it may not have been + * initialized yet. */ protected void initializeLocatorHandlerRegistry(ViewLocatorResolverRegistry handlerRegistry, IViewContext<ICommonClientServiceAsync> context) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/OpenViewAction.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/OpenViewAction.java index c07fafb004c..1b6eaff8fa1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/OpenViewAction.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/OpenViewAction.java @@ -38,6 +38,11 @@ public class OpenViewAction implements IDelegatedAction this.viewLocator = viewLocator; } + public ViewLocator getViewLocator() + { + return viewLocator; + } + /** @return true if executing this action would not result in opening any view */ public boolean isEmpty() { @@ -51,8 +56,7 @@ public class OpenViewAction implements IDelegatedAction } /** - * Opens the initial view and handles any user failure exceptions that may result in the - * process. + * Opens the initial view and handles any user failure exceptions that may result in the process. */ protected void openView() { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/ViewLocator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/ViewLocator.java index 79dbb61b4e8..5b756bc9368 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/ViewLocator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/ViewLocator.java @@ -23,16 +23,15 @@ import java.util.Map; import ch.systemsx.cisd.common.shared.basic.string.StringUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.lang.StringEscapeUtils; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; +import ch.systemsx.cisd.openbis.generic.shared.basic.GenericSharedConstants; import ch.systemsx.cisd.openbis.generic.shared.basic.PermlinkUtilities; /** - * A view locator represents the information necessary to open a view including populating it any - * parameters. The concept is similar to a URL (Universal Resource Locator), but made specific to - * view in openBIS. + * A view locator represents the information necessary to open a view including populating it any parameters. The concept is similar to a URL + * (Universal Resource Locator), but made specific to view in openBIS. * <p> - * The view locator may be initialized from URL-encoded parameters. One parameter, ACTION, is - * required. ENTITY, though not required, is often used. These two parameters are thus handled - * specially. + * The view locator may be initialized from URL-encoded parameters. One parameter, ACTION, is required. ENTITY, though not required, is often used. + * These two parameters are thus handled specially. * * @author Chandrasekhar Ramakrishnan */ @@ -43,6 +42,8 @@ public class ViewLocator private static final String PARAMETER_SEPARATOR = "&"; + public static final String SESSION_ID_PARAMETER = GenericSharedConstants.SESSION_ID_PARAMETER; + public static final String ACTION_PARAMETER = BasicConstant.LOCATOR_ACTION_PARAMETER; public static final String ENTITY_PARAMETER = PermlinkUtilities.ENTITY_KIND_PARAMETER_KEY; @@ -54,6 +55,8 @@ public class ViewLocator private static final String GWT_PARAMETER = "gwt.codesvr"; // Instance Variables + private String sessionIdOrNull; + private String actionOrNull; private String entityOrNull; @@ -80,6 +83,14 @@ public class ViewLocator return historyToken; } + /** + * Returns the session id or <code>null</code> if not known. + */ + public String getSessionId() + { + return sessionIdOrNull; + } + /** * The action parameter for the view locator. If the locator is valid, then action is non-null. */ @@ -107,8 +118,7 @@ public class ViewLocator } /** - * Return true if this view locator meets the minimal criteria for validity. If the locator is - * valid, then action is non-null. + * Return true if this view locator meets the minimal criteria for validity. If the locator is valid, then action is non-null. */ public boolean isValid() { @@ -150,6 +160,9 @@ public class ViewLocator if (GWT_PARAMETER.equals(paramName)) { // skip GWT parameters -- only relevant during testing + } else if (SESSION_ID_PARAMETER.equalsIgnoreCase(paramName)) + { + sessionIdOrNull = paramValue; } else if (ACTION_PARAMETER.equalsIgnoreCase(paramName)) { actionOrNull = paramValue; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java index ac74847e3b3..746de99e87d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java @@ -537,11 +537,12 @@ public abstract class AbstractClientService implements IClientService, } @Override - public final SessionContext tryToGetCurrentSessionContext(boolean anonymous) + public final SessionContext tryToGetCurrentSessionContext(boolean anonymous, String sessionIdOrNull) { + boolean sessionIdSpecified = sessionIdOrNull != null; try { - final String sessionToken = getSessionToken(); + final String sessionToken = sessionIdSpecified ? sessionIdOrNull : getSessionToken(); final SessionContextDTO session = getServer().tryGetSession(sessionToken); if (session == null) { @@ -552,7 +553,7 @@ public abstract class AbstractClientService implements IClientService, getServer().logout(sessionToken); return null; } - return createSessionContext(session); + return sessionIdSpecified ? tryToLogin(session) : createSessionContext(session); } catch (final InvalidSessionException e) { return null; -- GitLab