private void throwSecurityViolationIfNotAllowed(final IObject i) { final String type = i.getClass().getName(); final Details d = i.getDetails(); final long user = d.getOwner().getId(); final long group = d.getGroup().getId(); final EventContext ec = getSecuritySystem().getEventContext(); final boolean root = ec.isCurrentUserAdmin(); final List<Long> leaderof = ec.getLeaderOfGroupsList(); final boolean pi = leaderof.contains(group); final boolean own = ec.getCurrentUserId().equals(user); if (!own && !root && !pi) { if (log.isWarnEnabled()) { log.warn( String.format( "User %d attempted to delete " + type + " %d belonging to User %d", ec.getCurrentUserId(), i.getId(), user)); } throw new SecurityViolation( String.format("User %s cannot delete %s %d ", ec.getCurrentUserName(), type, i.getId())); } }
public static OMEROMetadataStoreClient mockStore(ServiceFactory sf, String password) throws Exception { System.setProperty("omero.testing", "true"); OmeroContext inner = sf.getContext(); OmeroContext outer = new OmeroContext( new String[] { "classpath:ome/services/messaging.xml", // To share events "classpath:ome/formats/fixture.xml", "classpath:ome/services/blitz-servantDefinitions.xml", "classpath:ome/services/throttling/throttling.xml", "classpath:ome/config.xml" }, false); outer.setParent(inner); outer.refresh(); EventContext ec = sf.getAdminService().getEventContext(); String username = ec.getCurrentUserName(); long groupid = ec.getCurrentGroupId(); MockFixture fixture = new MockFixture(new MockObjectTestCase() {}, outer); omero.client client = fixture.newClient(); // Fixing group permissions from 4.2.0 client .createSession(username, password) .setSecurityContext(new omero.model.ExperimenterGroupI(groupid, false)); OMEROMetadataStoreClient store = new OMEROMetadataStoreClient(); store.initialize(client); return store; }