本文介绍了我该如何配置SQL Server数据源在JBoss中使用特定的Active Directory用户连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JBoss的运行与Active Directory用户 ABC \ APPUSER 。我想连接到MS SQL Server的8.0数据库作为AD用户 ABC \ DBUSER 。使用参数 integratedSecurity = TRUE ,除非我指定用户= ABC \ DBUSER;密码= DBPASS 在连接URL时,系统会尝试连接的服务AD用户, ABC \ APPUSER

每this问题,我已经证实,通过下面的网址,我可以连接到数据库 ABC \ DBUSER 运行应用程序的时, ABC \ APPUSER

<$p$p><$c$c>jdbc:sqlserver://MYHOSTNAME:1433;DatabaseName=MyDatabaseName;integratedSecurity=true;user=ABC\dbuser;password=dbpass

不幸的是,当我设置的URL,在JBoss配置XML数据源( JBoss的\ jboss的-EAP-6.1.0 \独立\配置\ standalone.xml )如下:

 &LT;数据源JNDI名称=java的:JBoss的/数据源/ MyDatabaseName池名=MyPoolName启用=真正的使用Java的上下文=真与GT ;
  <connection-url>jdbc:sqlserver://MYHOSTNAME:1433;DatabaseName=MyDatabaseName;integratedSecurity=true;user=ABC\dbuser;password=dbpass</connection-url>
  &LT;驱动器&GT; SQLSERVER&LT; /驱动器&GT;
  &LT;游泳池&GT;
    &LT;分池大小大于1&LT; /分池大小&GT;
    &LT;最大池大小&GT; 10&LT; / max一池的大小和GT;
    &LT; pre灌注&GT;真&LT; / pre灌注&GT;
  &LT; /池&GT;
  &LT;安全&GT;
    &lt;使用者-名称&gt;&LT; /用户名称&gt;
    &LT;密码&GT;&LT; /密码&GT;
  &LT; /安全&GT;
&LT; /数据源&GT;
 

我无法建立与此警告池资源:

  WARN
[org.jboss.jca.core.connectionmanager.pool.strategy.OnePool](JCA PoolFiller)
IJ000610:无法填补池:
javax.resource.ResourceException:无法创建连接
 

用户名密码 XML项设置的值会创建一个类似的故障警告。

我目前的解决方法的选择似乎是任何的:

  1. 在扩展任何类的JBoss被用来创建这个数据源,与适用的连接网址值如预期或自定义类替换它
  2. 变化的JBoss为 ABC \ DBUSER
  3. 运行
  4. 给JBoss服务用户 ABC \ APPUSER 由要么给它直接访问或访问将它添加到AD组数据库的访问。

所有这些解决方法是preferable;必须有一个更优雅的,接受的解决方案。我该如何解决此问题?

解决方案

我很惊讶的连接字符串工作。我的理解是,在微软的integratedSecurity酒店所提供的JDBC驱动程序的等效.NET连接字符串中的工作方式相同的集成安全或受信任的连接属性。

也就是说,设置integratedSecurity为true使JDBC驱动程序有效地忽略所提供的用户名和密码,并试图登录作为应用程序运行的用户。

我没有与Microsoft SQL Server驱动程序的解决方案,但这个问题可以通过使用开放源码 JTDS JDBC来解决司机

有关的很大一部分,你应该能够换出的JDBC驱动程序JAR文件和调整的连接XML看起来是这样的:

 &LT;数据源JNDI名称=java的:JBoss的/数据源/ MyDatabaseName池名=MyPoolName启用=真正的使用Java的上下文=真与GT ;
  <connection-url>jdbc:jtds:sqlserver://MYHOSTNAME:1433/MyDatabaseName;domain=ABC</connection-url>
  &LT;驱动器&GT; JTDS&LT; /驱动器&GT;
  &LT;游泳池&GT;
    &LT;分池大小大于1&LT; /分池大小&GT;
    &LT;最大池大小&GT; 10&LT; / max一池的大小和GT;
    &LT; pre灌注&GT;真&LT; / pre灌注&GT;
  &LT; /池&GT;
  &LT;安全&GT;
    &lt;使用者名称&GT; DBUSER&LT; /用户名称&gt;
    &LT;密码&GT; DBPASS&LT; /密码&GT;
  &LT; /安全&GT;
&LT; /数据源&GT;
 

根据您连接到您的SQL Server的配置可能还需要添加 useNTLMv2 = TRUE 来连接URL。

即。整个连接网址是:

JDBC:JTDS:SQLSERVER:// MYHOSTNAME:1433 / MyDatabaseName;域= ABC; useNTLMv2 =真

编辑:不幸的是JBoss中的EAP你的目标增加一个新的JDBC驱动程序是不一样滴罐在正确的地方容易的版本

