Class UserCredentialStore

java.lang.Object
io.github.mastodonContentMover.UserCredentialStore

public class UserCredentialStore extends Object
Holds in an XML-persistable object the user-level API access tokens for user accounts on respective Mastodon instances.

Uses the singleton model, as only one UserCredentialStore object is needed to hold all credentials and only one should be instantiated at a time. Synchronized methods will be synchronized on the singleton object (because there is only ever one).

TODO: Add a parameter that allows the tool to run without persisting any tokens (for user or client) for use in low-security environments.

Since:
0.01.00
  • Method Details

    • getSingletonInstance

      public static UserCredentialStore getSingletonInstance() throws jakarta.xml.bind.JAXBException, IOException
      Obtains a reference to the currently instantiated UserCredentialStore singleton object, or instantiates one if that has not already been done.

      Returns:
      a reference to an UserCredentialStore object

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)
      Since:
      0.01.00
    • addCredentials

      public void addCredentials(String instance, String username, String accessToken) throws jakarta.xml.bind.JAXBException, IOException
      Adds a user-level API access token for a specified user account on a Mastodon instance specified by hostname or address to the object data store within this UserCredentialStore object and saves its state to file in an XML format using JAXB.

      The user account and instance data is stored by one-way concatenation of the instance address and user account name, separated with an underscore, which is then used as a key that maps to the access token.

      Parameters:
      instance - the hostname or address of the Mastodon instance
      username - the username for the account on the Mastodon instance
      accessToken - a user-level API access token

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
    • getAccessToken

      public String getAccessToken(String instance, String username)
      Retrieves a user-level API access token for a specified user account on a Mastodon instance specified by hostname or address from the object data store within this UserCredentialStore instance.

      Parameters:
      instance - the hostname or address of the Mastodon instance
      username - the username for the account on the Mastodon instance

      Returns:
      a user-level API access token for the specified user account and instance
      Since:
      0.01.00