oracle wallet使用与维护

时间:2021-10-12 02:15:44

oracle wallet使用与维护
2015年05月26日 17:58:55 SilenceRiver 阅读数:1614
oracle wallet使用与维护---oracle无密码登录
分类: Oracle Management2012-07-24 19:54 3111人阅读 评论(1) 收藏 举报
oraclestringoracle11g数据库listjdbc
author:skate
time:2012/07/24

oracle wallet使用与维护

从Oracle10gR2开始, 通过使用Oracle Wallet达到任意用户不使用密码登录数据库(非操作系统认证方式),这对于用脚本登录数据库进行操作来说是非常有用的;尤其对于企业安全要求很高,不希望用户名和密码明文存在配置文件中,而且对于密码的维护是极为方便的,比如我把wallet放在指定路径下,当修改密码时,只需统一覆盖wallet即可,对于有大量应用服务器尤为方便。

在客户端创建一个wallet

用法:
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore --help
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
未指定 Wallet 的位置。
mkstore [-wrl wrl] [-create] [-createSSO] [-createLSSO] [-createALO] [-delete] [
-deleteSSO] [-list] [-createEntry alias secret] [-viewEntry alias] [-modifyEntry
alias secret] [-deleteEntry alias] [-createCredential connect_string username p
assword] [-listCredential] [-modifyCredential connect_string username password]
[-deleteCredential connect_string] [-help] [-nologo]
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>

1. 创建wallet
语法: mkstore -wrl <wallet_location> -create
eg:
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -create
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入口令:(输入wallet的密码,要设置的复杂些,否则失败)
再次输入口令:(输入wallet的密码)
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>

查看创建wallet
e:\temp\wallet>dir
驱动器 E 中的卷是 data
卷的序列号是 DCEE-F1D9
e:\temp\wallet 的目录
2012/07/24 17:19 <DIR> .
2012/07/24 17:19 <DIR> ..
2012/07/24 17:19 3,589 cwallet.sso
2012/07/24 17:19 3,512 ewallet.p12
2 个文件 7,101 字节
2 个目录 212,962,336,768 可用字节
e:\temp\wallet>

2.创建客户端连接服务端的网络连接串,每个连接串对应一个数据库用户
skate_192.168.1.9 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.9)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = skate)
)
)

3.把登入数据库的用户认证信息添加到wallet中
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -createCredential skate_192.168.1.9 skate skatepwd
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
Create credential oracle.security.client.connect_string1

4.在客户端的sqlnet.ora文件里,编辑参数“WALLET_LOCATION ”
WALLET_LOCATION=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=e:\temp\wallet)))
SQLNET.WALLET_OVERRIDE = TRUE

5.测试在客户端无需密码连接数据库测试

E:\app\Administrator\product\11.2.0\dbhome_1\BIN>sqlplus /@skate_192.168.1.9
SQL*Plus: Release 11.2.0.1.0 Production on 星期二 7月 24 17:59:21 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> show user;
USER 为 "SKATE"
SQL>

6.如何管理wallet
6.1 查看wallet里的连接认证信息
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -listCredential
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
List credential (index: connect_string username)
1: skate_192.168.1.9 skate

6.2 添加一个新的认证信息到wallet里,在wallet是以连接串为唯一标识的
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -createCredential test_skate_s_192.168.1.9 skate skatepwd
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
Create credential oracle.security.client.connect_string2

查看已经添加用户认证信息
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -listCredential
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
List credential (index: connect_string username)
2: test_skate_s_192.168.1.9 skate
1: skate_192.168.1.9 skate

6.3 编辑wallet里的用户密码
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -modifyCredential test_skate_s_192.168.1.9 skate skatepwd1
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
Modify credential
Modify 2
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>

6.4 删除wallet的用户认证信息
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -listCredential
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
List credential (index: connect_string username)
2: test_skate_s_192.168.1.9 skate
1: skate_192.168.1.9 skate
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -deleteCredential test_prodb_s_192.168.1.9
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
Delete credential
Delete 2
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -listCredential
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
List credential (index: connect_string username)
1: skate_192.168.1.9 skate
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>

7.查看wallet里的详细认证信息
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -list
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
Oracle 密钥存储条目:
oracle.security.client.connect_string1
oracle.security.client.password1
oracle.security.client.username1

E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -viewEntry oracle.security.client.connect_string1
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
oracle.security.client.connect_string1 = skate_192.168.1.9
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -viewEntry oracle.security.client.password1
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
oracle.security.client.password1 = skatepwd
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -viewEntry oracle.security.client.username1
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:
oracle.security.client.username1 = skate
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>

8.更改wallet里用户认证信息的内容
8.1 更改密码
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -modifyEntry oracle.security.client.password1 skatepwd1
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:

8.2 更改密码
E:\app\Administrator\product\11.2.0\dbhome_1\BIN>mkstore -wrl e:\temp\wallet -modifyEntry oracle.security.client.username1 skate1
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
输入 Wallet 口令:

E:\app\Administrator\product\11.2.0\dbhome_1\BIN>

和6.3步骤里(-modifyCredential)的区别是,这里不仅仅改密码,连接串和密码都可以改

我们这里是本地创建wallet,从本地客户端可以登录,那从其他地方可以吗?
A.
在win7+oracle11g客户端上创建的wallet,无密码访问linux+oracle10g服务服务端没有问题,但是把wallet复制到linux+oracle10g的服务端,再无密码登录是报错“ORA-12534: TNS:operation not supported”,需要用如下命令编辑一下,就可以无密码登录了。虽然语句没有改任何内容。
[oracle@localhost ~]$ mkstore -wrl /tmp/wallet1 -createCredential skate_192.168.1.9 skate skatepwd1

B. 在linux+oracle10g服务端上创建的wallet,无密码访问linux+oracle10g服务服务端没有问题,把wallet复制到win7+oracle11g客户端,无密码登录也没问题。

猜测可能是版本问题。

在客户端使用wallet无密码登录的步骤:

1.创建wallet(tnsname.ora里面的连接串,sqlnet.ora文件内容都要复制到客户端)
2.把wallet复制到客户端指定路径(注意文件权限和属主)
3.修改客户端的tnsname.ora文件里连接服务器的连接串为创建时的连接串,在sqlnet.ora文件里添加如下内容:
WALLET_LOCATION=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=e:\temp\wallet)))
SQLNET.WALLET_OVERRIDE = TRUE
4.在sqlplus无密码等里测试
sqlplus /@skate_192.168.1.9

在jdbc里连接数据库密码形式如下:
public static Connection getConnection() throws SQLException {
DriverManager.registerDriver(new OracleDriver());
Connection conn = DriverManager
.getConnection("jdbc:oracle:oci:/@tnskate");
conn.setAutoCommit(false);
return conn;
}

参考: [ID 340559.1] [ID 741810.1]