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

在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文件,增加下面几行

复制代码
  1. HTZDG =
  2. (DESCRIPTION =
  3. (ADDRESS_LIST =
  4. (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.30)(PORT = 1521))
  5. )
  6. (CONNECT_DATA =
  7. (SERVER = DEDICATED)
  8. (SERVICE_NAME = htzdg)
  9. )
  10. )

测试是否可以正常解析

复制代码
  1. C:\Users\luoping>tnsping htzdg
  2. TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 29-8月 -
  3. 2012 21:40:40
  4. Copyright (c) 1997, 2010, Oracle. All rights reserved.
  5. 已使用的参数文件:
  6. D:\app\luoping\product\11.2.0\client_1\network\admin\sqlnet.ora
  7. 已使用 TNSNAMES 适配器来解析别名
  8. 尝试连接 (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.1
  9. 68.100.30)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = h
  10. tzdg)))
  11. OK (40 毫秒)
  12. C:\Users\luoping>

下面是开始配置wallet

1,创建一个wallet

复制代码
  1. D:\app\luoping\product\11.2.0\client_1\BIN>mkstore -wrl D:\app\luoping\product\11.2.0\client_1\pstore -create
  2. Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
  3. 版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
  4. 输入口令:
  5. 再次输入口令:
  6. D:\app\luoping\product\11.2.0\client_1\BIN>cd ../
  7. D:\app\luoping\product\11.2.0\client_1>cd pstore
  8. D:\app\luoping\product\11.2.0\client_1\pstore>dir
  9. 驱动器 D 中的卷是 DATA
  10. 卷的序列号是 D60C-09BD
  11. D:\app\luoping\product\11.2.0\client_1\pstore 的目录
  12. 2012/08/29 15:39 <DIR> .
  13. 2012/08/29 15:39 <DIR> ..
  14. 2012/08/29 15:39 3,589 cwallet.sso
  15. 2012/08/29 15:39 3,512 ewallet.p12
  16. 2 个文件 7,101 字节
  17. 2 个目录 368,717,893,632 可用字节

2,启动wallet与指定wallet位置

复制代码
  1. D:\app\luoping\product\11.2.0\client_1\network\admin>more sqlnet.ora
  2. sqlnet.ora Network Configuration File: D:\app\luoping\product\11.2.0\client_1\

  3. network\admin\sqlnet.ora
  4. Generated by Oracle configuration tools.

  5. This file is actually generated by netca. But if customers choose to

  6. install "Software Only", this file wont exist and without the native

  7. authentication, they will not be able to connect to the database on NT.

  8. SQLNET.AUTHENTICATION_SERVICES= (NTS)
  9. NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
  10. WALLET_LOCATION=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=D:\app\luoping\product\11.2.0\client_1\pstore)))
  11. SQLNET.WALLET_OVERRIDE=TRUE

3,增加需要登陆的网络服务名,用户,密码到wallet中

复制代码
  1. D:\app\luoping\product\11.2.0\client_1\BIN>mkstore -wrl D:\app\luoping\product\1
  2. 1.2.0\client_1\pstore -createCredential htzdg sys oracle
  3. Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
  4. 版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
  5. 输入 Wallet 口令:
  6. Create credential oracle.security.client.connect_string1

4,测试是否成功

复制代码
  1. D:\app\luoping\product\11.2.0\client_1\BIN>sqlplus /@htzdg as sysdba
  2. SQL*Plus: Release 11.2.0.1.0 Production on 星期三 8月 29 17:48:27 2012
  3. Copyright (c) 1982, 2010, Oracle. All rights reserved.
  4. 连接到:
  5. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
  6. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  7. SQL>

5,查看wallet中配置的网络服务名

复制代码
  1. D:\app\luoping\product\11.2.0\client_1\BIN>mkstore -wrl d:\app\luoping\product\1
  2. 1.2.0\client_1\pstore -listCredential
  3. Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
  4. 版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
  5. 输入 Wallet 口令:
  6. List credential (index: connect_string username)
  7. 1: htzdg sys

6,一个网络服务名,只能对应一个用户,如果相同的数据库有多少用户需要在同一个client通过wallet实现时,我们需要每一个用户,创建一个网络服务名。

下面是测试一个网络服务名,相增加两个用户时,报错。

复制代码
  1. C:\Users\luoping>mkstore -wrl D:\app\luoping\product\11.2.0\client_1\pstore -cre
  2. ateCredential htzdg scott oracle
  3. Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
  4. 版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
  5. 输入 Wallet 口令:
  6. Create credential 出现密钥存储错误: oracle.security.pki.OracleSecretStoreExcepti
  7. on: Credential already exists

7,当密码修改后,要手动更新wallet中相应的密码。不然要报错的。

