Java源码示例:org.eclipse.equinox.security.storage.StorageException
示例1
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;
}
示例2
/**
*
* @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));
}
}
}
示例3
/**
*
* @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;
}
示例4
@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;
}
示例5
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;
}
示例6
/**
* @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));
}
}
示例7
/**
* @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));
}
}
示例8
/**
* @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));
}
}
示例9
/**
* @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));
}
}
示例10
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;
}
示例11
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$
}
}
}
示例12
@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);
}
}
示例13
@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);
}
}
示例14
@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);
}
}
示例15
@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);
}
}
示例16
@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);
}
}
示例17
@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);
}
}
示例18
@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);
}
}
示例19
public void checkGetOperation() throws StorageException {
if (!this.allowGet)
throw new StorageException(
StorageException.INTERNAL_ERROR, new IllegalStateException("get disabled"));
}
示例20
public void checkPutOperation() throws StorageException {
if (!this.allowPut)
throw new StorageException(
StorageException.INTERNAL_ERROR, new IllegalStateException("put disabled"));
}
示例21
@Override
public boolean isEncrypted(String key) throws StorageException {
return true;
}
示例22
@Override
public void put(String key, String value, boolean encrypt) throws StorageException {
checkPutOperation();
preferences.put(key, value);
}
示例23
@Override
public void putBoolean(String key, boolean value, boolean encrypt) throws StorageException {
checkPutOperation();
preferences.put(key, value);
}
示例24
@Override
public void putByteArray(String key, byte[] value, boolean encrypt) throws StorageException {
checkPutOperation();
preferences.put(key, value);
}
示例25
@Override
public void putDouble(String key, double value, boolean encrypt) throws StorageException {
checkPutOperation();
preferences.put(key, value);
}
示例26
@Override
public void putFloat(String key, float value, boolean encrypt) throws StorageException {
checkPutOperation();
preferences.put(key, value);
}
示例27
@Override
public void putInt(String key, int value, boolean encrypt) throws StorageException {
checkPutOperation();
preferences.put(key, value);
}
示例28
@Override
public void putLong(String key, long value, boolean encrypt) throws StorageException {
checkPutOperation();
preferences.put(key, value);
}