Class CredentialService

java.lang.Object
io.github.jbastgen.stemma.app.credential.CredentialService
All Implemented Interfaces:
io.github.jbastgen.stemma.git.api.CredentialLookup

public final class CredentialService extends Object implements io.github.jbastgen.stemma.git.api.CredentialLookup
The accounts Stemma knows (which host, which user, which key) and their secrets. The accounts are kept in a small properties file; the secrets are in the SecretVault, encrypted with the master password. Git backends use this class as their CredentialLookup.
  • Constructor Details

    • CredentialService

      public CredentialService(Path file, SecretVault vault)
      Parameters:
      file - accounts.properties; the accounts without their secrets
      vault - the encrypted store of the secrets
  • Method Details

    • defaultFile

      public static Path defaultFile()
      accounts.properties in the configuration folder.
    • defaultVaultFile

      public static Path defaultVaultFile()
      credentials.vault in the configuration folder.
    • vault

      public SecretVault vault()
      The vault that holds the secrets.
    • accounts

      public List<CredentialService.Account> accounts()
      A copy of the list of accounts.
    • account

      The account with this id.
    • add

      public CredentialService.Account add(String label, io.github.jbastgen.stemma.git.api.CredentialLookup.Kind kind, String host, String username, String keyFile) throws IOException
      Adds an account (without secret); returns it with its new id.
      Throws:
      IOException
    • update

      public void update(CredentialService.Account changed) throws IOException
      Replaces the account with the same id; nothing happens when there is none.
      Throws:
      IOException
    • remove

      public void remove(String id) throws IOException
      Removes the account; its secret goes too if the vault is open, else with the next clean-up.
      Throws:
      IOException
    • setSecret

      public void setSecret(String id, String secret) throws IOException
      Stores the secret of an account; the vault must be unlocked. An empty secret removes it.
      Throws:
      IOException
    • cleanUp

      public void cleanUp()
      After unlocking: forgets secrets of accounts that are gone.
    • needsUnlock

      public boolean needsUnlock()
      Whether the secrets are needed but the vault is locked, so the user should be asked for the master password.
    • find

      public Optional<io.github.jbastgen.stemma.git.api.CredentialLookup.Credential> find(String accountId, String url)
      Specified by:
      find in interface io.github.jbastgen.stemma.git.api.CredentialLookup