/**
  * Creates a {@link Details} object for the current security context.
  *
  * <p>The {@link Permissions} on the instance are calculated from the current group as well as the
  * user's umask.
  *
  * @return
  * @see <a href="https://trac.openmicroscopy.org.uk/trac/omero/ticket:1434">ticket:1434</a>
  */
 public Details createDetails() {
   BasicEventContext c = current();
   Details d = Details.create();
   d.setCreationEvent(c.getEvent());
   d.setUpdateEvent(c.getEvent());
   d.setOwner(c.getOwner());
   d.setGroup(c.getGroup());
   // ticket:1434
   Permissions groupPerms = c.getCurrentGroupPermissions();
   Permissions userUmask = c.getCurrentUmask();
   Permissions p = new Permissions(groupPerms);
   p.revokeAll(userUmask);
   d.setPermissions(p);
   return d;
 }
 /**
  * Checks if the current {@link Thread} has non-null {@link Experimenter}, {@link Event}, and
  * {@linkExperimenterGroup}, required for proper functioning of the security system.
  */
 public boolean isReady() {
   BasicEventContext c = current();
   if (c.getEvent() != null && c.getGroup() != null && c.getOwner() != null) {
     return true;
   }
   return false;
 }
  public void addLog(String action, Class klass, Long id) {

    Assert.notNull(action);
    Assert.notNull(klass);
    Assert.notNull(id);

    if (Event.class.isAssignableFrom(klass) || EventLog.class.isAssignableFrom(klass)) {
      if (log.isDebugEnabled()) {
        log.debug("Not logging creation of logging type:" + klass);
      }
      return; // EARLY EXIT
    } else {
      if (!isReady()) {
        throw new InternalException("Not ready to add EventLog");
      }
    }

    if (log.isInfoEnabled()) {
      log.info("Adding log:" + action + "," + klass + "," + id);
    }

    BasicEventContext c = current();
    List<EventLog> list = current().getLogs();
    if (list == null) {
      list = new ArrayList<EventLog>();
      c.setLogs(list);
    }

    EventLog l = new EventLog();
    l.setAction(action);
    l.setEntityType(klass.getName()); // TODO could be id to Type entity
    l.setEntityId(id);
    l.setEvent(c.getEvent());
    Details d = Details.create();
    d.setPermissions(new Permissions());
    l.getDetails().copy(d);
    list.add(l);
  }