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?

2
  • Did you mean a LDAP server? Commented Jul 9, 2013 at 14:58
  • No, it's a Java application integrating with a Windows ecosystem. Commented Jul 10, 2013 at 13:10

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.