kundera
kundera copied to clipboard
Not able to authenticate MongoDB - Kundera 2.15
Hello, We have authentication setup on MongoDB. We have used kundera-mongo(version 2.15) dependency. We have given the below mentioned properties in persistence.xml . But when we run the application, we get the error for the kundera.username and kundera.password properties. Below mentioned are the details of each step. Please let us know if any configuration changes or version changes needs to be done.
- We start the mongoDB using the command:
mongod --auth --dbpath D:\MongoDB-Path
- Persistence.xml looks like:
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="27017" />
<property name="kundera.keyspace" value="ATS_NEW" />
<property name="kundera.dialect" value="mongoDb" />
<property name="show_sql" value="true" />
<property name="kundera.client.lookup.class" value="com.impetus.client.mongodb.MongoDBClientFactory" />
<property name="kundera.username" value="admin" />
<property name="kundera.password" value="123456" />
<property name="kundera.ddl.auto.prepare" value="update" />
</properties>
</persistence-unit>
- Now when we try to run the application it gives the following error:
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoEntityManagerFactory' defined in class path resource [Beans.xml]: Invocation of init method failed; nested exception is com.impetus.kundera.configure.schema.SchemaGenerationException: com.impetus.kundera.loader.KunderaAuthenticationException: Authentication failed, invalid 'kundera.username' :adminand 'kundera.password' :123456 provided
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1488)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: com.impetus.kundera.configure.schema.SchemaGenerationException: com.impetus.kundera.loader.KunderaAuthenticationException: Authentication failed, invalid 'kundera.username' :adminand 'kundera.password' :123456 provided
at com.impetus.client.mongodb.schemamanager.MongoDBSchemaManager.initiateClient(MongoDBSchemaManager.java:235)
at com.impetus.kundera.configure.schema.api.AbstractSchemaManager.exportSchema(AbstractSchemaManager.java:112)
at com.impetus.client.mongodb.schemamanager.MongoDBSchemaManager.exportSchema(MongoDBSchemaManager.java:84)
at com.impetus.kundera.configure.SchemaConfiguration.configure(SchemaConfiguration.java:187)
at com.impetus.kundera.configure.ClientMetadataBuilder.buildClientFactoryMetadata(ClientMetadataBuilder.java:48)
at com.impetus.kundera.persistence.EntityManagerFactoryImpl.configureClientFactories(EntityManagerFactoryImpl.java:408)
at com.impetus.kundera.persistence.EntityManagerFactoryImpl.configure(EntityManagerFactoryImpl.java:161)
at com.impetus.kundera.persistence.EntityManagerFactoryImpl.
@sbheda
The configurations looks ok. Are you trying to access via same user with which you created the database ? Please verify if the credentials and access permissions to the user are appropriate.
You can look at the following test case for further details - https://github.com/impetus-opensource/Kundera/blob/4ab46233e39b87c5516e0f870dd581b79eaac265/src/kundera-mongo/src/test/java/com/impetus/client/crud/MongoAuthenticationTest.java
https://github.com/impetus-opensource/Kundera/blob/trunk/src/kundera-mongo/src/test/resources/META-INF/persistence.xml#L56
Chhavi
@sbheda
Did above solution work for you?
-Devender
@sbheda
Any updates ?
Chhavi