复制代码
  1. D:\app\luoping\product\11.2.0\client_1\BIN>sqlplus /@htzdg as sysdba
  2. SQL*Plus: Release 11.2.0.1.0 Production on 星期三 8月 29 17:45:56 2012
  3. Copyright (c) 1982, 2010, Oracle. All rights reserved.
  4. 连接到:
  5. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
  6. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  7. SQL>
  8. SQL> alter user sys identified by htz;
  9. 用户已更改。
  10. SQL> exit
  11. 从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
  12. With the Partitioning, OLAP, Data Mining and Real Application Testing options 断
  13. 开
  14. D:\app\luoping\product\11.2.0\client_1\BIN>sqlplus /@htzdg as sysdba
  15. SQL*Plus: Release 11.2.0.1.0 Production on 星期三 8月 29 17:46:25 2012
  16. Copyright (c) 1982, 2010, Oracle. All rights reserved.
  17. ERROR:
  18. ORA-01017: invalid username/password; logon denied
  19. 请输入用户名:
  20. D:\app\luoping\product\11.2.0\client_1\BIN>mkstore -wrl D:\app\luoping\product\1
  21. 1.2.0\client_1\pstore -modifyCredential htzdg sys
  22. Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
  23. 版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
  24. 命令行中缺少您的密钥/口令
  25. 请输入您的密钥/口令:
  26. 请重新输入您的密钥/口令:
  27. 输入 Wallet 口令:
  28. Modify credential
  29. Modify 1
  30. D:\app\luoping\product\11.2.0\client_1\BIN>
  31. D:\app\luoping\product\11.2.0\client_1\BIN>mkstore -wrl D:\app\luoping\product\1
  32. 1.2.0\client_1\pstore -modifyCredential htzdg sys
  33. Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
  34. 版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
  35. 命令行中缺少您的密钥/口令
  36. 请输入您的密钥/口令:
  37. 请重新输入您的密钥/口令:
  38. 输入 Wallet 口令:
  39. Modify credential
  40. Modify 1
  41. D:\app\luoping\product\11.2.0\client_1\BIN>
  42. D:\app\luoping\product\11.2.0\client_1\BIN>sqlplus /@htzdg as sysdba
  43. SQL*Plus: Release 11.2.0.1.0 Production on 星期三 8月 29 17:48:27 2012
  44. Copyright (c) 1982, 2010, Oracle. All rights reserved.
  45. 连接到:
  46. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
  47. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  48. SQL>

8,手动删除wallet中的记录

复制代码
  1. D:\app\luoping\product\11.2.0\client_1\BIN>mkstore -wrl d:\app\luoping\product\1
  2. 1.2.0\client_1\pstore -deleteCredential htzdg
  3. Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
  4. 版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
  5. 输入 Wallet 口令:
  6. Delete credential
  7. Delete 1

9,mkstore命令帮忙手册

复制代码
  1. D:\app\luoping\product\11.2.0\client_1\BIN>mkstore
  2. Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
  3. 版权所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有权利。
  4. mkstore -wrl wrl -create -createSSO -createLSSO -createALO -delete [
  5. -deleteSSO] -list -createEntry alias secret -viewEntry alias [-modifyEntry
  6. alias secret] -deleteEntry alias [-createCredential connect_string username p
  7. assword] -listCredential -modifyCredential connect_string username password
  8. -deleteCredential connect_string\] \[-help\] \[-nologo

相关推荐
CS创新实验室30 分钟前
数据库突然断电,凭什么没丢数据?——WAL 日志与崩溃恢复
数据库·mysql
Warolitbos38 分钟前
【数据库】SQL面试基础15题,测试/开发必背速查
数据库
ClouGence39 分钟前
开源数据库管理工具 CloudDM 新版本上线,新增 AI SQL 助手,支持 Elasticsearch、崖山数据库
数据库·sql·elasticsearch
ly76891 小时前
PostgreSQL 执行计划深读:从 EXPLAIN 输出到代价模型驱动的 SQL 改写
数据库·sql·postgresql·explain·执行计划·代价模型
Python自动化直播2 小时前
自动化笔记:素材管理、命名、轮换的几条土办法
linux·运维·数据库
xiaomuzuirenzhen2 小时前
2027校招ERP实施顾问:大数据管理与应用专业如何用SQL、BI证明业务能力
大数据·数据库
底层玩家老张2 小时前
从副本集到分片:百亿级文档数据的KES架构边界
数据库·分布式架构·分片·架构选型·文档数据库
ss2732 小时前
AI时代首先数据库-PostgreSQL实战笔记 | 16 PostgreSQL子查询与嵌套查询(下)
数据库·笔记·postgresql
川石课堂软件测试2 小时前
涨薪技术|0到1学会性能测试第8课-Analysis分析图
服务器·数据库·python·sql·jmeter·mysql·容器
SelectDB技术团队2 小时前
云数仓成本结构拆解:五层计费模型与 Apache Doris 托管形态对照
大数据·数据库·elk·全文检索·snowflake