Database connection encryption and integrity with ColdFusion and Oracle thin client - java

As ColdFusion datasource we are using the Oracle thin client to connect with the database. So, basically we are using a JDBC URL such as jdbc:oracle:thin:#... and as Driver Class oracle.jdbc.OracleDriver
This works successfully however we would like to set encryption and integrity parameters as well. In Java this is done similarly by setting a Properties object prior to getting a connection as follows:
Properties prop = new Properties();
prop.put("oracle.net.encryption_client", "REQUIRED");
prop.put("oracle.net.encryption_types_client", "( DES40 )");
prop.put("oracle.net.crypto_checksum_client", "REQUESTED");
prop.put("oracle.net.crypto_checksum_types_client", "( MD5 )");
...
OracleDataSource ods = new OracleDataSource();
ods.setProperties(prop);
ods.setURL("jdbc:oracle:thin:#localhost:1521:main");
Connection conn = ods.getConnection();
...
Is there a way that I can pass these parameters to the ColdFusion datasource. Ideally, I would love to do this centrally in such way that a change to all the cfquery or cfstoredproc is not needed.
I also know that in application servers such as Oracle AS there is an option when creating a datasource which says "Add Properties". In there you can add such properties. So, I was thinking of maybe creating a JNDI DS in the app. server and then magically connecting to it but this may have some impacts on the app.
Besides this I was also thinking of communicating with the CF datasource through the CF admin API (cfide.adminapi.administrator) and also the option of extending the Oracle driver so that when CF connects with it these params are already set.
I would love to have your professional opinion and suggestions on this.

