oracle 如何使用oracle钱包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24160428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use oracle wallet
提问by user2507962
I am trying to store password in an Oracle Wallet file which I will retrieve from the code and use.
我正在尝试将密码存储在我将从代码中检索并使用的 Oracle Wallet 文件中。
I tried to create a wallet and save a credential there:-
我尝试创建一个钱包并在那里保存凭证:-
$ mkstore -wrl <wallet_location> -createCredential sid scott tiger
Oracle Secret Store Tool : Version 12.1.0.2
Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:
Create credential oracle.security.client.connect_string1
The creation does not give any error but when I try to list the credential, I don't get anything.
创建没有给出任何错误,但是当我尝试列出凭据时,我什么也没得到。
$ mkstore -wrl -listCredential
Oracle Secret Store Tool : Version 12.1.0.2
Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved
Also, how to retrieve this password using java?
另外,如何使用java检索此密码?
回答by Joshan George
For connecting the Oracle DB using wallet requires the following changes.
使用 wallet 连接 Oracle DB 需要进行以下更改。
you need to create a wallet store, you need to also choose a password for the wallet and you need to use this password while modifying the wallet
- OracleClientHome/bin/mkstore -wrl Where you want to store your wallet-create
e.g.C:\Oracle_11.2.0\product\client_1\bin\mkstore -wrl C:\Users\sample\app\wallet
you need to add the tns entries in tnsnames.ora (OracleClientHome/network/admin/tnsnames.ora) and same tns entry name will be used us wallet connect string
- TNS_Entry_Name=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=Hostname)(PORT=Port_Number))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=Service_Name)))
e.g.C:\Oracle_11.2.0\product\client_1\network\admin\tnsnames.ora
- SAMPLEDB_RO=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=HostName)(PORT=PortNumber))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=samplesrv)))
you need to create wallet entry for the above tns entry with credentials, you also need to provide the wallet password which you have given while creating the wallet.
- OracleClientHome/bin/mkstore -wrl Where you want to store your wallet-createCredential TNS_Entry_Name/Wallet_Entry_nameDB_UsernameDB_Password
e.g.C:\Oracle_11.2.0\product\client_1\bin\mkstore -wrl C:\Users\sample\app\wallet -createCredential SAMPLEDB_RO sample sample
you need to add the sqlnet.ora file to update the wallet location and wallet override flag to true
- WALLET_LOCATION =(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=Where you want to store your wallet)))
- SQLNET.WALLET_OVERRIDE = TRUE
e.g.
- WALLET_LOCATION =(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=C:\Users\sample\app\wallet)))
- SQLNET.WALLET_OVERRIDE = TRUE
test the db connection using wallet and oracle client to make sure the wallet configurations are correct
OracleClientHome/bin/sqlplus /nolog
connect DB_Username/DB_Password@TNS_Entry_Name
- connect /@TNS_Entry_Name
e.g.
- connect sample/sample@SAMPLEDB_RO
- connect /@SAMPLEDB_RO
you need to make the java application ready to use the wallet and run the java program with the below JVM Parameters
- Add the following jars to the application classpath.
- OracleClientHome/jdbc/lib/ojdbc.jar
- OracleClientHome/jlib/oraclepki.jar
- OracleClientHome/jlib/osdt_cert.jar
OracleClientHome/jlib/osdt_core.jar
e.g.
- C:\Oracle_11.2.0\product\client_1\jdbc\lib\ojdbc.jar
- C:\Oracle_11.2.0\product\client_1\jlib\oraclepki.jar
- C:\Oracle_11.2.0\product\client_1\jlib\osdt_cert.jar
C:\Oracle_11.2.0\product\client_1\jlib\osdt_core.jar
Change application configuration thin url to use the wallet
jdbc:oracle:thin:/@TNS_Entry_Name/Wallet_Entry_name
e.g.
jdbc:oracle:thin:/@SAMPLEDB_RO
Also add the following properties as JVM Parameters, this help the library to find the oracle wallet
-Doracle.net.tns_admin=OracleClientHome/network/admin -Doracle.net.wallet_location=Where you want to store your wallet
e.g.-Doracle.net.tns_admin=C:\Oracle_11.2.0\product\client_1\network\admin -Doracle.net.wallet_location=C:\Users\sample\app\wallet
You are all set!!
- For listing the existing credentials in the wallet you can use the below command, but you need to provide the wallet password which you have given while creating the wallet.
OracleClientHome/bin/mkstore -wrl Where you want to store your wallet-listCredential
e.g.C:\Oracle_11.2.0\product\client_1\bin\mkstore -wrl C:\Users\sample\app\wallet -listCredential
你需要创建一个钱包商店,你还需要为钱包选择一个密码,修改钱包时需要使用这个密码
- OracleClientHome/斌/ mkstore -wrl哪里要存储你的钱包-创建
例如C:\Oracle_11.2.0\product\client_1\bin\mkstore -wrl C:\Users\sample\app\wallet
您需要在 tnsnames.ora ( OracleClientHome/network/admin/tnsnames.ora ) 中添加 tns 条目,并且将使用相同的 tns 条目名称作为我们的钱包连接字符串
- TNS_Entry_Name=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST= Hostname)(PORT= Port_Number))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME= Service_Name)))
例如C:\Oracle_11.2.0\product\client_1\network\admin\tnsnames.ora
- SAMPLEDB_RO=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST= HostName)(PORT= PortNumber))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=samplesrv)))
您需要使用凭据为上述 tns 条目创建钱包条目,您还需要提供您在创建钱包时提供的钱包密码。
- OracleClientHome/bin/mkstore -wrl钱包存放位置-createCredential TNS_Entry_Name/Wallet_Entry_name DB_Username DB_Password
例如C:\Oracle_11.2.0\product\client_1\bin\mkstore -wrl C:\Users\sample\app\wallet -createCredential SAMPLEDB_RO 示例示例
您需要添加 sqlnet.ora 文件以将钱包位置和钱包覆盖标志更新为 true
- WALLET_LOCATION =(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=你想存放钱包的地方)))
- SQLNET.WALLET_OVERRIDE = TRUE
例如
- WALLET_LOCATION =(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=C:\Users\sample\app\wallet)))
- SQLNET.WALLET_OVERRIDE = TRUE
使用钱包和oracle客户端测试数据库连接以确保钱包配置正确
OracleClientHome/bin/sqlplus /nolog
连接DB_Username/ DB_Password@ TNS_Entry_Name
- 连接 //@ TNS_Entry_Name
例如
- 连接样品/样品@SAMPLEDB_RO
- 连接 /@SAMPLEDB_RO
您需要使 Java 应用程序准备好使用钱包并使用以下 JVM 参数运行 Java 程序
- 将以下 jars 添加到应用程序类路径。
- OracleClientHome/jdbc/lib/ojdbc.jar
- OracleClientHome/jlib/oraclepki.jar
- OracleClientHome/jlib/osdt_cert.jar
OracleClientHome/jlib/osdt_core.jar
例如
- C:\Oracle_11.2.0\product\client_1\jdbc\lib\ojdbc.jar
- C:\Oracle_11.2.0\product\client_1\jlib\oraclepki.jar
- C:\Oracle_11.2.0\product\client_1\jlib\osdt_cert.jar
C:\Oracle_11.2.0\product\client_1\jlib\osdt_core.jar
更改应用程序配置细 url 以使用钱包
jdbc:oracle:thin:/@ TNS_Entry_Name/Wallet_Entry_name
例如
jdbc:oracle:thin:/@SAMPLEDB_RO
还要添加以下属性作为JVM参数,这有助于库找到oracle钱包
-Doracle.net.tns_admin= OracleClientHome/network/admin -Doracle.net.wallet_location=您想要存放钱包的位置
例如-Doracle.net.tns_admin=C:\Oracle_11.2.0\product\client_1\network\admin -Doracle.net.wallet_location=C:\Users\sample\app\wallet
你都准备好了!!
- 要列出钱包中的现有凭据,您可以使用以下命令,但您需要提供您在创建钱包时提供的钱包密码。
OracleClientHome/bin/mkstore -wrl钱包的存放位置 -listCredential
例如C:\Oracle_11.2.0\product\client_1\bin\mkstore -wrl C:\Users\sample\app\wallet -listCredential
回答by Stephan
One important thing you must have in mind is, that the alias you choose for the createCredential
command must be identicalto the URL you are using for the connection.
您必须牢记的一件重要事情是,您为createCredential
命令选择的别名必须与您用于连接的 URL相同。
When your JDBC connection string looks like jdbc:oracle:thin:/@dbsrv:1521/orcl
you must use the command
当您的 JDBC 连接字符串看起来像jdbc:oracle:thin:/@dbsrv:1521/orcl
您必须使用命令
mkstore -wlr /foobar -createCredential dbsrv:1521/orcl USER PASSWORD