下面是添加新的JDBC驱动程序相当繁琐的说明:

  1. 创建文件夹JBOSS_HOME \模块\网络\ sourceforge上\ JTDS \主

  2. 复制文件JTDS-1.3.1.jar到该文件夹​​。

  3. 创建一个名为module.xml包含以下内容的文件夹中的文件

     &LT; XML版本=1.0编码=UTF-8&GT?;
    &LT;模块的xmlns =金塔:JBoss的:模块:1.0NAME =net.sourceforge.jtds&GT;
      &LT;资源&GT;
        &LT;资源根路径=JTDS-1.3.1.jar/&GT;
      &LT; /资源&GT;
      &LT;依赖&GT;
        &LT;模块名称=javax.api/&GT;
        &LT;模块名称=javax.transaction.api/&GT;
      &LT; /依赖性&GT;
    &LT; /模块&GT;
     

  4. 添加以下XML来standalone.xml(修改驱动程序元素添加驱动元件,如果它已经存在)

     &LT;驱动&GT;
      &LT;驱动程序名称=JTDS模块=net.sourceforge.jtds&GT;
        &LT;驱动级&GT; net.sourceforge.jtds.jdbc.Driver&LT; /驱动器级&GT;
      &LT; /驱动器&GT;
    &LT; /驱动器&GT;
     

JBoss runs as Active Directory user ABC\appuser. I want to connect to a MS SQL Server 8.0 database as AD user ABC\dbuser. Using parameter integratedSecurity=true, unless I specify user=ABC\dbuser;password=dbpass on the connection url, the system will try to connect as the service AD user, ABC\appuser.

Per this question, I have confirmed that by using the following url, I can connect to the database as ABC\dbuser when running the application as ABC\appuser:

jdbc:sqlserver://MYHOSTNAME:1433;DatabaseName=MyDatabaseName;integratedSecurity=true;user=ABC\dbuser;password=dbpass

Unfortunately, when I set the url for the datasource in the JBoss configuration xml ( JBoss\jboss-eap-6.1.0\standalone\configuration\standalone.xml ) as follows:

<datasource jndi-name="java:jboss/datasources/MyDatabaseName" pool-name="MyPoolName" enabled="true" use-java-context="true">
  <connection-url>jdbc:sqlserver://MYHOSTNAME:1433;DatabaseName=MyDatabaseName;integratedSecurity=true;user=ABC\dbuser;password=dbpass</connection-url>
  <driver>sqlserver</driver>
  <pool>
    <min-pool-size>1</min-pool-size>
    <max-pool-size>10</max-pool-size>
    <prefill>true</prefill>
  </pool>
  <security>
    <user-name></user-name>
    <password></password>
  </security>
</datasource>

I am unable to create the pool resource with this warning:

WARN  
[org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (JCA PoolFiller) 
IJ000610: Unable to fill pool: 
javax.resource.ResourceException: Could not create connection

Setting values for user-name and password XML entries creates a similar failure warning.

My current workaround options seem to be any of:

  1. extending whichever class JBoss is using to create this datasource, replacing it with a custom class that applies the connection-url value as expected or
  2. changing JBoss to run as ABC\dbuser or
  3. giving the JBoss service user ABC\appuser database access by either giving it direct access or adding it to an AD Group with access.

None of these workarounds is preferable; there must be a more elegant, accepted solution. How can I resolve this?

解决方案

I'm surprised the connection string is working. My understanding was that the integratedSecurity property in the Microsoft provided JDBC driver worked the same way as the Integrated Security or Trusted Connection properties in the equivalent .NET connection string.

That is to say that setting integratedSecurity to true makes the JDBC driver effectively ignore the user and password provided and attempt to login as the user that the application is running as.

I don't have a solution with the Microsoft SQL Server driver but this problem can be solved using the open source jTDS JDBC Driver.

For the large part you should be able to swap out the JDBC driver JAR file and tweak the connection XML to look something like this:

<datasource jndi-name="java:jboss/datasources/MyDatabaseName" pool-name="MyPoolName" enabled="true" use-java-context="true">
  <connection-url>jdbc:jtds:sqlserver://MYHOSTNAME:1433/MyDatabaseName;domain=ABC</connection-url>
  <driver>jtds</driver>
  <pool>
    <min-pool-size>1</min-pool-size>
    <max-pool-size>10</max-pool-size>
    <prefill>true</prefill>
  </pool>
  <security>
    <user-name>dbuser</user-name>
    <password>dbpass</password>
  </security>
</datasource>

Depending on the configuration of the SQL Server you are connecting to you may need to also add useNTLMv2=true to the connection URL.

i.e. the entire connection URL would be:

jdbc:jtds:sqlserver://MYHOSTNAME:1433/MyDatabaseName;domain=ABC;useNTLMv2=true

EDIT: Unfortunately in the version of JBoss EAP you're targeting adding a new JDBC driver isn't as easy as dropping the jar in the right place.

Here are the rather cumbersome instructions for adding the new JDBC driver:

  1. Create the folder JBOSS_HOME\modules\net\sourceforge\jtds\main

  2. Copy the file jtds-1.3.1.jar into the folder.

  3. Create a file named module.xml in the folder with the following contents

    <?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.0" name="net.sourceforge.jtds">
      <resources>
        <resource-root path="jtds-1.3.1.jar"/>
      </resources>
      <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
      </dependencies>
    </module>
    

  4. Add the following XML to standalone.xml (modify the drivers element to add the driver element if it already exists)

    <drivers>
      <driver name="jtds" module="net.sourceforge.jtds">
        <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
      </driver>
    </drivers>
    

这篇关于我该如何配置SQL Server数据源在JBoss中使用特定的Active Directory用户连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 01:04