简体   繁体   中英

Using Hibernate with MS SQL and domain user

Good morning,

I'm trying to connect to an MS SQL Server with Hibernate 4.3. Connecting with SSO and database credentials (username and password) works fine, but when I try to use a username with a domain (domain\\user) specification, I get the following exception.

java.lang.ExceptionInInitializerError
caused by com.microsoft.sqlserver.jdbc.sqlserverexception login failed for user
  • The username and password are valid (already checked).
  • Tryed it with \\\\ at the input and replaced it with \\ in the jdbc-string
  • Tryed to set the properties with

     ((org.hibernate.cfg.Configuration) configuration) .setProperty("hibernate.connection.username", "domain\\user\u0026quot;); 
  • Tryed to set the properties over the jdbc connection string

     jdbc:sqlserver://[IP]:[PORT];user=[domain\\user];password=[pwd];databaseName=[db] 
  • Tryed to encapsulate with \\' and \\" around the user and password.

It would be glad, if somebody can suggest how to get this work.

If some Informations are required, I will extend this post if requested.

Thanks.

UPDATE

The link mentioned by Mark Rotteveel mentioned the missing piece.

To continue using integrated authentication with sqljdbc_auth.dll, just specify integratedSecurity=true

connection property (and optionally authenticationScheme=NativeAuthentication ).

don't forget to specify the domain=[DOMAIN]; part

Specially the part of set the authenticationScheme was missing in the connection String. Without that, the SSO was used.

Now the jdbc connection string for the domain-users looks like:

jdbc:sqlserver://[IP]:[PORT];IntegratedSecurity=true;authenticationScheme=NativeAuthentication;sendStringParametersAsUnicode=false;selectMethod=cursor;domain=[DOMAIN];user=[DOMAIN\USER];password=[PW];databaseName=[DB];

Thanks for the replys and have a nice day.

PS: I didn't tested the possible solution with JDNI, which is suggested by BharatG. But thank you.

Can you try if one of the following works?

1) Place the connection properties as the JNDI settings

2) Escaping the username as "domain\\\\user\u0026quot; (not sure if this is what you tried in your 2nd bullet)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM