SSL + PostgreSQL + Apache BasicDataSource ( + Spring )

So... this may not be completely advisable for a production environment, but if you are using this stack, here is a snippet to show you how to get SSL connections working with PostgreSQL. It can surely be extrapolated for use in a production environment. The "connectionProperties" is the important piece though the other common properties are included for reference:
Stack:
  • PostgreSQL 
    • postgresql-9.0-801.jdbc4.jar 
  • Apache Commons 
    • commons-dbcp-1.4.jar 
  • Spring 
    • spring-xxx-3.0.5.RELEASE.jar 

<b:bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="yourid">
    <b:property name="url" value="${yourprop.url}"/>
    <b:property name="username" value="${yourprop.username}"/>
    <b:property name="password" value="${yourprop.password}"/>
    <b:property name="driverClassName" value="${yourprop.driverClassName}"/>
    <b:property name="connectionProperties" value="ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory;">

Comments

Popular Posts