我正在尝试使用以下内容升级我的应用程序:
我正在使用OGM 5.1获得身份验证失败,但它适用于OGM 4.2
异常堆栈 -
com.mongodb.MongoSecurityException:异常验证MongoCredential {mechanism = null,userName =' prodhub',source =' admin',password =,mechanismProperties = {}} 在com.mongodb.connection.SaslAuthenticator.wrapInMongoSecurityException(SaslAuthenticator.java:157)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.SaslAuthenticator.access $ 200(SaslAuthenticator.java:37)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.SaslAuthenticator $ 1.run(SaslAuthenticator.java:66)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.SaslAuthenticator $ 1.run(SaslAuthenticator.java:44)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:162)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:44)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:109)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:46)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:116)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.DefaultServerMonitor $ ServerMonitorRunnable.run(DefaultServerMonitor.java:113)〜[mongo-java-driver-3.4.2.jar:na] 在java.lang.Thread.run(Thread.java:745)[na:1.8.0_72] 引起:com.mongodb.MongoCommandException:命令失败,错误18:'身份验证失败。'在服务器localhost:27017。完整的回答是{" ok" :0.0," errmsg" :"身份验证失败。","代码" :18," codeName" :" AuthenticationFailed" } 在com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:170)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:117)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.SaslAuthenticator.access $ 000(SaslAuthenticator.java:37)〜[mongo-java-driver-3.4.2.jar:na] 在com.mongodb.connection.SaslAuthenticator $ 1.run(SaslAuthenticator.java:50)〜[mongo-java-driver-3.4.2.jar:na] ...省略了9个常见帧
我遇到了这个jira - https://hibernate.atlassian.net/browse/OGM-791,这表明我可能需要进行mongo身份验证方案迁移。
我的持久性xml就像这样 -
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="productHub">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.ogm.datastore.provider" value="mongodb" />
<property name="hibernate.ogm.datastore.database" value="test" />
<!-- property name="hibernate.ogm.datastore.host" value="localhost" / -->
<!-- property name="hibernate.ogm.datastore.port" value="27017" / -->
<property name="hibernate.ogm.datastore.username" value="prodhub" />
<property name="hibernate.ogm.datastore.password" value="xxxxxxxxx" />
<property name="hibernate.ogm.mongodb.connection_timeout" value="6000" />
<!-- property name="hibernate.ogm.mongodb.authentication_mechanism" value="MONGODB_CR" / -->
<property name="hibernate.cache.use_second_level_cache" value="false" />
<!--
<property name="hibernate.search.default.directory_provider" value="filesystem" />
<property name="hibernate.search.default.indexBase" value="D:\\Projects\\prodhub\\lucene" />
<property name="jboss.as.jpa.managed" value="false" />
-->
</properties>
</persistence-unit>
</persistence>
mongo日志显示 -
2017-03-19T01:37:37.352 + 0530 I NETWORK [thread1]连接从127.0.0.1:62379#640接受(现已打开2个连接) 2017-03-19T01:37:37.353 + 0530 I NETWORK [conn640]从127.0.0.1:62379 conn640收到客户端元数据:{driver:{name:&#34; mongo-java-driver&#34;,version:&# 34; 3.4.2&#34; },os:{type:&#34; Windows&#34;,name:&#34; Windows 7&#34 ;, architecture:&#34; amd64&#34;,version:&#34; 6.1&#34; },平台:&#34; Java / Oracle Corporation / 1.8.0_72-b15&#34; } 2017-03-19T01:37:37.355 + 0530 I ACCESS [conn640]来自客户端127.0.0.1:62379的管理员prodhub的SCRAM-SHA-1认证失败; UserNotFound:找不到用户prodhub @ admin 2017-03-19T01:37:37.356 + 0530 I - [conn640] end connection 127.0.0.1:62379(2个连接现已开通)
如果我将身份验证机制更改为MONGODB_CR,我会收到以下日志消息 -
[conn667]从127.0.0.1:64331 conn667收到客户端元数据:{driver:{name:&#34; mongo-java-driver&#34;,version:&#34; 3.4.2&#34; },os:{type:&#34; Windows&#34;,name:&#34; Windows 7&#34 ;, architecture:&#34; amd64&#34;,version:&#34; 6.1&#34; },平台:&#34; Java / Oracle Corporation / 1.8.0_72-b15&#34; } 2017-03-19T15:10:33.346 + 0530 I ACCESS [conn667]认证db:admin {authenticate:1,user:&#34; prodhub&#34;,nonce:&#34; xxx&#34;,key:& #34; XXX&#34; } 2017-03-19T15:10:33.347 + 0530 I ACCESS [conn667]无法通过机制MONGODB-CR验证prodhub @ admin:AuthenticationFailed:UserNotFound:找不到用户prodhub @ admin 2017-03-19T15:10:33.349 + 0530 I - [conn667] end connection 127.0.0.1:64331(2个连接现已开启)
从错误堆栈&amp;日志消息,是否确认我需要完成此处提到的身份验证迁移过程 - https://docs.mongodb.com/manual/release-notes/3.0-scram/
或者我应该在进行升级之前查找更多诊断信息?
答案 0 :(得分:2)
我找到了解决方案。从这个线程 - MongoDb authentication using Hibernate OGM中获取线索,我在“admin”db中创建了用户,这似乎是mongo 3.x中的默认身份验证数据库。早些时候,用户居住在我的“测试”数据库中。
我想,将属性“hibernate.ogm.mongodb.authentication_database”设置为“test”可能也有效,但我还没有尝试过。