I know this is an old question...
You absolutely can pass connection string properties to ANY ColdFusion datasource.
Once the datasource is open in CF ADMIN, open the Advanced Settings. The first option you can change in the Advanced Settings tab is "Connection String". This would be all the name-value pairs of parameters separated by ampersand (&) to be passed on the connection to the database.
For example:
encryption_client=REQUIRED&encryption_types_client=DES40&crypto_checksum_client=REQUESTED&crypto_checksum_types_client=MD5`
However, the answer to the OP, is that you can pass parameters along on the JDBC URL as well.
For example:
Using the Progress Datadirect driver, your JDBC URL might look like this:
jdbc:datadirect:oracle://server;SID=someSID;encryption_client=REQUIRED;encryption_types_client=DES40;crypto_checksum_client=REQUIRED;crypto_checksum_types_client=MD5
Just remember, that your params are separated by semicolons, not commas.
When defining a datasource, make sure you are using the right KIND of driver... Some features aren't available from the native datasource setup screens, so to use more advanced features, you may need to use OTHER.

All data sources in ColdFusion can be configured with a connection string. I would see if it is possible to pass your properties as part of the connection string.
To change the connection string open the data source in the CF admin and go to 'Advanced Settings'. There is a box there you can fill out.
If you figure that out then the whole process should be transparent those those using the data source.
I hope that helps some.

Related

Trouble establishing a simple connection with JDBC to MySql, java.sql.SQLNonTransientConnectionException

I fail to establish a connection to a MySql database on an external server when I use the mysql-connector-java version 8.0.11+ (I was currently testing with 8.0.25). However I am able to create a connection when I use the older MySql connector mysql-connector-java version 5.1.49.
The version of the MySql Database is "8.0.25-15"
The code fails on the first line:
try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
{...}
Since I can connect though mysql-connector-java version 5.1.49, I first thought I could solve this problem by adding parameters to the DB_URL. I have experimented with a lot of parameters, but no luck:
useSSL=false
serverTimezone=GMT
useUnicode=true
characterEncoding=utf-8
passwordCharacterEncoding=utf-8
connectionCollation=utf8mb4_bin
autoReconnect=true
failOverReadOnly=false
maxReconnects=10
cacheServerConfiguration=false
The error I always receive is:
java.sql.SQLNonTransientConnectionException: Could not create connection to database server.
Caused by: java.lang.NullPointerException: Cannot invoke "String.toUpperCase(java.util.Locale)" because "javaEncoding" is null
at com.mysql.cj.CharsetMapping.getMysqlCharsetForJavaEncoding(CharsetMapping.java:552)
at com.mysql.cj.CharsetMapping.getCollationIndexForJavaEncoding(CharsetMapping.java:585)
at com.mysql.cj.protocol.a.NativeServerSession.configureCharacterSets(NativeServerSession.java:452)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1329)
at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:866)
A month ago, I did not have this problem, so I suspect the cause is a change in the database (I am not tbe database Administrator).
When I debug, the error seems to be caused because the program requests the "character_set_system" variable from MySql, which is"utf8mb3" (instead "utf8" or "utf8mb4").
I suspect that changing the database variable "utf8mb3" to "utf8" might solve this problem? But I am not certain and I cannot simply change this value because the database is hosted by an external company. I have typed "Show Variables" and "Show Global Variables" in a MySql editor for your information:
A screenshot of the DB variables concerning language.
Alternatively I would like to tell java to ignore "character_set_system". It seems that Java first looks for "local.character_set_results", but this variable returns null despite that "character_set_results" is defined in the database.
I hope someone can help me with this problem.
Kind Regards
Steven

Oracle FCF OSN Client Side Configuration

Good time!
First of all, here is my environment:
Java 1.7
Tomcat 7
Oracle UCP connection pool
Thin JDBC driver
Oracle 10g database with RAC and SCAN (some information)
I need to configure the Oracle FCF feature. There are several articles about it's configuration: Spring documentation (1), complete example (2), ...
I've performed all the steps described in the article (1) and I've also configured a UCP logging where I can see that FCF is actually enabled.
What is confusing for me is the following statement fro the second article:
FAST CONNECTION FAILOVER PREREQUISITES
...
5.) The JVM in which your JDBC instance is running must have
* oracle.ons.oraclehome set to point to your ORACLE_HOME. For example:
*
* -Doracle.ons.oraclehome=C:\oracle\product\10.2.0\db_1
...
Question:
My Oracle database (RAC) is located at a remote server and I use a thin JDBC driver, thus what should I do here (Do I really need to set uop this parameter, and, if yes, than how)? There is no point in the first article about configuring such a JVM parameter, it is only said that I need to set up the 'ONSConfiguration' parameter of a datasource where I should list all the RAC nodes...
UPDATE 1:
Also from the second article:
CLIENT-SIDE ONS CONFIGURATION
...
(2) ONS daemon on the client side
Example ons.config file for a client:
...
At the beginning of this article it is said that the 'client-side' is a java-based application, while the 'server-side' is a database (RAC). It is really required to creare the 'ons.config' file on a java-based-application-side in case of using a thin JDBC driver?
UDPADE 2:
From the Oracle documentation:
Remote Configuration
UCP for JDBC supports remote configuration of ONS through the SetONSConfiguration pool property. The ONS property value is a string that closely resembles the content of an ons.config file. The string contains a list of name=value pairs separated by a new line character (\n). The name can be: nodes, walletfile, or walletpassword. The parameter string should at least specify the ONS configuration nodes attribute as a list of host:port pairs separated by a comma. SSL would be used when the walletfile attribute is specified as an Oracle wallet file.
Applications that use remote configuration must set the oracle.ons.oraclehome system property to the location of ORACLE_HOME before starting the application. For example: java -Doracle.ons.oraclehome=$ORACLE_HOME ...
But how can I set the ORACLE_HOME variable when I have no local installation of Oracle database, that is what the thin driver is about, right?
If you want only use UCP pool , then you just need this setup :
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
pds.setONSConfiguration("nodes=10.247.43.111:4500, 10.247.43.112:4500");
pds.setFastConnectionFailoverEnabled(true);
where "nodes=10.247.43.111:4500, 10.247.43.112:4500" is list of ons listerers
10.247.43.111:4500 - remote ons listerner on node1
10.247.43.112:4500 - remote ons listerner on node2
etc.
see this good example:
http://www.idevelopment.info/data/Programming/java/jdbc/High_Availability/FastConnectionFailoverExampleThin.java
and this http://docs.oracle.com/cd/B19306_01/java.102/b14355/fstconfo.htm#CEGGDDFJ
ORACLE_HOME needed for local ONS demon connection.

Can connect to remote database through MySQL Workbench, but not Java JBDC

I have a remote MySQL database that I can connect to with MySQL Workbench (screen shot below), but I ultimately need to connect to it via JBDC and everytime I try to connect, it throws an exception. I'm new to this, so could anyone provide me some insight on what could be wrong?
String host = "testdb.db.10682960.hostedresource.com";
String datab = "testdb";
String url = "jdbc:mysql://" + host + ":3306/" + datab;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(url, datab, "password");
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
Edit: Not sure if this is relevant or not, but I'm running this on Android.
It looks like you're missing a user name. Try adding "?user=testdb" to the end of your url.
Edit: I didn't realize this was an Android app. Technically, it should be possible, but not advisable. Your network connection would be much less reliable, and you would be pushing server credentials out to your client. Use of a REST API to communicate from your Android to a web server in the same data center as the database is a much safer option.
I don't have experience trying this from Android... so I don't know what exception would be thrown if, for example, you can't reach port 3306 from the Android's connection to the network. Even if you get it working, though, do look into using a web service instead.
According to the jTDS FAQ (http://jtds.sourceforge.net/faq.html) the format of a JDBC URL is:
jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;...]]
If I were you, I would replace the '?' with a ';' to adhere to the above format. The "query string" is not like that of a "normal" URL.
This, of course, assumes that you are using the open source JDBC connector found via the link above.

How can I configure persistence.xml for SQL server

How can I configure persistence.xml file to connect to my SQL Server. Some information is connected as: Host, DatabaseName, UserName, Password, Port, ...
Setting up a connection pool to MySQL database using a configuration .xml file can be pretty troublesome to someone who has just started like you.
In my opinion, you should take a look at this short guide. You simply need to start Glassfish server, open the browser and surf to http://yourdomain.com:4848 to access the Admin panel. After that, just follow the instruction in that article and to create the JDBC Connection pool and JDBC Resource. At this point, you only need to open the persistence.xml file with your IDE (NetBeans, etc.) and set the Data Source property with name of your JDBC Resource and you're done.
One thing to note is that you must download the latest MySQL Connector/J and copy the file
mysql-connector-java-<version>-bin.jar
into the folder
<GlassFish-install-folder>\glassfish\domains\domain1\lib\ext
Otherwise, you will run into the expcetion Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource if you try to ping the database after creating the JDBC Connection pool.
First of all donwload jdbc driver for sqlserver and put that in glassfish lib directory and boot that.
Using Glassfish admin console:
define a jdbc connection pool and specify Host, DatabaseName,
UserName, Password, Port, ...
define a jdbc resource and select connection pool name that you have specified in step 1
then grab the name of jdbc resource and put it in your persistence.xml file : <jta-data-source>YOUR-JDBC-RESOURCE-NAME</jta-data-source>
and now you can connect to data base.
If you are using Netbeans, it has some nice wizards to produce connection pool and jdbc resource in glassfish.
Since you are using JEE6 this is another way using annotation:
import javax.annotation.sql.DataSourceDefinition;
#DataSourceDefinition(name = "java:app/env/myDatasource",
minPoolSize = 0,
initialPoolSize = 0,
className = "your.driver.class",
serverName="localhost",
user = "admin",
password = "admin",
databaseName = "test"
)
public class DbConfiguration {
}
For more info take a look at here.

Username & Password in JDBC Connection URL

I was using a SQuirrel SQL Client to connect & browse my oracle database servers. I have given the credentials in the connection URL itself. But it still prompts for the username and password. Does it really required to provide additional username/password while establishing connection. Won't it take it from the connection URL?
jdbc:oracle:thin:username/password#my.oracle.server.domain.com:1521:DBName
Thin driver
Oracle's JDBC Thin driver uses Java sockets to connect directly to Oracle. It provides its own TCP/IP version of Oracle's SQL*Net protocol. Because it is 100% Java, this driver is platform independent and can also run from a Web Browser (applets).
There are 2 URL syntax, old syntax which will only work with SID and the new one with Oracle service name.
Old syntax
jdbc:oracle:thin:#[HOST][:PORT]:SID
New syntax
jdbc:oracle:thin:#//[HOST][:PORT]/SERVICE
On new syntax SERVICE may be a oracle service name or a SID.
There are also some drivers that support a URL syntax which allow to put Oracle user id and password in URL.
jdbc:oracle:thin:[USER/PASSWORD]#[HOST][:PORT]:SID
jdbc:oracle:thin:[USER/PASSWORD]#//[HOST][:PORT]/SERVICE
source: http://www.orafaq.com/wiki/JDBC
Refer to this link, it will help you.
https://jdbc.postgresql.org/documentation/use/#connection-parameters
For example, if you want to include username & password in the Postgres connection string.
jdbc:postgresql://postgres-10.4.cluster:5432/default?user=postgres&password=postgres
Won't it take it from the connection
URL?
I think No
You need to enter usrename & password.
Check: http://squirrel-sql.sourceforge.net/user-manual/quick_start.html#howtoconnect
section Connecting
From what I have seen, support for passing the username/password in the JDBC URL is inconsistent across Oracle JDBC Drivers.

Categories