/** {@inheritDoc} */
  public void removeAuthzGroup(String azGroupId) throws AuthzPermissionException {
    if (azGroupId == null) return;

    // check for existance
    AuthzGroup azGroup = m_storage.get(azGroupId);
    if (azGroup == null) {
      return;
    }

    // check security (throws if not permitted)
    unlock(SECURE_REMOVE_AUTHZ_GROUP, authzGroupReference(azGroupId));

    // complete the azGroup
    m_storage.remove(azGroup);

    // track it
    eventTrackingService()
        .post(
            eventTrackingService()
                .newEvent(SECURE_REMOVE_AUTHZ_GROUP, azGroup.getReference(), true));

    // close the azGroup object
    ((BaseAuthzGroup) azGroup).closeEdit();

    // clear any site security based on this (if a site) azGroup
    removeSiteSecurity(azGroup);
  }
Exemplo n.º 2
0
 public void removeResponsibility(Number160 locationKey, boolean keepData) {
   RangeLock<Number640>.Range lockResp = lockResponsibility(locationKey);
   try {
     if (!keepData) {
       RangeLock<Number640>.Range lock = lock(locationKey);
       try {
         final NavigableMap<Number640, Data> removed =
             backend.remove(
                 new Number640(locationKey, Number160.ZERO, Number160.ZERO, Number160.ZERO),
                 new Number640(
                     locationKey, Number160.MAX_VALUE, Number160.MAX_VALUE, Number160.MAX_VALUE));
         for (Map.Entry<Number640, Data> entry : removed.entrySet()) {
           if (entry.getValue() != null) {
             entry.getValue().release();
           }
           backend.removeTimeout(entry.getKey());
         }
       } finally {
         lock.unlock();
       }
     }
     backend.removeResponsibility(locationKey);
   } finally {
     lockResp.unlock();
   }
 }
Exemplo n.º 3
0
  public NavigableMap<Number640, Data> removeReturnData(
      Number640 from, Number640 to, PublicKey publicKey) {
    RangeLock<Number640>.Range lock = rangeLock.lock(from, to);
    try {
      Map<Number640, Data> tmp = backend.subMap(from, to);
      NavigableMap<Number640, Data> result = new TreeMap<Number640, Data>();

      for (Number640 key : tmp.keySet()) {
        // fail fast, as soon as we want to remove 1 domain that we
        // cannot, abort
        if (!canClaimDomain(key.locationAndDomainKey(), publicKey)) {
          result.put(key, null);
        } else if (!canClaimEntry(key.locationAndDomainAndContentKey(), publicKey)) {
          result.put(key, null);
        } else {
          Data toRemove = backend.get(key);
          if (toRemove != null
              && (toRemove.publicKey() == null || toRemove.publicKey().equals(publicKey))) {
            backend.removeTimeout(key);
            Data removed = backend.remove(key, true);
            result.put(key, removed);
          }
        }
      }
      return result;
    } finally {
      lock.unlock();
    }
  }
Exemplo n.º 4
0
 public void checkTimeout() {
   long time = System.currentTimeMillis();
   Collection<Number640> toRemove = backend.subMapTimeout(time);
   for (Number640 key : toRemove) {
     RangeLock<Number640>.Range lock = lock(key);
     try {
       Data oldData = backend.remove(key, false);
       if (oldData != null) {
         oldData.release();
       }
       backend.removeTimeout(key);
       // remove responsibility if we don't have any data stored under
       // locationkey
       Number160 locationKey = key.locationKey();
       RangeLock<Number640>.Range lockResp = lockResponsibility(locationKey);
       try {
         if (isEmpty(locationKey)) {
           backend.removeResponsibility(locationKey);
         }
       } finally {
         lockResp.unlock();
       }
     } finally {
       lock.unlock();
     }
   }
 }
Exemplo n.º 5
0
 public void remove(Address address, byte[] addressSignature) throws Exception {
   // TODO Auto-generated method stub
   // do I have this value on myself ?
   // if (storage.contains(address)) {
   storage.remove(address, addressSignature);
   // }
   if (!isResponsible(address)) {
     getClient().remove(address, addressSignature);
   }
 }
