org.eclipse.equinox.security.storage.ISecurePreferences Java Examples

The following examples show how to use org.eclipse.equinox.security.storage.ISecurePreferences. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbapGitWizardPageRepositoryAndCredentials.java    From ADT_Frontend with MIT License 6 votes vote down vote up
private static IExternalRepositoryInfoRequest getRepoCredentialsFromSecureStorage(String url) {
	if (url == null) {
		return null;
	}
	ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
	String slashEncodedURL = GitCredentialsService.getUrlForNodePath(url);
	if (slashEncodedURL != null && preferences.nodeExists(slashEncodedURL)) {
		ISecurePreferences node = preferences.node(slashEncodedURL);

		IExternalRepositoryInfoRequest credentials = AbapgitexternalrepoFactoryImpl.eINSTANCE.createExternalRepositoryInfoRequest();

		try {
			credentials.setUser(node.get("user", null)); //$NON-NLS-1$
			credentials.setPassword(node.get("password", null)); //$NON-NLS-1$
		} catch (StorageException e) {
			AbapGitUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, AbapGitUIPlugin.PLUGIN_ID, e.getMessage(), e));
		}
		credentials.setUrl(url);
		return credentials;
	}
	return null;
}
 
Example #2
Source File: GitCredentialsService.java    From ADT_Frontend with MIT License 6 votes vote down vote up
/**
 *
 * @param repositoryCredentials
 * @param repositoryURL
 *            store repositoryCredentials in Secure Store for the given
 *            repositoryURL
 */
public static void storeCredentialsInSecureStorage(IExternalRepositoryInfoRequest repositoryCredentials, String repositoryURL) {
	if (repositoryCredentials != null && repositoryURL != null) {
		String hashedURL = getUrlForNodePath(repositoryURL);

		//Disable security questions
		Map<String, Boolean> options = new HashMap<String, Boolean>();
		options.put(IProviderHints.PROMPT_USER, false);

		try {
			ISecurePreferences preferences = SecurePreferencesFactory.open(null, options);
			if (preferences != null && hashedURL != null) {
				ISecurePreferences node = preferences.node(hashedURL);
				node.put("user", repositoryCredentials.getUser(), false); //$NON-NLS-1$
				node.put("password", repositoryCredentials.getPassword(), true); //$NON-NLS-1$
			}
		} catch (IOException | StorageException e) {
			AbapGitUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, AbapGitUIPlugin.PLUGIN_ID, e.getMessage(), e));
		}
	}

}
 
Example #3
Source File: GitCredentialsService.java    From ADT_Frontend with MIT License 6 votes vote down vote up
/**
 *
 * @param repositoryURL
 * @return the credentials from Secure Store for the given repository url
 */

private static IExternalRepositoryInfoRequest getRepoCredentialsFromSecureStorage(String repositoryURL) {
	if (repositoryURL == null) {
		return null;
	}
	ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
	String slashEncodedURL = getUrlForNodePath(repositoryURL);
	if (slashEncodedURL != null && preferences.nodeExists(slashEncodedURL)) {
		ISecurePreferences node = preferences.node(slashEncodedURL);
		IExternalRepositoryInfoRequest credentials = AbapgitexternalrepoFactoryImpl.eINSTANCE.createExternalRepositoryInfoRequest();

		try {
			credentials.setUser(node.get("user", null)); //$NON-NLS-1$
			credentials.setPassword(node.get("password", null)); //$NON-NLS-1$
		} catch (StorageException e) {
			AbapGitUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, AbapGitUIPlugin.PLUGIN_ID, e.getMessage(), e));
		}
		credentials.setUrl(repositoryURL);
		return credentials;
	}

	return null;
}
 
Example #4
Source File: AuthenticationManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public char[] getPassword(String authId) {
	ISecurePreferences preferences = getSecurePreferences();
	if (preferences.nodeExists(authId)) {
		try {
			ISecurePreferences node = preferences.node(authId);
			String password = node.get(PROP_PASSWORD, null);
			if (password != null) {
				return password.toCharArray();
			}
		} catch (StorageException e) {
			IdeLog.logWarning(CoreIOPlugin.getDefault(), Messages.AuthenticationManager_FailedGetSecurePreference, e);
		}
	}
	if (sessionPasswords.containsKey(authId)) {
		return sessionPasswords.get(authId);
	}
	return null;
}
 
Example #5
Source File: AuthenticationManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void setPassword(String authId, char[] password, boolean persistent) {
	ISecurePreferences node = getSecurePreferences().node(authId);
	try {
		sessionPasswords.remove(authId);
		if (password != null) {
			sessionPasswords.put(authId, password);
			if (persistent) {
				node.put(PROP_PASSWORD, String.copyValueOf(password), true);
			} else {
				node.removeNode();
			}
		}
		getSecurePreferences().flush();
	} catch (Exception e) {
		IdeLog.logWarning(CoreIOPlugin.getDefault(), Messages.AuthenticationManager_FailedSaveSecurePreference, e);
	}
}
 
