use of org.archicontribs.modelrepository.authentication.EncryptedCredentialsStorage in project archi-modelrepository-plugin by archi-contribs.
the class ModelRepositoryPreferencePage method performOk.
@Override
public boolean performOk() {
String name = fUserNameTextField.getText();
String email = fUserEmailTextField.getText();
try {
GraficoUtils.saveGitConfigUserDetails(name, email);
} catch (IOException | ConfigInvalidException ex) {
ex.printStackTrace();
}
getPreferenceStore().setValue(PREFS_REPOSITORY_FOLDER, fUserRepoFolderTextField.getText());
getPreferenceStore().setValue(PREFS_SSH_IDENTITY_FILE, fSSHIdentityFileTextField.getText());
getPreferenceStore().setValue(PREFS_SSH_IDENTITY_REQUIRES_PASSWORD, fSSHIdentityRequiresPasswordButton.getSelection());
getPreferenceStore().setValue(PREFS_FETCH_IN_BACKGROUND, fFetchInBackgroundButton.getSelection());
getPreferenceStore().setValue(PREFS_FETCH_IN_BACKGROUND_INTERVAL, fFetchInBackgroundIntervalSpinner.getSelection());
getPreferenceStore().setValue(PREFS_STORE_REPO_CREDENTIALS, fStoreCredentialsButton.getSelection());
getPreferenceStore().setValue(PREFS_PROXY_USE, fUseProxyButton.getSelection());
getPreferenceStore().setValue(PREFS_PROXY_HOST, fProxyHostTextField.getText());
getPreferenceStore().setValue(PREFS_PROXY_PORT, fProxyPortTextField.getText());
getPreferenceStore().setValue(PREFS_PROXY_REQUIRES_AUTHENTICATION, fRequiresProxyAuthenticationButton.getSelection());
// If "requires password" selected
if (fSSHIdentityRequiresPasswordButton.getSelection()) {
// If password changed
if (sshPasswordChanged) {
try {
EncryptedCredentialsStorage sshCredentials = getSSHCredentials();
sshCredentials.storePassword(fSSHIdentityPasswordTextField.getTextChars());
} catch (GeneralSecurityException | IOException ex) {
ex.printStackTrace();
return false;
}
}
}
// If "use proxy" selected
if (fUseProxyButton.getSelection()) {
EncryptedCredentialsStorage proxyCredentials = getProxyCredentials();
try {
// Username changed
if (proxyUsernameChanged) {
proxyCredentials.storeUserName(fProxyUserNameTextField.getText());
}
// Password changed
if (proxyPasswordChanged) {
proxyCredentials.storePassword(fProxyUserPasswordTextField.getTextChars());
}
} catch (IOException | GeneralSecurityException ex) {
ex.printStackTrace();
return false;
}
}
return true;
}
use of org.archicontribs.modelrepository.authentication.EncryptedCredentialsStorage in project archi-modelrepository-plugin by archi-contribs.
the class AbstractModelAction method getUsernamePassword.
/**
* Get user name and password from credentials file if prefs set or from dialog
*/
protected UsernamePassword getUsernamePassword() throws IOException, GeneralSecurityException {
// SSH
if (GraficoUtils.isSSH(getRepository().getOnlineRepositoryURL())) {
return null;
}
EncryptedCredentialsStorage cs = EncryptedCredentialsStorage.forRepository(getRepository());
// Is it stored?
if (cs.hasCredentialsFile()) {
return cs.getUsernamePassword();
}
// Else ask the user
UserNamePasswordDialog dialog = new UserNamePasswordDialog(fWindow.getShell(), cs);
if (dialog.open() == Window.OK) {
return new UsernamePassword(dialog.getUsername(), dialog.getPassword());
}
return null;
}
use of org.archicontribs.modelrepository.authentication.EncryptedCredentialsStorage in project archi-modelrepository-plugin by archi-contribs.
the class ModelRepositoryPreferencePage method setValues.
private void setValues() {
// Gobal user details
PersonIdent result = getUserDetails();
fUserNameTextField.setText(result.getName());
fUserEmailTextField.setText(result.getEmailAddress());
// Workspace folder
fUserRepoFolderTextField.setText(getPreferenceStore().getString(PREFS_REPOSITORY_FOLDER));
// Refresh in background
fFetchInBackgroundButton.setSelection(getPreferenceStore().getBoolean(PREFS_FETCH_IN_BACKGROUND));
fFetchInBackgroundIntervalSpinner.setSelection(getPreferenceStore().getInt(PREFS_FETCH_IN_BACKGROUND_INTERVAL));
// SSH details
fSSHIdentityFileTextField.setText(getPreferenceStore().getString(PREFS_SSH_IDENTITY_FILE));
fSSHIdentityRequiresPasswordButton.setSelection(getPreferenceStore().getBoolean(PREFS_SSH_IDENTITY_REQUIRES_PASSWORD));
try {
EncryptedCredentialsStorage sshCredentials = getSSHCredentials();
// $NON-NLS-1$ //$NON-NLS-2$
fSSHIdentityPasswordTextField.setText(sshCredentials.hasPassword() ? "********" : "");
fSSHIdentityPasswordTextField.addModifyListener(event -> {
sshPasswordChanged = true;
});
} catch (IOException ex) {
ex.printStackTrace();
}
// Store HTTP details by default
fStoreCredentialsButton.setSelection(getPreferenceStore().getBoolean(PREFS_STORE_REPO_CREDENTIALS));
// Proxy details
fUseProxyButton.setSelection(getPreferenceStore().getBoolean(PREFS_PROXY_USE));
fProxyHostTextField.setText(getPreferenceStore().getString(PREFS_PROXY_HOST));
fProxyPortTextField.setText(getPreferenceStore().getString(PREFS_PROXY_PORT));
fRequiresProxyAuthenticationButton.setSelection(getPreferenceStore().getBoolean(PREFS_PROXY_REQUIRES_AUTHENTICATION));
try {
EncryptedCredentialsStorage proxyCredentials = getProxyCredentials();
fProxyUserNameTextField.setText(proxyCredentials.getUserName());
// $NON-NLS-1$ //$NON-NLS-2$
fProxyUserPasswordTextField.setText(proxyCredentials.hasPassword() ? "********" : "");
fProxyUserNameTextField.addModifyListener(event -> {
proxyUsernameChanged = true;
});
fProxyUserPasswordTextField.addModifyListener(event -> {
proxyPasswordChanged = true;
});
} catch (IOException ex) {
ex.printStackTrace();
}
updateIdentityControls();
updateProxyControls();
}
use of org.archicontribs.modelrepository.authentication.EncryptedCredentialsStorage in project archi-modelrepository-plugin by archi-contribs.
the class FetchJob method run.
@Override
protected IStatus run(IProgressMonitor monitor) {
// Check first thing on entry
if (!canRun()) {
return Status.OK_STATUS;
}
boolean needsRefresh = false;
for (IArchiRepository repo : fViewer.getRepositories(fViewer.getRootFolder())) {
// Check also in for loop
if (!canRun()) {
return Status.OK_STATUS;
}
try {
UsernamePassword npw = null;
String url = repo.getOnlineRepositoryURL();
if (GraficoUtils.isHTTP(url)) {
// Get credentials. In some public repos we can still fetch without needing a password so we try anyway
EncryptedCredentialsStorage cs = EncryptedCredentialsStorage.forRepository(repo);
npw = cs.getUsernamePassword();
}
// Update ProxyAuthenticator
ProxyAuthenticator.update();
// Fetch
FetchResult fetchResult = repo.fetchFromRemote(npw, null, false);
// We got here, so the tree can be refreshed later
needsRefresh = true;
// Remote branches might have been deleted or added
if (!fetchResult.getTrackingRefUpdates().isEmpty() && !fViewer.getControl().isDisposed()) {
fViewer.getControl().getDisplay().asyncExec(() -> {
RepositoryListenerManager.INSTANCE.fireRepositoryChangedEvent(IRepositoryListener.BRANCHES_CHANGED, repo);
});
}
} catch (IOException | GitAPIException ex) {
ex.printStackTrace();
if (ex instanceof TransportException) {
disablePreference();
// Show message
Display.getDefault().syncExec(() -> {
// $NON-NLS-1$
String message = Messages.FetchJob_0 + " ";
// $NON-NLS-1$
message += Messages.FetchJob_1 + "\n\n";
try {
// $NON-NLS-1$
message += repo.getName() + "\n";
// $NON-NLS-1$
message += repo.getOnlineRepositoryURL() + "\n";
} catch (IOException ex1) {
ex1.printStackTrace();
}
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.FetchJob_2, message);
});
return Status.OK_STATUS;
}
}// Encrypted password key error
catch (GeneralSecurityException ex) {
ex.printStackTrace();
// Disable background fetch
disablePreference();
Display.getDefault().syncExec(() -> {
// $NON-NLS-1$
String message = Messages.FetchJob_0 + "\n";
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.FetchJob_2, message + ex.getMessage());
});
return Status.OK_STATUS;
} finally {
// Clear ProxyAuthenticator
ProxyAuthenticator.clear();
}
}
if (needsRefresh) {
fViewer.refreshInBackground();
}
if (canRun()) {
int seconds = ModelRepositoryPlugin.INSTANCE.getPreferenceStore().getInt(IPreferenceConstants.PREFS_FETCH_IN_BACKGROUND_INTERVAL);
// Schedule again in x milliseconds if possible
schedule(seconds * 1000);
}
return Status.OK_STATUS;
}
use of org.archicontribs.modelrepository.authentication.EncryptedCredentialsStorage in project archi-modelrepository-plugin by archi-contribs.
the class AuthSection method updateControls.
private void updateControls() {
// $NON-NLS-1$
textUserName.setText("");
// $NON-NLS-1$
textPassword.setText("");
try {
// Is this HTTP or SSH?
boolean isHTTP = GraficoUtils.isHTTP(fRepository.getOnlineRepositoryURL());
textUserName.setEnabled(isHTTP);
textPassword.setEnabled(isHTTP);
prefsButton.setEnabled(!isHTTP);
// HTTP so show credentials
if (isHTTP) {
EncryptedCredentialsStorage credentials = getCredentials();
textUserName.setText(credentials.getUserName());
if (credentials.hasPassword()) {
// $NON-NLS-1$
textPassword.setText("********");
}
}
} catch (IOException ex) {
showError(ex);
}
}
Aggregations