org.netbeans.libs.git/1 1.1

org.netbeans.libs.git
Class GitClientCallback

java.lang.Object
  extended by org.netbeans.libs.git.GitClientCallback

public abstract class GitClientCallback
extends Object

Used as a callback to acquire user's credentials and ask caller about different questions during an inter-repository commands, e.g. fetch, push, clone. If an API client runs a git command that accesses a remote repository and the repository requires authentication then this is the class it should use to pass the credentials.

How to use this class
  1. Get an instance of GitClient you want to run the fetch command with, see GitRepository
  2. Extend this class and implement all abstract methods
  3. Pass the instance of the class to the git client, see GitClient.setCallback(org.netbeans.libs.git.GitClientCallback)
  4. Run a remote command, see e.g. GitClient.fetch(java.lang.String, org.netbeans.libs.git.progress.ProgressMonitor)
  5. While the fetch command is running, methods getUsername and getPassword will be called from within the client so make sure they return the correct credentials
Let's assume we want to run a fetch command on a remote repository at http://myrepositoryhost/path that requires credentials username/password:
 GitClient client = GitRepository.getInstance(myLocalReposiry).createClient();
 GitClientCallback myCallback = new GitClientCallback () {
     public String askQuestion (String uri, String prompt) { return null; }
     
     public String getUsername (String uri, String prompt) {
         return "username";
     }
     
     public char[] getPassword (String uri, String prompt) {
         return "password".toCharArray();
     }
         
     public char[] getPassphrase (String uri, String prompt) { return null; }
 
     public String getIdentityFile (String uri, String prompt);
     public Boolean askYesNoQuestion (String uri, String prompt);
 };
 client.setCallback(myCallback);
 List refspecs = Arrays.asList("refs/heads/*:refs/remotes/origin/*");
 client.fetch("http://myrepositoryhost/path", refspecs, pm);
 

Also note that returning null from the implemented methods means that you want to cancel the authentication attempt.


Constructor Summary
GitClientCallback()
           
 
Method Summary
abstract  String askQuestion(String uri, String prompt)
          Through this method you are asked a question you should answer.
abstract  Boolean askYesNoQuestion(String uri, String prompt)
          Through this method you are asked a question you should answer Yes or No.
abstract  String getIdentityFile(String uri, String prompt)
          If the authentication should be done via a private/public key pair instead of usual username/password, implement this method and return the absolute path to the file with the private key.
abstract  char[] getPassphrase(String uri, String prompt)
          Implement this to pass the passphrase to unlock the private key.
abstract  char[] getPassword(String uri, String prompt)
          Implement this to pass the user's password to the authentication process.
abstract  String getUsername(String uri, String prompt)
          You should implement this to pass a username required by the authentication process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GitClientCallback

public GitClientCallback()
Method Detail

askQuestion

public abstract String askQuestion(String uri,
                                   String prompt)
Through this method you are asked a question you should answer. You can implement this by raising a dialog asking a user a question and return his answer.

Parameters:
uri - URI of a host you are trying to connect to.
prompt - a question asked by the system that needs answering.
Returns:
an answer to the given prompt or null if the authentication attempt should be halted.

getUsername

public abstract String getUsername(String uri,
                                   String prompt)
You should implement this to pass a username required by the authentication process.

Parameters:
uri - URI of a host you are trying to connect to.
prompt - explanation of what is expected as the return value
Returns:
username or null if the authentication attempt should be halted.

getPassword

public abstract char[] getPassword(String uri,
                                   String prompt)
Implement this to pass the user's password to the authentication process.

Parameters:
uri - URI of a host you are trying to connect to.
prompt - explanation of what is expected as the return value
Returns:
password or null if the authentication attempt should be halted.

getPassphrase

public abstract char[] getPassphrase(String uri,
                                     String prompt)
Implement this to pass the passphrase to unlock the private key.

Parameters:
uri - URI of a host you are trying to connect to.
prompt - explanation of what is expected as the return value
Returns:
passphrase to unlock the private key or null if the authentication attempt should be halted.
See Also:
getIdentityFile(java.lang.String, java.lang.String)

getIdentityFile

public abstract String getIdentityFile(String uri,
                                       String prompt)
If the authentication should be done via a private/public key pair instead of usual username/password, implement this method and return the absolute path to the file with the private key.

Parameters:
uri - URI of a host you are trying to connect to.
prompt - explanation of what is expected as the return value
Returns:
absolute path to the identity file with the private key or null if the authentication attempt should be halted.

askYesNoQuestion

public abstract Boolean askYesNoQuestion(String uri,
                                         String prompt)
Through this method you are asked a question you should answer Yes or No. You can implement this by raising a dialog asking a user a question and return his answer.

Parameters:
uri - URI of a host you are trying to connect to.
prompt - explanation of what is expected as the return value
Returns:
reply to the answer or null if the authentication attempt should be halted.

org.netbeans.libs.git/1 1.1

Built on May 22 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.