Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/main/java/omero/gateway/Connector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -1064,5 +1080,4 @@ private StatefulServiceInterfacePrx create(String name, boolean secure)
throw new DSOutOfServiceException("Could not create " + name, e);
}
}

}
12 changes: 12 additions & 0 deletions src/main/java/omero/gateway/Gateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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");
Expand Down
Loading