Class IdentityPasswordProvider

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  IdentityPasswordProvider.State
      A simple state object for repeated attempts to get a password for a resource.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getAttempts()
      Gets the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.
      char[] getPassphrase​(URIish uri, int attempt)
      Obtains a passphrase to use to decrypt an ecrypted private key.
      protected char[] getPassword​(URIish uri, int attempt, IdentityPasswordProvider.State state)
      Retrieves a password to decrypt a private key.
      private char[] getPassword​(URIish uri, java.lang.String message)  
      boolean keyLoaded​(URIish uri, int attempt, java.lang.Exception error)
      Invoked after a key has been loaded.
      protected boolean keyLoaded​(URIish uri, IdentityPasswordProvider.State state, char[] password, java.lang.Exception err)
      Invoked to inform the password provider about the decoding result.
      void setAttempts​(int numberOfPasswordPrompts)
      Define the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • setAttempts

        public void setAttempts​(int numberOfPasswordPrompts)
        Description copied from interface: KeyPasswordProvider
        Define the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.
        Specified by:
        setAttempts in interface KeyPasswordProvider
        Parameters:
        numberOfPasswordPrompts - number of times to ask for a passphrase; IllegalArgumentException may be thrown if <= 0
      • getAttempts

        public int getAttempts()
        Description copied from interface: KeyPasswordProvider
        Gets the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider. The default return 1.
        Specified by:
        getAttempts in interface KeyPasswordProvider
        Returns:
        the number of times to ask for a passphrase; should be >= 1.
      • getPassphrase

        public char[] getPassphrase​(URIish uri,
                                    int attempt)
                             throws java.io.IOException
        Description copied from interface: KeyPasswordProvider
        Obtains a passphrase to use to decrypt an ecrypted private key. Returning null or an empty array will skip this key. To cancel completely, the operation should raise CancellationException.
        Specified by:
        getPassphrase in interface KeyPasswordProvider
        Parameters:
        uri - identifying the key resource that is being attempted to be loaded
        attempt - the number of previous attempts to get a passphrase; >= 0
        Returns:
        the passphrase
        Throws:
        java.io.IOException - if no password can be obtained
      • getPassword

        protected char[] getPassword​(URIish uri,
                                     int attempt,
                                     @NonNull
                                     IdentityPasswordProvider.State state)
                              throws java.io.IOException
        Retrieves a password to decrypt a private key.
        Parameters:
        uri - identifying the resource to obtain a password for
        attempt - number of previous attempts to get a passphrase
        state - encapsulating state information about attempts to get the password
        Returns:
        the password, or null or the empty string if none available.
        Throws:
        java.io.IOException - if an error occurs
      • getPassword

        private char[] getPassword​(URIish uri,
                                   java.lang.String message)
      • keyLoaded

        protected boolean keyLoaded​(URIish uri,
                                    IdentityPasswordProvider.State state,
                                    char[] password,
                                    java.lang.Exception err)
                             throws java.io.IOException,
                                    java.security.GeneralSecurityException
        Invoked to inform the password provider about the decoding result.
        Parameters:
        uri - identifying the key resource the key was attempted to be loaded from
        state - associated with this key
        password - the password that was attempted
        err - the attempt result - null for success
        Returns:
        how to proceed in case of error
        Throws:
        java.io.IOException
        java.security.GeneralSecurityException
      • keyLoaded

        public boolean keyLoaded​(URIish uri,
                                 int attempt,
                                 java.lang.Exception error)
                          throws java.io.IOException,
                                 java.security.GeneralSecurityException
        Description copied from interface: KeyPasswordProvider
        Invoked after a key has been loaded. If this raises an exception, the original error is lost unless it is attached to that exception.
        Specified by:
        keyLoaded in interface KeyPasswordProvider
        Parameters:
        uri - identifying the key resource the key was attempted to be loaded from
        attempt - the number of times KeyPasswordProvider.getPassphrase(URIish, int) had been called; zero indicates that uri refers to a non-encrypted key
        error - null if the key was loaded successfully; otherwise an exception indicating why the key could not be loaded
        Returns:
        true to re-try again; false to re-raise the error exception; Ignored if the key was loaded successfully, i.e., if error == null.
        Throws:
        java.io.IOException
        java.security.GeneralSecurityException