Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
4e6f68b5
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4e6f68b5
编写于
12月 03, 2016
作者:
S
Serge Rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#1005 Secure passwords storage
上级
2093271c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
26 deletion
+50
-26
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceRegistry.java
...re/src/org/jkiss/dbeaver/registry/DataSourceRegistry.java
+50
-26
未找到文件。
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceRegistry.java
浏览文件 @
4e6f68b5
...
...
@@ -498,6 +498,8 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
private
void
saveDataSource
(
XMLBuilder
xml
,
DataSourceDescriptor
dataSource
)
throws
IOException
{
clearSecuredPasswords
(
dataSource
);
xml
.
startElement
(
RegistryConstants
.
TAG_DATA_SOURCE
);
xml
.
addAttribute
(
RegistryConstants
.
ATTR_ID
,
dataSource
.
getId
());
xml
.
addAttribute
(
RegistryConstants
.
ATTR_PROVIDER
,
dataSource
.
getDriver
().
getProviderDescriptor
().
getId
());
...
...
@@ -541,7 +543,6 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
xml
.
addAttribute
(
RegistryConstants
.
ATTR_URL
,
CommonUtils
.
notEmpty
(
connectionInfo
.
getUrl
()));
xml
.
addAttribute
(
RegistryConstants
.
ATTR_USER
,
CommonUtils
.
notEmpty
(
connectionInfo
.
getUserName
()));
clearSecuredPassword
(
dataSource
,
null
);
if
(
dataSource
.
isSavePassword
()
&&
!
CommonUtils
.
isEmpty
(
connectionInfo
.
getUserPassword
()))
{
saveSecuredPassword
(
xml
,
dataSource
,
null
,
connectionInfo
.
getUserPassword
());
}
...
...
@@ -592,7 +593,7 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
xml
.
addAttribute
(
RegistryConstants
.
ATTR_ENABLED
,
configuration
.
isEnabled
());
xml
.
addAttribute
(
RegistryConstants
.
ATTR_USER
,
CommonUtils
.
notEmpty
(
configuration
.
getUserName
()));
xml
.
addAttribute
(
RegistryConstants
.
ATTR_SAVE_PASSWORD
,
configuration
.
isSavePassword
());
if
(
configuration
.
isSavePassword
())
{
if
(
configuration
.
isSavePassword
()
&&
!
CommonUtils
.
isEmpty
(
configuration
.
getPassword
())
)
{
saveSecuredPassword
(
xml
,
dataSource
,
"network/"
+
configuration
.
getId
(),
configuration
.
getPassword
());
}
for
(
Map
.
Entry
<
String
,
String
>
entry
:
configuration
.
getProperties
().
entrySet
())
{
...
...
@@ -701,6 +702,7 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
prefNode
=
prefNode
.
node
(
nodeName
);
}
}
prefNode
.
put
(
"name"
,
dataSource
.
getName
(),
false
);
if
(!
CommonUtils
.
isEmpty
(
password
))
{
prefNode
.
put
(
RegistryConstants
.
ATTR_PASSWORD
,
password
,
true
);
saved
=
true
;
...
...
@@ -721,8 +723,23 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
}
}
private
void
clearSecuredPassword
(
DataSourceDescriptor
dataSource
,
String
subNode
)
{
private
void
clearSecuredPasswords
(
DataSourceDescriptor
dataSource
)
{
dataSource
.
getSecurePreferences
().
removeNode
();
}
@Nullable
private
static
String
decryptPassword
(
String
encPassword
)
{
if
(!
CommonUtils
.
isEmpty
(
encPassword
))
{
try
{
encPassword
=
ENCRYPTOR
.
decrypt
(
encPassword
);
}
catch
(
Throwable
e
)
{
// could not decrypt - use as is
encPassword
=
null
;
}
}
return
encPassword
;
}
private
void
saveObjectFiler
(
XMLBuilder
xml
,
String
typeName
,
String
objectID
,
DBSObjectFilter
filter
)
throws
IOException
...
...
@@ -776,6 +793,7 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
private
DBSObjectFilter
curFilter
;
private
StringBuilder
curQuery
;
private
ParseResults
parseResults
;
private
boolean
passwordReadCanceled
=
false
;
private
DataSourcesParser
(
boolean
extraConfig
,
boolean
refresh
,
ParseResults
parseResults
)
{
...
...
@@ -887,20 +905,9 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
config
.
setDatabaseName
(
atts
.
getValue
(
RegistryConstants
.
ATTR_DATABASE
));
config
.
setUrl
(
atts
.
getValue
(
RegistryConstants
.
ATTR_URL
));
config
.
setUserName
(
atts
.
getValue
(
RegistryConstants
.
ATTR_USER
));
/*
final ISecurePreferences dsNode = curDataSource.getSecurePreferences();
try {
final String password = dsNode.get(RegistryConstants.ATTR_PASSWORD, null);
if (password != null) {
config.setUserPassword(password);
}
} catch (StorageException e) {
log.error("Can't get password in secure storage", e);
if
(!
passwordReadCanceled
)
{
config
.
setUserPassword
(
readSecuredPassword
(
atts
,
curDataSource
,
null
));
}
*/
config
.
setUserPassword
(
decryptPassword
(
atts
.
getValue
(
RegistryConstants
.
ATTR_PASSWORD
)));
config
.
setClientHomeId
(
atts
.
getValue
(
RegistryConstants
.
ATTR_HOME
));
config
.
setConnectionType
(
DataSourceProviderRegistry
.
getInstance
().
getConnectionType
(
...
...
@@ -1008,6 +1015,10 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
curNetworkHandler
.
setEnabled
(
CommonUtils
.
getBoolean
(
atts
.
getValue
(
RegistryConstants
.
ATTR_ENABLED
)));
curNetworkHandler
.
setUserName
(
CommonUtils
.
notEmpty
(
atts
.
getValue
(
RegistryConstants
.
ATTR_USER
)));
curNetworkHandler
.
setSavePassword
(
CommonUtils
.
getBoolean
(
atts
.
getValue
(
RegistryConstants
.
ATTR_SAVE_PASSWORD
)));
if
(!
passwordReadCanceled
)
{
curNetworkHandler
.
setPassword
(
readSecuredPassword
(
atts
,
curDataSource
,
"network/"
+
handlerId
));
}
curNetworkHandler
.
setPassword
(
decryptPassword
(
atts
.
getValue
(
RegistryConstants
.
ATTR_PASSWORD
)));
curDataSource
.
getConnectionConfiguration
().
addHandler
(
curNetworkHandler
);
}
...
...
@@ -1085,19 +1096,32 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
isDescription
=
false
;
}
@Nullable
private
String
decryptPassword
(
String
encPassword
)
{
if
(!
CommonUtils
.
isEmpty
(
encPassword
))
{
private
String
readSecuredPassword
(
Attributes
xmlAttrs
,
DataSourceDescriptor
dataSource
,
String
subNode
)
{
final
DBASecureStorage
secureStorage
=
getPlatform
().
getSecureStorage
();
{
try
{
encPassword
=
ENCRYPTOR
.
decrypt
(
encPassword
);
}
catch
(
Throwable
e
)
{
// could not decrypt - use as is
encPassword
=
null
;
if
(
secureStorage
.
useSecurePreferences
())
{
ISecurePreferences
prefNode
=
dataSource
.
getSecurePreferences
();
if
(
subNode
!=
null
)
{
for
(
String
nodeName
:
subNode
.
split
(
"/"
))
{
prefNode
=
prefNode
.
node
(
nodeName
);
}
}
final
String
password
=
prefNode
.
get
(
RegistryConstants
.
ATTR_PASSWORD
,
null
);
if
(
password
!=
null
)
{
return
password
;
}
}
}
catch
(
StorageException
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
;
}
}
return
encPassword
;
final
String
encPassword
=
xmlAttrs
.
getValue
(
RegistryConstants
.
ATTR_PASSWORD
);
return
CommonUtils
.
isEmpty
(
encPassword
)
?
null
:
decryptPassword
(
encPassword
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录