Exemplo n.º 6
0
    public AliasEdit edit(String id) {
      BaseAliasEdit rv = (BaseAliasEdit) super.editResource(id);

      // if not found, try from the old (convert to the new)
      if (m_checkOld && (rv == null)) {
        // this locks the old table/record
        rv = (BaseAliasEdit) m_oldStorage.edit(id);
        if (rv != null) {
          // create the record in new, also locking it into an edit
          rv = (BaseAliasEdit) super.putResource(id, fields(id, rv, false));

          // delete the old record
          m_oldStorage.remove(rv);
        }
      }

      if (rv != null) rv.activate();
      return rv;
    }
  /** @inheritDoc */
  public void remove(DigestEdit edit) {
    // check for closed edit
    if (!edit.isActiveEdit()) {
      try {
        throw new Exception();
      } catch (Exception e) {
        M_log.warn(".remove(): closed DigestEdit", e);
      }
      return;
    }

    // complete the edit
    m_storage.remove(edit);

    // track it
    eventTrackingService()
        .post(eventTrackingService().newEvent(SECURE_REMOVE_DIGEST, edit.getReference(), true));

    // close the edit object
    ((BaseDigest) edit).closeEdit();
  }
Exemplo n.º 8
0
 public Pair<Data, Enum<?>> remove(Number640 key, PublicKey publicKey, boolean returnData) {
   RangeLock<Number640>.Range lock = lock(key);
   try {
     if (!canClaimDomain(key.locationAndDomainKey(), publicKey)) {
       return new Pair<Data, Enum<?>>(null, PutStatus.FAILED_SECURITY);
     }
     if (!canClaimEntry(key.locationAndDomainAndContentKey(), publicKey)) {
       return new Pair<Data, Enum<?>>(null, PutStatus.FAILED_SECURITY);
     }
     if (!backend.contains(key)) {
       return new Pair<Data, Enum<?>>(null, PutStatus.NOT_FOUND);
     }
     backend.removeTimeout(key);
     Data removed = backend.remove(key, returnData);
     if (removed != null && !returnData) {
       removed.release();
     }
     // else -> it will be removed in the encoder
     return new Pair<Data, Enum<?>>(removed, PutStatus.OK);
   } finally {
     lock.unlock();
   }
 }
