Class Session

java.lang.Object
org.shredzone.acme4j.Session

public class Session extends Object
A Session tracks the entire communication with a CA.

To create a session instance, use its constructor. It requires the URI of the ACME server to connect to. This can be the location of the CA's directory (via http or https protocol), or a special URI (via acme protocol). See the documentation about valid URIs.

  • Field Details

  • Constructor Details

    • Session

      public Session(String serverUri)
      Creates a new Session.
      Parameters:
      serverUri - URI string of the ACME server to connect to. This is either the location of the CA's ACME directory (using http or https protocol), or a special URI (using the acme protocol).
      Throws:
      IllegalArgumentException - if no ACME provider was found for the server URI.
    • Session

      public Session(URI serverUri)
      Creates a new Session.
      Parameters:
      serverUri - URI of the ACME server to connect to. This is either the location of the CA's ACME directory (using http or https protocol), or a special URI (using the acme protocol).
      Throws:
      IllegalArgumentException - if no ACME provider was found for the server URI.
    • Session

      public Session(URI serverUri, AcmeProvider provider)
      Creates a new Session using the given AcmeProvider.

      This constructor is only to be used for testing purposes.

      Parameters:
      serverUri - URI of the ACME server
      provider - AcmeProvider to be used
      Since:
      2.8
  • Method Details

    • login

      public Login login(URL accountLocation, KeyPair accountKeyPair)
      Logs into an existing account.
      Parameters:
      accountLocation - Location URL of the account
      accountKeyPair - Account KeyPair
      Returns:
      Login to this account
    • getServerUri

      public URI getServerUri()
      Gets the ACME server URI of this session.
    • getNonce

      @Nullable public String getNonce()
      Gets the last base64 encoded nonce, or null if the session is new. This method is mainly for internal use.
    • setNonce

      public void setNonce(@Nullable String nonce)
      Sets the base64 encoded nonce received by the server. This method is mainly for internal use.
    • getLocale

      @Nullable public Locale getLocale()
      Gets the current locale of this session, or null if no special language is selected.
    • setLocale

      public void setLocale(@Nullable Locale locale)
      Sets the locale used in this session. The locale is passed to the server as Accept-Language header. The server may respond with localized messages. The default is the system's language. If set to null, any language will be accepted.
    • getLanguageHeader

      Gets an Accept-Language header value that matches the current locale. This method is mainly for internal use.
      Since:
      3.0.0
    • networkSettings

      Returns the current NetworkSettings.
      Returns:
      NetworkSettings
      Since:
      2.8
    • provider

      Returns the AcmeProvider that is used for this session.
      Returns:
      AcmeProvider
    • connect

      public Connection connect()
      Returns a new Connection to the ACME server.
      Returns:
      Connection
    • resourceUrl

      public URL resourceUrl(Resource resource) throws AcmeException
      Gets the URL of the given Resource. This may involve connecting to the server and fetching the directory. The result is cached.
      Parameters:
      resource - Resource to get the URL of
      Returns:
      URL of the resource
      Throws:
      AcmeException - if the server does not offer the Resource
    • resourceUrlOptional

      Gets the URL of the given Resource. This may involve connecting to the server and fetching the directory. The result is cached.
      Parameters:
      resource - Resource to get the URL of
      Returns:
      URL of the resource, or empty if the resource is not available.
      Throws:
      AcmeException
      Since:
      3.0.0
    • getMetadata

      Gets the metadata of the provider's directory. This may involve connecting to the server and fetching the directory. The result is cached.
      Returns:
      Metadata. May contain no data, but is never null.
      Throws:
      AcmeException
    • getDirectoryLastModified

      Returns the date when the directory has been modified the last time.
      Returns:
      The last modification date of the directory, or null if unknown (directory has not been read yet or did not provide this information).
      Since:
      2.10
    • setDirectoryLastModified

      public void setDirectoryLastModified(@Nullable ZonedDateTime directoryLastModified)
      Sets the date when the directory has been modified the last time. Should only be invoked by AcmeProvider implementations.
      Parameters:
      directoryLastModified - The last modification date of the directory, or null if unknown (directory has not been read yet or did not provide this information).
      Since:
      2.10
    • getDirectoryExpires

      @Nullable public ZonedDateTime getDirectoryExpires()
      Returns the date when the current directory records will expire. A fresh copy of the directory will be fetched automatically after that instant.
      Returns:
      The expiration date, or null if the server did not provide this information.
      Since:
      2.10
    • setDirectoryExpires

      public void setDirectoryExpires(@Nullable ZonedDateTime directoryExpires)
      Sets the date when the current directory will expire. Should only be invoked by AcmeProvider implementations.
      Parameters:
      directoryExpires - Expiration date, or null if the server did not provide this information.
      Since:
      2.10
    • hasDirectory

      public boolean hasDirectory()
      Returns true if a copy of the directory is present in a local cache. It is not evaluated if the cached copy has expired though.
      Returns:
      true if a directory is available.
      Since:
      2.10
    • purgeDirectoryCache

      public void purgeDirectoryCache()
      Purges the directory cache. Makes sure that a fresh copy of the directory will be read from the CA on the next time the directory is accessed.
      Since:
      3.0.0