Search in sources :

Example 1 with UserNamePasswordDialog

use of org.archicontribs.modelrepository.dialogs.UserNamePasswordDialog in project archi-modelrepository-plugin by archi-contribs.

the class AbstractModelAction method getUserNameAndPasswordFromCredentialsFileOrDialog.

/**
 * Get user name and password from credentials file if prefs set or from dialog
 * @param storageFileName
 * @param shell
 * @return the username and password, or null
 */
protected UsernamePassword getUserNameAndPasswordFromCredentialsFileOrDialog(Shell shell) {
    boolean doStoreInCredentialsFile = ModelRepositoryPlugin.INSTANCE.getPreferenceStore().getBoolean(IPreferenceConstants.PREFS_STORE_REPO_CREDENTIALS);
    SimpleCredentialsStorage scs = new SimpleCredentialsStorage(new File(getRepository().getLocalGitFolder(), IGraficoConstants.REPO_CREDENTIALS_FILE));
    // Is it stored?
    if (doStoreInCredentialsFile && scs.hasCredentialsFile()) {
        try {
            return new UsernamePassword(scs.getUsername(), scs.getPassword());
        } catch (IOException ex) {
            displayErrorDialog(Messages.AbstractModelAction_9, ex);
        }
    }
    // Else ask the user
    UserNamePasswordDialog dialog = new UserNamePasswordDialog(shell, scs);
    if (dialog.open() == Window.OK) {
        return new UsernamePassword(dialog.getUsername(), dialog.getPassword());
    }
    return null;
}
Also used : SimpleCredentialsStorage(org.archicontribs.modelrepository.authentication.SimpleCredentialsStorage) IOException(java.io.IOException) File(java.io.File) UserNamePasswordDialog(org.archicontribs.modelrepository.dialogs.UserNamePasswordDialog) UsernamePassword(org.archicontribs.modelrepository.authentication.UsernamePassword)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 SimpleCredentialsStorage (org.archicontribs.modelrepository.authentication.SimpleCredentialsStorage)1 UsernamePassword (org.archicontribs.modelrepository.authentication.UsernamePassword)1 UserNamePasswordDialog (org.archicontribs.modelrepository.dialogs.UserNamePasswordDialog)1