else {    newDetails.setPermissions( currentP ); if ( ! currentP.identical( previousP ) ) { altered = true; } }      if ( locked ) {
Permissions previousP = previousDetails == null ? null : previousDetails.getPermissions();  Permissions currentP = currentDetails == null ? null : currentDetails .getPermissions();     if (previousP == null) { if (currentP == null) { newDetails.setPermissions(null); altered |= false; } else { newDetails.setPermissions(currentP); altered = true; } }          else if (currentP == null || currentP.isSet(Flag.SOFT)) { newDetails.setPermissions(previousP); altered = true; }     else {    newDetails.setPermissions(currentP); if (!currentP.identical(previousP)) { altered = true; } }      if (locked) {
    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 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 newP = newDetails.getPermissions();    		    		if ( newP != null )    		{    		    			// can't override    			newP.set( Flag.LOCKED );    							if ((previousP.isGranted(USER, READ) && !newP.isGranted(USER, READ))						|| (previousP.isGranted(GROUP, READ) && !newP.isGranted(								GROUP, READ))						|| (previousP.isGranted(WORLD, READ) && !newP.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;    	        	    }