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

The following examples show how to use org.eclipse.equinox.security.storage.StorageException. 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: KeystoreGenerationPreferences.java    From balzac with Apache License 2.0 6 votes vote down vote up
@Override
public boolean performOk() {

    // store
    if (!repeatPasswordText.getText().isEmpty()) {
        try {
            secureStorage.node(SecureStorageUtils.SECURE_STORAGE__NODE__KEYSTORE).put(
                SecureStorageUtils.SECURE_STORAGE__PROPERTY__KEYSTORE_PASSWORD, repeatPasswordText.getText(), true);
        } catch (StorageException e) {
            e.printStackTrace();
            this.setErrorMessage("An error occurred reading the secure storage");
            return false;
        }
    }

    return true;
}
 
Example #5
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 #6
Source File: CredentialStore.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
/**
 * @return the stored password or <code>null</code>
 * @throws ConfigurationException
 */
public String getPassword() throws ConfigurationException {
	try {
		return getSecureNode().get(KEY_PASSWORD, ""); //$NON-NLS-1$
	} catch (StorageException e) {
		throw LogUtil.throwing(new ConfigurationException("StorageException while getting password.", e));
	}
}
 
Example #7
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getLong(String key, long def) throws StorageException {
  checkGetOperation();

  Object object = preferences.get(key);

  if (object == null) return def;

  try {
    return (Long) object;
  } catch (Exception e) {
    throw new StorageException(StorageException.INTERNAL_ERROR, e);
  }
}
 
Example #8
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getInt(String key, int def) throws StorageException {
  checkGetOperation();

  Object object = preferences.get(key);

  if (object == null) return def;

  try {
    return (Integer) object;
  } catch (Exception e) {
    throw new StorageException(StorageException.INTERNAL_ERROR, e);
  }
}
 
Example #9
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public float getFloat(String key, float def) throws StorageException {
  checkGetOperation();

  Object object = preferences.get(key);

  if (object == null) return def;

  try {
    return (Float) object;
  } catch (Exception e) {
    throw new StorageException(StorageException.INTERNAL_ERROR, e);
  }
}
 
Example #10
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public double getDouble(String key, double def) throws StorageException {
  checkGetOperation();

  Object object = preferences.get(key);

  if (object == null) return def;

  try {
    return (Double) object;
  } catch (Exception e) {
    throw new StorageException(StorageException.INTERNAL_ERROR, e);
  }
}
 
Example #11
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] getByteArray(String key, byte[] def) throws StorageException {
  checkGetOperation();

  Object object = preferences.get(key);

  if (object == null) return def;

  try {
    return (byte[]) object;
  } catch (Exception e) {
    throw new StorageException(StorageException.INTERNAL_ERROR, e);
  }
}
 
Example #12
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean getBoolean(String key, boolean def) throws StorageException {
  checkGetOperation();

  Object object = preferences.get(key);

  if (object == null) return def;

  try {
    return (Boolean) object;
  } catch (Exception e) {
    throw new StorageException(StorageException.INTERNAL_ERROR, e);
  }
}
 
Example #13
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String get(String key, String def) throws StorageException {
  checkGetOperation();

  Object object = preferences.get(key);

  if (object == null) return def;

  try {
    return (String) object;
  } catch (Exception e) {
    throw new StorageException(StorageException.INTERNAL_ERROR, e);
  }
}
 
Example #14
Source File: PreferencePage.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public static void setSecurePreference(String key, String value) {
    try {
        if (StringUtil.isEmpty(value)) {
            SecurePreferencesFactory.getDefault().remove(key);                     
        } else {
            SecurePreferencesFactory.getDefault().put(key, value, true);                
        }
    } catch (StorageException e) {
        if (BluemixLogger.BLUEMIX_LOGGER.isErrorEnabled()) {
            BluemixLogger.BLUEMIX_LOGGER.errorp(PreferencePage.class, "setSecurePreference", e, "Error setting Secure Preference {0}", key); // $NON-NLS-1$ $NLE-PreferencePage.ErrorsettingSecurePreference0-2$
        }
    }
}
 
Example #15
Source File: PreferencePage.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public static String getSecurePreference(String key, String def) {
    try {
        return SecurePreferencesFactory.getDefault().get(key, def);
    } catch (StorageException e) {
        if (BluemixLogger.BLUEMIX_LOGGER.isErrorEnabled()) {
            BluemixLogger.BLUEMIX_LOGGER.errorp(PreferencePage.class, "getSecurePreference", e, "Error getting Secure Preference {0}", key); // $NON-NLS-1$ $NLE-PreferencePage.ErrorgettingSecurePreference0-2$
        }
    }        
    return def;
}
 
Example #16
Source File: CredentialStore.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
/**
 * @param password the password to store
 * @throws ConfigurationException
 */
public void setPassword(String password) throws ConfigurationException {
	try {
		getSecureNode().put(KEY_PASSWORD, password, true);
	} catch (StorageException e) {
		throw LogUtil.throwing(new ConfigurationException("StorageException while setting password.", e));
	}
}
 
Example #17
Source File: CredentialStore.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
/**
 * @param username the username to store
 * @throws ConfigurationException
 */
public void setUsername(String username) throws ConfigurationException {
	try {
		getSecureNode().put(KEY_USERNAME, username, false);
	} catch (StorageException e) {
		throw LogUtil.throwing(new ConfigurationException("StorageException while setting username.", e));
	}
}
 
Example #18
Source File: CredentialStore.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
/**
 * @return the stored username or <code>null</code>
 * @throws ConfigurationException
 */
public String getUsername() throws ConfigurationException {
	try {
		return getSecureNode().get(KEY_USERNAME, ""); //$NON-NLS-1$
	} catch (StorageException e) {
		throw LogUtil.throwing(new ConfigurationException("StorageException while getting username.", e));
	}
}
 
Example #19
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
public void checkPutOperation() throws StorageException {
  if (!this.allowPut)
    throw new StorageException(
        StorageException.INTERNAL_ERROR, new IllegalStateException("put disabled"));
}
 
Example #20
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
public void checkGetOperation() throws StorageException {
  if (!this.allowGet)
    throw new StorageException(
        StorageException.INTERNAL_ERROR, new IllegalStateException("get disabled"));
}
 
Example #21
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isEncrypted(String key) throws StorageException {
  return true;
}
 
Example #22
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void put(String key, String value, boolean encrypt) throws StorageException {
  checkPutOperation();
  preferences.put(key, value);
}
 
Example #23
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void putBoolean(String key, boolean value, boolean encrypt) throws StorageException {
  checkPutOperation();
  preferences.put(key, value);
}
 
Example #24
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void putByteArray(String key, byte[] value, boolean encrypt) throws StorageException {
  checkPutOperation();
  preferences.put(key, value);
}
 
Example #25
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void putDouble(String key, double value, boolean encrypt) throws StorageException {
  checkPutOperation();
  preferences.put(key, value);
}
 
Example #26
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void putFloat(String key, float value, boolean encrypt) throws StorageException {
  checkPutOperation();
  preferences.put(key, value);
}
 
Example #27
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void putInt(String key, int value, boolean encrypt) throws StorageException {
  checkPutOperation();
  preferences.put(key, value);
}
 
Example #28
Source File: MemorySecurePreferences.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void putLong(String key, long value, boolean encrypt) throws StorageException {
  checkPutOperation();
  preferences.put(key, value);
}