Example #6
Source File: HandlerDeletePasswordCache.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
@Execute
public void execute(Shell shell) {
	LogUtil.entering(shell);

	URL location = InternalExchangeUtils.defaultStorageLocation();
	if (location == null) {
		LOGGER.info("location is null."); //$NON-NLS-1$
		LogUtil.exiting();
		return;
	}

	MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO);
	messageBox.setText(SecUIMessages.generalDialogTitle);
	messageBox.setMessage(SecUIMessages.confirmDeleteMsg);
	if (messageBox.open() != SWT.YES) {
		LogUtil.exiting();
		return;
	}

	// clear the data structure itself in case somebody holds on to it
	ISecurePreferences defaultStorage = SecurePreferencesFactory.getDefault();
	defaultStorage.clear();
	defaultStorage.removeNode();

	// clear it from the list of open storages, delete the file
	InternalExchangeUtils.defaultStorageDelete();

	// suggest restart in case somebody holds on to the deleted storage
	MessageBox postDeletionBox = new MessageBox(shell, SWT.YES | SWT.NO);
	postDeletionBox.setText(SecUIMessages.generalDialogTitle);
	postDeletionBox.setMessage(SecUIMessages.postDeleteMsg);
	int result = postDeletionBox.open();
	if (result == SWT.YES) {
		PlatformUI.getWorkbench().restart();
	}
	LogUtil.exiting();
}
 
Example #7
Source File: RemoteConfigurationType.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Removes the authentication info from the session cache.
 *
 * @param resolvedCheckConfigurationURL
 *          the check configuration URL
 * @throws CheckstylePluginException
 *           if the authentication could not be removed
 */
public static void removeCachedAuthInfo(URL resolvedCheckConfigurationURL)
        throws CheckstylePluginException {
  sFailedWith401URLs.remove(resolvedCheckConfigurationURL.toString());

  String storagePath = getSecureStoragePath(resolvedCheckConfigurationURL);

  if (SecurePreferencesFactory.getDefault().nodeExists(storagePath)) {

    ISecurePreferences prefs = SecurePreferencesFactory.getDefault()
            .node(getSecureStoragePath(resolvedCheckConfigurationURL));
    prefs.removeNode();
  }
}
 
Example #8
Source File: GitCredentialsService.java    From ADT_Frontend with MIT License 5 votes vote down vote up
/**
 *
 * @param repositoryURL
 *            delete credentials for the given repository url from Secure
 *            Store, if they already exist in the Secure Store.
 */
public static void deleteCredentialsFromSecureStorage(String repositoryURL) {
	if (repositoryURL == null) {
		return;
	}
	ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
	String hashedURL = getUrlForNodePath(repositoryURL);
	if (hashedURL != null && preferences.nodeExists(hashedURL)) {
		ISecurePreferences node = preferences.node(hashedURL);
		node.removeNode();
	}
}
 
Example #9
Source File: AuthenticationManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public boolean hasPersistent(String authId) {
	ISecurePreferences preferences = getSecurePreferences();
	if (preferences.nodeExists(authId)) {
		ISecurePreferences node = preferences.node(authId);
		return Arrays.asList(node.keys()).contains(PROP_PASSWORD);
	}
	return false;
}
 
Example #10
Source File: AuthenticationManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void resetPassword(String authId) {
	ISecurePreferences preferences = getSecurePreferences();
	if (preferences.nodeExists(authId)) {
		ISecurePreferences node = preferences.node(authId);
		node.removeNode();
	}
	sessionPasswords.remove(authId);
}
 
Example #11
Source File: CredentialStore.java    From MergeProcessor with Apache License 2.0 4 votes vote down vote up
private static ISecurePreferences getSecureNode() {
	ISecurePreferences securePreferences = SecurePreferencesFactory.getDefault();
	return securePreferences.node(NODE_PATH_NAME);
}
 
Example #12
Source File: KeystoreGenerationPreferences.java    From balzac with Apache License 2.0 4 votes vote down vote up
private boolean isPasswordSaved() {
    ISecurePreferences node = secureStorage.node(SecureStorageUtils.SECURE_STORAGE__NODE__KEYSTORE);
    return Arrays.asList(node.keys()).contains(SecureStorageUtils.SECURE_STORAGE__PROPERTY__KEYSTORE_PASSWORD);
}
 
Example #13
Source File: AuthenticationManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private ISecurePreferences getSecurePreferences() {
	return SecurePreferencesFactory.getDefault().node(SECURITY_NODE);
}
 
Example #14
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ISecurePreferences node(String name) {
  throw new UnsupportedOperationException();
}
 
Example #15
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ISecurePreferences parent() {
  throw new UnsupportedOperationException();
}