您好,欢迎访问一九零五行业门户网

Oracle wallet实现无需输入用户名与密码登陆数据库

在oracle 10g前,我们在shell或jdbc中连接数据库时,都需要输入用户名与密码,并且都是明文。从1ogr2开始,oracle提供wallet这个工具,可以实现无需输入用户名与密码就可以登陆数据库,如下: 一般情况:sqlplus scott/oracle@htzdg 用wallet后:sqlplus /@ht
在oracle 10g前,我们在shell或jdbc中连接数据库时,都需要输入用户名与密码,并且都是明文。从1ogr2开始,oracle提供wallet这个工具,可以实现无需输入用户名与密码就可以登陆数据库,如下:
一般情况:sqlplus scott/oracle@htzdg
用wallet后:sqlplus /@htzdg
测试环境:
server :solaris 10,oracle 11gr2
client :win 7,oracle11gr2
登陆端配置tnsnames.ora文件,增加下面几行
htzdg =
  (description =
    (address_list =
      (address = (protocol = tcp)(host = 192.168.100.30)(port = 1521))
    )
    (connect_data =
      (server = dedicated)
      (service_name = htzdg)
    )
  )
测试是否可以正常解析
c:\users\luoping>tnsping htzdg
tns ping utility for 32-bit windows: version 11.2.0.1.0 - production on 29-8月 -
2012 21:40:40
copyright (c) 1997, 2010, oracle.  all rights reserved.
已使用的参数文件:
d:\app\luoping\product\11.2.0\client_1\network\admin\sqlnet.ora
已使用 tnsnames 适配器来解析别名
尝试连接 (description = (address_list = (address = (protocol = tcp)(host = 192.1
68.100.30)(port = 1521))) (connect_data = (server = dedicated) (service_name = h
tzdg)))
ok (40 毫秒)
c:\users\luoping>
下面是开始配置wallet
1,创建一个wallet
d:\app\luoping\product\11.2.0\client_1\bin>mkstore -wrl d:\app\luoping\product\11.2.0\client_1\pstore -create
oracle secret store tool: 版本 11.2.0.1.0 - production
版权所有 (c) 2004, 2009, oracle 和/或其子公司。保留所有权利。
输入口令:
再次输入口令:
d:\app\luoping\product\11.2.0\client_1\bin>cd ../
d:\app\luoping\product\11.2.0\client_1>cd pstore
d:\app\luoping\product\11.2.0\client_1\pstore>dir
驱动器 d 中的卷是 data
卷的序列号是 d60c-09bd
d:\app\luoping\product\11.2.0\client_1\pstore 的目录
2012/08/29  15:39              .
2012/08/29  15:39              ..
2012/08/29  15:39             3,589 cwallet.sso
2012/08/29  15:39             3,512 ewallet.p12
               2 个文件          7,101 字节
               2 个目录 368,717,893,632 可用字节
   2,启动wallet与指定wallet位置
d:\app\luoping\product\11.2.0\client_1\network\admin>more sqlnet.ora
# sqlnet.ora network configuration file: d:\app\luoping\product\11.2.0\client_1\
network\admin\sqlnet.ora
# generated by oracle configuration tools.
# this file is actually generated by netca. but if customers choose to
# install software only, this file wont exist and without the native
# authentication, they will not be able to connect to the database on nt.
sqlnet.authentication_services= (nts)
names.directory_path= (tnsnames, ezconnect)
wallet_location=(source=(method=file)(method_data=(directory=d:\app\luoping\product\11.2.0\client_1\pstore)))
sqlnet.wallet_override=true
     3,增加需要登陆的网络服务名,用户,密码到wallet中
d:\app\luoping\product\11.2.0\client_1\bin>mkstore -wrl d:\app\luoping\product\1
1.2.0\client_1\pstore -createcredential htzdg sys oracle
oracle secret store tool: 版本 11.2.0.1.0 - production
版权所有 (c) 2004, 2009, oracle 和/或其子公司。保留所有权利。
输入 wallet 口令:
create credential oracle.security.client.connect_string1
     4,测试是否成功
d:\app\luoping\product\11.2.0\client_1\bin>sqlplus /@htzdg as sysdba
sql*plus: release 11.2.0.1.0 production on 星期三 8月 29 17:48:27 2012
copyright (c) 1982, 2010, oracle.  all rights reserved.
连接到:
oracle database 11g enterprise edition release 11.2.0.1.0 - 64bit production
with the partitioning, olap, data mining and real application testing options
sql>
    5,查看wallet中配置的网络服务名