Exemplo n.º 9
0
  public Map<Number640, Enum<?>> putAll(
      final NavigableMap<Number640, Data> dataMap,
      PublicKey publicKey,
      boolean putIfAbsent,
      boolean domainProtection,
      boolean sendSelf) {
    if (dataMap.isEmpty()) {
      return Collections.emptyMap();
    }
    final Number640 min = dataMap.firstKey();
    final Number640 max = dataMap.lastKey();
    final Map<Number640, Enum<?>> retVal = new HashMap<Number640, Enum<?>>();
    final HashSet<Number480> keysToCheck = new HashSet<Number480>();
    final RangeLock<Number640>.Range lock = lock(min, max);
    try {
      for (Map.Entry<Number640, Data> entry : dataMap.entrySet()) {
        Number640 key = entry.getKey();
        keysToCheck.add(key.locationAndDomainAndContentKey());
        Data newData = entry.getValue();
        if (!securityDomainCheck(
            key.locationAndDomainKey(), publicKey, publicKey, domainProtection)) {
          retVal.put(key, PutStatus.FAILED_SECURITY);
          newData.release();
          continue;
        }

        // We need this check in case we did not use the encoder/decoder,
        // which is the case if we send the message to ourself. In that
        // case, the public key of the data is never set to the message
        // publick key, if the publick key of the data was null.
        final PublicKey dataKey;
        if (sendSelf && newData.publicKey() == null) {
          dataKey = publicKey;
        } else {
          dataKey = newData.publicKey();
        }

        if (!securityEntryCheck(
            key.locationAndDomainAndContentKey(), publicKey, dataKey, newData.isProtectedEntry())) {
          retVal.put(key, PutStatus.FAILED_SECURITY);
          newData.release();
          continue;
        }

        final Data oldDataGet = backend.get(key);
        if (oldDataGet != null) {
          if (putIfAbsent) {
            retVal.put(key, PutStatus.FAILED_NOT_ABSENT);
            newData.release();
            continue;
          }

          if (oldDataGet.isDeleted()) {
            retVal.put(key, PutStatus.DELETED);
            newData.release();
            continue;
          }
          if (!oldDataGet.basedOnSet().equals(newData.basedOnSet())) {
            retVal.put(key, PutStatus.VERSION_FORK);
            newData.release();
            continue;
          }
        }

        final Data oldDataPut = backend.put(key, newData);

        long expiration = newData.expirationMillis();
        // handle timeout
        backend.addTimeout(key, expiration);

        if (newData.hasPrepareFlag()) {
          retVal.put(key, PutStatus.OK_PREPARED);
        } else {
          retVal.put(key, PutStatus.OK);
        }
        if (oldDataPut != null && oldDataPut != newData) {
          oldDataPut.release();
        }
      }

      for (Number480 key : keysToCheck) {

        // now check for forks
        Number640 minVersion = new Number640(key, Number160.ZERO);
        Number640 maxVersion = new Number640(key, Number160.MAX_VALUE);
        NavigableMap<Number640, Data> tmp = backend.subMap(minVersion, maxVersion);
        tmp = filterCopyOrig(tmp, -1, true);
        NavigableMap<Number640, Data> heads = getLatestInternalOrig(tmp);

        final boolean forked = heads.size() > 1;
        for (final Map.Entry<Number640, Data> entry : heads.entrySet()) {
          if (forked) {
            if (retVal.containsKey(entry.getKey())) {
              retVal.put(entry.getKey(), PutStatus.VERSION_FORK);
            }
          }
        }

        // now remove old versions
        if (maxVersions > 0) {
          NavigableMap<Number640, Data> versions = backend.subMap(minVersion, maxVersion);

          while (!versions.isEmpty()
              && versions.firstKey().versionKey().timestamp() + maxVersions
                  <= versions.lastKey().versionKey().timestamp()) {
            Map.Entry<Number640, Data> entry = versions.pollFirstEntry();
            Data removed = backend.remove(entry.getKey(), true);
            if (removed != null) {
              removed.release();
            }
            backend.removeTimeout(entry.getKey());
          }
        }
      }
      return retVal;

    } finally {
      lock.unlock();
    }
  }
Exemplo n.º 10
0
  /**
   * Tests {@link Storage} by creating a new Storage, {@link Storage#add(Storable) adding data},
   * adding more data, {@link Storage#remove(long) removing data}, and {@link Storage#compact()
   * compacting the directory}, checking the {@link Storage#size() number of stored objects} and the
   * {@link Storage#getDirectorySize() number of directory entries} after every action.
   *
   * @throws StorageException
   */
  @SuppressWarnings("synthetic-access")
  public void testSimpleStorage() throws StorageException {
    Storage<Data> storage;
    Data data;

    storage = new Storage<Data>(new DataFactory(), directory, "data");
    data = new Data(0x12345678);
    try {
      storage.add(data);
      fail("exception expected");
    } catch (IllegalStateException ise1) {
      /* okay. */
    }

    storage.open();
    assertEquals(0, storage.size());
    assertEquals(0, storage.getDirectorySize());
    storage.add(data);
    assertEquals(1, storage.size());
    assertEquals(1, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(1, storage.size());
    assertEquals(1, storage.getDirectorySize());
    data = storage.load(0x12345678);
    assertNotNull(data);
    storage.close();

    data = new Data(0x23456789);
    storage.open();
    assertEquals(1, storage.size());
    assertEquals(1, storage.getDirectorySize());
    storage.add(data);
    assertEquals(2, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(2, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.remove(0x12345678);
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.remove(0x01234567);
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.remove(0x23456789);
    assertEquals(0, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(0, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.compact();
    storage.open();
    assertEquals(0, storage.size());
    assertEquals(0, storage.getDirectorySize());
    storage.close();
  }