1

I am working on a Java project that runs on Linux/WebLogic that needs to integrate with an existing SQL Server instance that only allows authentication through a windows domain account. I've seen .Net applications use impersonation to connect and run the query as the domain account with the permissions.

Is there an equivalent way to do this with Java?

rynmrtn
  • 3,371
  • 5
  • 28
  • 44

1 Answers1

0

While this question is closely related to the potential duplicate, I'm going to post my answer in the hope that it is helpful to someone in the future.

What we did was define a non-jndi data source:

<bean id="nonJndiDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driver" value="net.sourceforge.jtds.jdbcx.JtdsDataSource"/>
    <property name="url" value="${url}"/>
    <property name="username" value="${user}"/>
    <property name="password" value="${password}"/>
    <property name="initialSize" value="${initial_size}"/>
    <property name="maxActive" value="${max_active}"/>
    <property name="maxWait" value="${max_wait}"/>
    <property name="minIdle" value="${min_idle}"/>
    <property name="maxIdle" value="${max_idle}"/>
</bean>

With the following properties file (that sets the values in the bean):

# Hibernate specific property
dialect=org.hibernate.dialect.SQLServer2008Dialect

# This is the key line
url=jdbc:jtds:sqlserver://127.0.0.1;databaseName=yourDatabase;useNTLMv2=true;domain=nameOfDomain

user=windows_account
password=password
initial_size=5
max_active=30
max_wait=600000
min_idle=0
max_idle=10

This can then be hooked into JDBC, Hibernate, JDBI, or some other JDBC based framework.

One gotcha at the time of this post is the version of jTDS. Version 1.3 requires Java 7 - we ended up pulling the jar for Version 1.2.x.

rynmrtn
  • 3,371
  • 5
  • 28
  • 44