diff --git a/src/main/java/omero/gateway/Connector.java b/src/main/java/omero/gateway/Connector.java index 039141d2..6b65edd9 100644 --- a/src/main/java/omero/gateway/Connector.java +++ b/src/main/java/omero/gateway/Connector.java @@ -98,6 +98,7 @@ import omero.log.LogMessage; import omero.log.Logger; import omero.model.ExperimenterGroup; +import omero.model.ExperimenterGroupI; import omero.model.Session; import omero.sys.Principal; @@ -1010,6 +1011,21 @@ boolean needsKeepAlive() return elapsed > ELAPSED_TIME; } + /** + * Makes sure the ServiceFactory has the correct group context. + * This is necessary when sessionID login was used, because all connectors + * are attached to the same session in that case. + * @throws ServerError if the group context cannot be refreshed + */ + void refreshGroupContext() throws ServerError { + if (entryEncrypted != null) { + entryEncrypted.setSecurityContext(new ExperimenterGroupI(context.getGroupID(), false)); + } + if (entryUnencrypted != null) { + entryUnencrypted.setSecurityContext(new ExperimenterGroupI(context.getGroupID(), false)); + } + } + /** * Recycles the specified service. * @@ -1064,5 +1080,4 @@ private StatefulServiceInterfacePrx create(String name, boolean secure) throw new DSOutOfServiceException("Could not create " + name, e); } } - } diff --git a/src/main/java/omero/gateway/Gateway.java b/src/main/java/omero/gateway/Gateway.java index 5a9e2dee..4e974226 100644 --- a/src/main/java/omero/gateway/Gateway.java +++ b/src/main/java/omero/gateway/Gateway.java @@ -1594,6 +1594,13 @@ public Connector getConnector(SecurityContext ctx, boolean recreate, c = null; } } + try { + // In case of sessionID login all connectors are attached + // to same session, so need to explicitely change group context. + c.refreshGroupContext(); + } catch (ServerError e) { + throw new DSOutOfServiceException("Failed to refresh group context: " + e.getMessage()); + } } // We are going to create a connector and activate a session. @@ -1717,6 +1724,11 @@ private Connector createConnector(SecurityContext ctx, boolean permitNull) .getUser().getPassword()); } if (ctx.getGroupID() >= 0) { + // if this connector attaches to an existing session, have to make sure + // that all stateful services are closed before changing group (see issue #98) + for (StatefulServiceInterfacePrx service : client.getStatefulServices()) { + service.close(); + } prx.setSecurityContext(new ExperimenterGroupI(ctx.getGroupID(), false)); } else { throw new IllegalArgumentException("must set security context with a valid group ID");