class MetadataServiceImpl implements MetadataService {

  @Override
  public byte[] getMetadata()
  {
    ArrayList<EidasPersonAttributes> list = new ArrayList<>();
    list.add(EidasNaturalPersonAttributes.FAMILY_NAME);
    list.add(EidasNaturalPersonAttributes.FIRST_NAME);
    list.add(EidasNaturalPersonAttributes.CURRENT_ADDRESS);
    list.add(EidasNaturalPersonAttributes.PERSON_IDENTIFIER);
    list.add(EidasNaturalPersonAttributes.BIRTH_NAME);
    list.add(EidasNaturalPersonAttributes.PLACE_OF_BIRTH);
    list.add(EidasNaturalPersonAttributes.DATE_OF_BIRTH);

    List<EidasNameIdType> supportedNameIdTypes = new ArrayList<>();
    supportedNameIdTypes.add(EidasNameIdType.PERSISTENT);
    supportedNameIdTypes.add(EidasNameIdType.TRANSIENT);
    supportedNameIdTypes.add(EidasNameIdType.UNSPECIFIED);
    try
    {
      EidasSigner signer = getEidasSigner();

      Date validUntil;
      if (configHolder.getMetadataValidity() == null)
      {
        // 86400000 milliseconds per day
        validUntil = new Date(System.currentTimeMillis() + 30L * 86400000L);
      }
      else
      {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        validUntil = sdf.parse(configHolder.getMetadataValidity());
      }
      String middlewareVersion = buildProperties.getVersion();
      boolean requesterIdFlag = true;
      return EidasSaml.createMetaDataService("_eumiddleware",
                                             configHolder.getServerURLWithContextPath()
                                                              + ContextPaths.METADATA,
                                             validUntil,
                                             signer.getSigCert(),
                                             configHolder.getDecryptionCert(),
                                             configHolder.getOrganization(),
                                             configHolder.getContactPerson(),
                                             configHolder.getContactPerson(),
                                             configHolder.getServerURLWithContextPath()
                                                                              + ContextPaths.REQUEST_RECEIVER,
                                             configHolder.getServerURLWithContextPath() + ContextPaths.REQUEST_RECEIVER,
                                             supportedNameIdTypes,
                                             list,
                                             signer,
                                             middlewareVersion,
                                             configHolder.isDoSignMetadata(),
                                             requesterIdFlag);
    }
    catch (ParseException | CertificateEncodingException | MarshallingException | SignatureException
      | TransformerFactoryConfigurationError | TransformerException | InitializationException | IOException
      | UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException e)
    {
      log.error("Cannot create metadata for this middleware", e);
    }
    return ArrayUtils.EMPTY_BYTE_ARRAY;
  }

  public  MetadataServiceImpl(ConfigHolder configHolder,
                             BuildProperties buildProperties,
                             HSMServiceHolder hsmServiceHolder);

}