Java源码示例:org.eclipse.equinox.security.storage.SecurePreferencesFactory
示例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
@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();
}
示例5
/**
* 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();
}
}
示例6
/**
*
* @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();
}
}
示例7
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;
}
示例8
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$
}
}
}
示例9
private static ISecurePreferences getSecureNode() {
ISecurePreferences securePreferences = SecurePreferencesFactory.getDefault();
return securePreferences.node(NODE_PATH_NAME);
}
示例10
/**
* Initialize the preference page.
*/
public void init(IWorkbench workbench) {
secureStorage = SecurePreferencesFactory.getDefault();
}
示例11
private ISecurePreferences getSecurePreferences() {
return SecurePreferencesFactory.getDefault().node(SECURITY_NODE);
}