use of org.eclipse.equinox.security.storage.ISecurePreferences in project dbeaver by serge-rider.
the class DataSourceSerializerModern method readSecuredCredentials.
private SecureCredentials readSecuredCredentials(@Nullable DataSourceDescriptor dataSource, @Nullable DBPConfigurationProfile profile, @Nullable String subNode) {
assert dataSource != null || profile != null;
SecureCredentials creds = new SecureCredentials();
final DBASecureStorage secureStorage = dataSource == null ? registry.getProject().getSecureStorage() : dataSource.getProject().getSecureStorage();
{
try {
if (secureStorage.useSecurePreferences()) {
ISecurePreferences prefNode = dataSource == null ? secureStorage.getSecurePreferences() : dataSource.getSecurePreferences();
if (subNode != null) {
for (String nodeName : subNode.split("/")) {
prefNode = prefNode.node(nodeName);
}
}
for (String key : prefNode.keys()) {
switch(key) {
case RegistryConstants.ATTR_USER:
creds.setUserName(prefNode.get(key, null));
break;
case RegistryConstants.ATTR_PASSWORD:
creds.setUserPassword(prefNode.get(key, null));
break;
default:
creds.setSecureProp(key, prefNode.get(key, null));
break;
}
}
}
} catch (Throwable e) {
// Most likely user canceled master password enter of failed by some other reason.
// Anyhow we won't try it again
log.error("Can't read password from secure storage", e);
passwordReadCanceled = true;
}
}
String topNodeId = profile != null ? "profile:" + profile.getProfileId() : dataSource.getId();
if (subNode == null)
subNode = NODE_CONNECTION;
Map<String, Map<String, String>> subMap = secureProperties.get(topNodeId);
if (subMap != null) {
Map<String, String> propMap = subMap.get(subNode);
if (propMap != null) {
for (Map.Entry<String, String> prop : propMap.entrySet()) {
switch(prop.getKey()) {
case RegistryConstants.ATTR_USER:
creds.setUserName(prop.getValue());
break;
case RegistryConstants.ATTR_PASSWORD:
creds.setUserPassword(prop.getValue());
break;
default:
creds.setSecureProp(prop.getKey(), prop.getValue());
break;
}
}
}
}
return creds;
}
use of org.eclipse.equinox.security.storage.ISecurePreferences in project generator by mybatis.
the class LauncherUtils method getSecurePreferencesNode.
private static ISecurePreferences getSecurePreferencesNode() {
ISecurePreferences root = SecurePreferencesFactory.getDefault();
// $NON-NLS-1$
ISecurePreferences node = root.node("/org.mybatis.generator/sqlscript");
return node;
}
use of org.eclipse.equinox.security.storage.ISecurePreferences in project generator by mybatis.
the class LauncherUtils method getPassword.
public static String getPassword(ILaunchConfiguration configuration) {
boolean secure = getBooleanOrFalse(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_SECURE_CREDENTIALS);
String password;
if (secure) {
ISecurePreferences node = getSecurePreferencesNode();
// $NON-NLS-1$
password = getTextOrBlank(node, "password");
} else {
password = getTextOrBlank(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_PASSWORD);
}
return password;
}
use of org.eclipse.equinox.security.storage.ISecurePreferences in project hale by halestudio.
the class PreferenceInitializer method initializeDefaultPreferences.
/**
* @see AbstractPreferenceInitializer#initializeDefaultPreferences()
*/
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = UIUtilitiesPlugin.getDefault().getPreferenceStore();
// configure proxy host
String proxyHost = System.getProperty(PreferenceConstants.CONNECTION_PROXY_HOST);
if (proxyHost == null) {
// $NON-NLS-1$
proxyHost = "";
}
store.setDefault(PreferenceConstants.CONNECTION_PROXY_HOST, proxyHost);
// configure proxy port
String proxyPortStr = System.getProperty(PreferenceConstants.CONNECTION_PROXY_PORT);
int proxyPort = 8080;
if (proxyPortStr != null && !proxyPortStr.isEmpty()) {
proxyPort = Integer.parseInt(proxyPortStr);
}
store.setDefault(PreferenceConstants.CONNECTION_PROXY_PORT, proxyPort);
// configure proxy user
String proxyUser = System.getProperty(CONNECTION_PROXY_USER);
if (proxyUser == null) {
// $NON-NLS-1$
proxyUser = "";
}
store.setDefault(CONNECTION_PROXY_USER, proxyUser);
// configure proxy user
ISecurePreferences secPref = SecurePreferencesFactory.getDefault();
String proxyPassword = System.getProperty(CONNECTION_PROXY_PASSWORD);
try {
if (proxyPassword != null && secPref.node(SECURE_NODE_NAME).get(CONNECTION_PROXY_PASSWORD, null) == null) {
secPref.node(SECURE_NODE_NAME).put(CONNECTION_PROXY_PASSWORD, proxyPassword, true);
}
} catch (StorageException e) {
// $NON-NLS-1$
log.warn("Error accessing secure preferences");
}
// configure non proxy hosts
String nonProxyHosts = System.getProperty(PreferenceConstants.CONNECTION_NON_PROXY_HOSTS);
if (nonProxyHosts == null) {
// $NON-NLS-1$
nonProxyHosts = "";
}
store.setDefault(PreferenceConstants.CONNECTION_NON_PROXY_HOSTS, nonProxyHosts);
}
use of org.eclipse.equinox.security.storage.ISecurePreferences in project dbeaver by dbeaver.
the class DataSourceSerializerModern method readSecuredCredentials.
private SecureCredentials readSecuredCredentials(@Nullable DataSourceDescriptor dataSource, @Nullable DBPConfigurationProfile profile, @Nullable String subNode) {
assert dataSource != null || profile != null;
SecureCredentials creds = new SecureCredentials();
final DBASecureStorage secureStorage = dataSource == null ? registry.getProject().getSecureStorage() : dataSource.getProject().getSecureStorage();
{
try {
if (secureStorage.useSecurePreferences()) {
ISecurePreferences prefNode = dataSource == null ? secureStorage.getSecurePreferences() : dataSource.getSecurePreferences();
if (subNode != null) {
for (String nodeName : subNode.split("/")) {
prefNode = prefNode.node(nodeName);
}
}
for (String key : prefNode.keys()) {
switch(key) {
case RegistryConstants.ATTR_USER:
creds.setUserName(prefNode.get(key, null));
break;
case RegistryConstants.ATTR_PASSWORD:
creds.setUserPassword(prefNode.get(key, null));
break;
default:
creds.setSecureProp(key, prefNode.get(key, null));
break;
}
}
}
} catch (Throwable e) {
// Most likely user canceled master password enter of failed by some other reason.
// Anyhow we won't try it again
log.error("Can't read password from secure storage", e);
passwordReadCanceled = true;
}
}
String topNodeId = profile != null ? "profile:" + profile.getProfileId() : dataSource.getId();
if (subNode == null)
subNode = NODE_CONNECTION;
Map<String, Map<String, String>> subMap = secureProperties.get(topNodeId);
if (subMap != null) {
Map<String, String> propMap = subMap.get(subNode);
if (propMap != null) {
for (Map.Entry<String, String> prop : propMap.entrySet()) {
switch(prop.getKey()) {
case RegistryConstants.ATTR_USER:
creds.setUserName(prop.getValue());
break;
case RegistryConstants.ATTR_PASSWORD:
creds.setUserPassword(prop.getValue());
break;
default:
creds.setSecureProp(prop.getKey(), prop.getValue());
break;
}
}
}
}
return creds;
}
Aggregations