if ( ! isOwnerOrSupervisor(obj)) throw new SecurityViolation(String.format( "You are not authorized to change " + "the permissions for %s from %s to %s", obj, previousP, currentP));
	protected boolean managedPermissions(boolean locked, boolean privileged,			IObject obj, Details previousDetails, Details currentDetails,			Details newDetails) {				// setup		boolean altered = false;		Permissions previousP = previousDetails == null ? null				: previousDetails.getPermissions();		Permissions currentP = currentDetails == null ? null : currentDetails				.getPermissions();		// ignore newDetails permissions.		if ( ! isOwnerOrSupervisor(obj))			throw new SecurityViolation(String.format(					"You are not authorized to change "							+ "the permissions for %s from %s to %s", obj,					previousP, currentP));				// If the stored perms are null, then we can't validate anything		if (previousP == null) {			if (currentP == null) {				newDetails.setPermissions(null);				altered |= false; // don't need to update			} else {				newDetails.setPermissions(currentP);				altered = true;			}		}		// WORKAROUND for ticket:307 by checking for SOFT below		// see https://trac.openmicroscopy.org.uk/omero/ticket/307		// see		// http://opensource.atlassian.com/projects/hibernate/browse/HHH-2027		// Users did not enter permission (normal case) so is null OR		// in the workaround permissions is SOFT, then		// need to copy whole sale those from database.		else if (currentP == null || currentP.isSet(Flag.SOFT)) {			newDetails.setPermissions(previousP);			altered = true;		}		// if the user has set the permissions (currentDetails), then we should		// try to allow that. if it's identical to the current, then there		// is no reason to hit the DB.		else {			// if we need to filter any permissions, do it here!			newDetails.setPermissions(currentP);			if (!currentP.identical(previousP)) {				altered = true;			}		}		// now we've calculated the desired permissions, throw		// a security violation if this instance was locked AND		// the read permissions have been lowered or if the lock		// was removed.		if (locked) {			if (previousP == null) // if null it can't have been locked.				throw new InternalException("Null permissions cannot be locked");			Permissions calculatedP = newDetails.getPermissions();			if (calculatedP != null) {				// can't override				if ( ! calculatedP.isSet( Flag.LOCKED ))				{					calculatedP.set(Flag.LOCKED);					altered = true;				}								if ((previousP.isGranted(USER, READ) && !calculatedP.isGranted(USER,						READ))						|| (previousP.isGranted(GROUP, READ) && !calculatedP								.isGranted(GROUP, READ))						|| (previousP.isGranted(WORLD, READ) && !calculatedP								.isGranted(WORLD, READ)))					throw new SecurityViolation(							"Cannot remove READ from locked entity:" + obj);			}		}		// privileged plays no role since everyone can alter their permissions		// (within bounds)		return altered;	}