d:\app\luoping\product\11.2.0\client_1\bin>mkstore -wrl d:\app\luoping\product\1
1.2.0\client_1\pstore -listcredential
oracle secret store tool: 版本 11.2.0.1.0 - production
版权所有 (c) 2004, 2009, oracle 和/或其子公司。保留所有权利。
输入 wallet 口令:
list credential (index: connect_string username)
1: htzdg sys
    6,一个网络服务名,只能对应一个用户,如果相同的数据库有多少用户需要在同一个client通过wallet实现时,我们需要每一个用户,创建一个网络服务名。
下面是测试一个网络服务名,相增加两个用户时,报错。
c:\users\luoping>mkstore -wrl d:\app\luoping\product\11.2.0\client_1\pstore -cre
atecredential htzdg scott oracle
oracle secret store tool: 版本 11.2.0.1.0 - production
版权所有 (c) 2004, 2009, oracle 和/或其子公司。保留所有权利。
输入 wallet 口令:
create credential 出现密钥存储错误: oracle.security.pki.oraclesecretstoreexcepti
on: credential already exists
     7,当密码修改后,要手动更新wallet中相应的密码。不然要报错的。
d:\app\luoping\product\11.2.0\client_1\bin>sqlplus /@htzdg as sysdba
sql*plus: release 11.2.0.1.0 production on 星期三 8月 29 17:45:56 2012
copyright (c) 1982, 2010, oracle.  all rights reserved.
连接到:
oracle database 11g enterprise edition release 11.2.0.1.0 - 64bit production
with the partitioning, olap, data mining and real application testing options
sql>
sql> alter user sys identified by htz;
用户已更改。
sql> exit
从 oracle database 11g enterprise edition release 11.2.0.1.0 - 64bit production
with the partitioning, olap, data mining and real application testing options 断

d:\app\luoping\product\11.2.0\client_1\bin>sqlplus /@htzdg as sysdba
sql*plus: release 11.2.0.1.0 production on 星期三 8月 29 17:46:25 2012
copyright (c) 1982, 2010, oracle.  all rights reserved.
error:
ora-01017: invalid username/password; logon denied
请输入用户名:
d:\app\luoping\product\11.2.0\client_1\bin>mkstore -wrl d:\app\luoping\product\1
1.2.0\client_1\pstore -modifycredential htzdg sys
oracle secret store tool: 版本 11.2.0.1.0 - production
版权所有 (c) 2004, 2009, oracle 和/或其子公司。保留所有权利。
命令行中缺少您的密钥/口令
请输入您的密钥/口令:
请重新输入您的密钥/口令:
输入 wallet 口令:
modify credential
modify 1
d:\app\luoping\product\11.2.0\client_1\bin>
d:\app\luoping\product\11.2.0\client_1\bin>mkstore -wrl d:\app\luoping\product\1
1.2.0\client_1\pstore -modifycredential htzdg sys
oracle secret store tool: 版本 11.2.0.1.0 - production
版权所有 (c) 2004, 2009, oracle 和/或其子公司。保留所有权利。
命令行中缺少您的密钥/口令
请输入您的密钥/口令:
请重新输入您的密钥/口令:
输入 wallet 口令:
modify credential
modify 1
d:\app\luoping\product\11.2.0\client_1\bin>
d:\app\luoping\product\11.2.0\client_1\bin>sqlplus /@htzdg as sysdba
sql*plus: release 11.2.0.1.0 production on 星期三 8月 29 17:48:27 2012
copyright (c) 1982, 2010, oracle.  all rights reserved.
连接到:
oracle database 11g enterprise edition release 11.2.0.1.0 - 64bit production
with the partitioning, olap, data mining and real application testing options
sql>
     8,手动删除wallet中的记录
d:\app\luoping\product\11.2.0\client_1\bin>mkstore -wrl d:\app\luoping\product\1
1.2.0\client_1\pstore -deletecredential htzdg
oracle secret store tool: 版本 11.2.0.1.0 - production
版权所有 (c) 2004, 2009, oracle 和/或其子公司。保留所有权利。
输入 wallet 口令:
delete credential
delete 1
     9,mkstore命令帮忙手册
d:\app\luoping\product\11.2.0\client_1\bin>mkstore
oracle secret store tool: 版本 11.2.0.1.0 - production
版权所有 (c) 2004, 2009, oracle 和/或其子公司。保留所有权利。
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]
其它类似信息

推荐信息