Oracle wallet實現無需輸入使用者名稱與密碼登陸資料庫

來源:互聯網
上載者:User

在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.  
  3. TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 29-8月 - 
  4. 2012 21:40:40 
  5.  
  6. Copyright (c) 1997, 2010, Oracle.  All rights reserved. 
  7.  
  8. 已使用的參數檔案: 
  9. D:\app\luoping\product\11.2.0\client_1\network\admin\sqlnet.ora 
  10.  
  11.  
  12. 已使用 TNSNAMES 適配器來解析別名 
  13. 嘗試串連 (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.1 
  14. 68.100.30)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = h 
  15. tzdg))) 
  16. OK (40 毫秒) 
  17.  
  18. 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.  
  6. # This file is actually generated by netca. But if customers choose to 
  7. # install "Software Only", this file wont exist and without the native 
  8. # authentication, they will not be able to connect to the database on NT. 
  9.  
  10. SQLNET.AUTHENTICATION_SERVICES= (NTS) 
  11.  
  12. NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT) 
  13. WALLET_LOCATION=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=D:\app\luoping\product\11.2.0\client_1\pstore))) 
  14. 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.  
  6. 輸入 Wallet 口令: 
  7.  
  8. Create credential oracle.security.client.connect_string1 

     4,測試是否成功

 
  1. D:\app\luoping\product\11.2.0\client_1\BIN>sqlplus /@htzdg as sysdba 
  2.  
  3. SQL*Plus: Release 11.2.0.1.0 Production on 星期三 8月 29 17:48:27 2012 
  4.  
  5. Copyright (c) 1982, 2010, Oracle.  All rights reserved. 
  6.  
  7.  
  8. 串連到: 
  9. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production 
  10. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  11.  
  12. 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.  
  6. 輸入 Wallet 口令: 
  7.  
  8. List credential (index: connect_string username) 
  9. 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.  
  6. 輸入 Wallet 口令: 
  7.  
  8. Create credential 出現金鑰儲存區錯誤: oracle.security.pki.OracleSecretStoreExcepti 
  9. on: Credential already exists 

     7,當密碼修改後,要手動更新wallet中相應的密碼。不然要報錯的。

 
  1. D:\app\luoping\product\11.2.0\client_1\BIN>sqlplus /@htzdg as sysdba 
  2.  
  3. SQL*Plus: Release 11.2.0.1.0 Production on 星期三 8月 29 17:45:56 2012 
  4.  
  5. Copyright (c) 1982, 2010, Oracle.  All rights reserved. 
  6.  
  7.  
  8. 串連到: 
  9. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production 
  10. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  11.  
  12. SQL> 
  13. SQL> alter user sys identified by htz; 
  14.  
  15. 使用者已更改。 
  16.  
  17. SQL> exit 
  18. 從 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production 
  19. With the Partitioning, OLAP, Data Mining and Real Application Testing options 斷 
  20. 開 
  21.  
  22. D:\app\luoping\product\11.2.0\client_1\BIN>sqlplus /@htzdg as sysdba 
  23.  
  24. SQL*Plus: Release 11.2.0.1.0 Production on 星期三 8月 29 17:46:25 2012 
  25.  
  26. Copyright (c) 1982, 2010, Oracle.  All rights reserved. 
  27.  
  28. ERROR: 
  29. ORA-01017: invalid username/password; logon denied 
  30.  
  31.  
  32. 請輸入使用者名稱: 
  33.  
  34. D:\app\luoping\product\11.2.0\client_1\BIN>mkstore -wrl D:\app\luoping\product\1 
  35. 1.2.0\client_1\pstore -modifyCredential htzdg sys 
  36. Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production 
  37. 著作權 (c) 2004, 2009, Oracle 和/或其子公司。著作權所有,並保留一切權利。 
  38.  
  39. 命令列中缺少您的密鑰/口令 
  40. 請輸入您的密鑰/口令: 
  41.  
  42. 請重新輸入您的密鑰/口令: 
  43.  
  44. 輸入 Wallet 口令: 
  45.  
  46. Modify credential 
  47. Modify 1 
  48.  
  49. D:\app\luoping\product\11.2.0\client_1\BIN> 
  50.  
  51. D:\app\luoping\product\11.2.0\client_1\BIN>mkstore -wrl D:\app\luoping\product\1 
  52. 1.2.0\client_1\pstore -modifyCredential htzdg sys 
  53. Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production 
  54. 著作權 (c) 2004, 2009, Oracle 和/或其子公司。著作權所有,並保留一切權利。 
  55.  
  56. 命令列中缺少您的密鑰/口令 
  57. 請輸入您的密鑰/口令: 
  58.  
  59. 請重新輸入您的密鑰/口令: 
  60.  
  61. 輸入 Wallet 口令: 
  62.  
  63. Modify credential 
  64. Modify 1 
  65.  
  66. D:\app\luoping\product\11.2.0\client_1\BIN> 
  67. D:\app\luoping\product\11.2.0\client_1\BIN>sqlplus /@htzdg as sysdba 
  68.  
  69. SQL*Plus: Release 11.2.0.1.0 Production on 星期三 8月 29 17:48:27 2012 
  70.  
  71. Copyright (c) 1982, 2010, Oracle.  All rights reserved. 
  72.  
  73.  
  74. 串連到: 
  75. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production 
  76. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  77.  
  78. 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.  
  6. 輸入 Wallet 口令: 
  7.  
  8. Delete credential 
  9. 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.  
  5. mkstore [-wrl wrl] [-create] [-createSSO] [-createLSSO] [-createALO] [-delete] [ 
  6. -deleteSSO] [-list] [-createEntry alias secret] [-viewEntry alias] [-modifyEntry 
  7.  alias secret] [-deleteEntry alias] [-createCredential connect_string username p 
  8. assword] [-listCredential] [-modifyCredential connect_string username password] 
  9. [-deleteCredential connect_string] [-help] [-nologo] 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.