예제 #1
0
  @Override
  public ContainerToken verifyToken(final String token, String containerHostId, String publicKey)
      throws HostRegistrationException {

    ContainerTokenImpl containerToken = containerTokenDataService.find(token);

    if (containerToken == null) {
      throw new HostRegistrationException("Couldn't verify container token");
    }

    if (containerToken.getDateCreated().getTime() + containerToken.getTtl()
        < System.currentTimeMillis()) {
      throw new HostRegistrationException("Container token expired");
    }

    try {
      securityManager
          .getKeyManager()
          .savePublicKeyRing(
              containerHostId, SecurityKeyType.CONTAINER_HOST_KEY.getId(), publicKey);
    } catch (Exception e) {
      LOG.error("Error verifying token", e);

      throw new HostRegistrationException("Failed to store container pubkey", e);
    }

    return containerToken;
  }
예제 #2
0
  @Override
  public ContainerToken generateContainerTTLToken(final long ttlInMs)
      throws HostRegistrationException {
    Preconditions.checkArgument(ttlInMs > 0, "Invalid ttl");

    ContainerTokenImpl token =
        new ContainerTokenImpl(
            UUID.randomUUID().toString(), new Timestamp(System.currentTimeMillis()), ttlInMs);
    try {
      containerTokenDataService.persist(token);
    } catch (Exception e) {
      LOG.error("Error persisting container token", e);

      throw new HostRegistrationException(e);
    }

    return token;
  }