001/* 002 * acme4j - Java ACME client 003 * 004 * Copyright (C) 2016 Richard "Shred" Körber 005 * http://acme4j.shredzone.org 006 * 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 013 */ 014package org.shredzone.acme4j; 015 016import static java.util.stream.Collectors.toList; 017 018import java.net.URI; 019import java.util.Collection; 020import java.util.Collections; 021 022import org.shredzone.acme4j.toolbox.JSON; 023import org.shredzone.acme4j.toolbox.JSON.Array; 024import org.shredzone.acme4j.toolbox.JSON.Value; 025 026/** 027 * Contains metadata related to the provider. 028 */ 029public class Metadata { 030 031 private final JSON meta; 032 033 /** 034 * Creates a new {@link Metadata} instance. 035 * 036 * @param meta 037 * JSON map of metadata 038 */ 039 public Metadata(JSON meta) { 040 this.meta = meta; 041 } 042 043 /** 044 * Returns an {@link URI} to the current terms of service, or {@code null} if not 045 * available. 046 */ 047 public URI getTermsOfService() { 048 return meta.get("terms-of-service").asURI(); 049 } 050 051 /** 052 * Returns an {@link URI} to a website providing more information about the ACME 053 * server. {@code null} if not available. 054 */ 055 public URI getWebsite() { 056 return meta.get("website").asURI(); 057 } 058 059 /** 060 * Returns a collection of hostnames, which the ACME server recognises as referring to 061 * itself for the purposes of CAA record validation. Empty if not available. 062 */ 063 public Collection<String> getCaaIdentities() { 064 Array array = meta.get("caa-identities").asArray(); 065 if (array == null) { 066 return Collections.emptyList(); 067 } 068 069 return array.stream().map(Value::asString).collect(toList()); 070 } 071 072 /** 073 * Returns the JSON representation of the metadata. This is useful for reading 074 * proprietary metadata properties. 075 */ 076 public JSON getJSON() { 077 return meta; 078 } 079 080}