Hello,
I have a simple springboot application which is connecting to mongodb atlas using x509. The error message is as below:
18:45:05.239 [main] INFO org.mongodb.driver.client - MongoClient with metadata {"driver": {"name": "mongo-java-driver|sync", "version": "4.6.1"}, "os": {"type": "Windows", "name": "Windows 10", "architecture": "amd64", "version": "10.0"}, "platform": "Java/Oracle Corporation/1.8.0_271-b09"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=majority, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=MongoCredential{mechanism=MONGODB-X509, userName='null', source='$external', password=<hidden>, mechanismProperties=<hidden>}, streamFactoryFactory=null, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.Jep395RecordCodecProvider@7791a895]}, clusterSettings={hosts=[127.0.0.1:27017], srvHost=SANDBOX_LOCATION, srvServiceName=mongodb, mode=MULTIPLE, requiredClusterType=REPLICA_SET, requiredReplicaSetName='atlas-14aia3-shard-0', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='30000 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, sendBufferSize=0}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, sendBufferSize=0}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=true, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=UNSPECIFIED, serverApi=ServerApi{version=V1, deprecationErrors=null, strict=null}, autoEncryptionSettings=null, contextProvider=null}
18:45:05.250 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-srv-SANDBOX_LOCATION] INFO org.mongodb.driver.cluster - Adding discovered server sandbox-shard-00-01.zvy8h.mongodb.net:27017 to client view of cluster
18:45:05.264 [main] INFO org.mongodb.driver.cluster - Cluster description not yet available. Waiting for 30000 ms before timing out
18:45:05.283 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-srv-SANDBOX_LOCATION] INFO org.mongodb.driver.cluster - Adding discovered server sandbox-shard-00-02.zvy8h.mongodb.net:27017 to client view of cluster
18:45:05.284 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-srv-SANDBOX_LOCATION] INFO org.mongodb.driver.cluster - Adding discovered server SANDBOX_LOCATION:27017 to client view of cluster
18:45:05.287 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-srv-SANDBOX_LOCATION] DEBUG org.mongodb.driver.cluster - Updating cluster description to {type=REPLICA_SET, servers=[{address=sandbox-shard-00-01.zvy8h.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, {address=SANDBOX_LOCATION:27017, type=UNKNOWN, state=CONNECTING}, {address=sandbox-shard-00-02.zvy8h.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}]
18:45:05.302 [main] INFO org.mongodb.driver.cluster - No server chosen by com.mongodb.client.internal.MongoClientDelegate$1@704a52ec from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=sandbox-shard-00-01.zvy8h.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=SANDBOX_LOCATION:27017, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=sandbox-shard-00-02.zvy8h.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
18:45:07.391 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:2, serverValue:109113}] to SANDBOX_LOCATION:27017
18:45:07.391 [cluster-rtt-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:1, serverValue:106109}] to SANDBOX_LOCATION:27017
18:45:07.392 [cluster-rtt-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:4, serverValue:109113}] to SANDBOX_LOCATION:27017
18:45:07.393 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:5, serverValue:110945}] to SANDBOX_LOCATION:27017
18:45:07.393 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:3, serverValue:106109}] to SANDBOX_LOCATION:27017
18:45:07.392 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=SANDBOX_LOCATION:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=13, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=1070126600, setName='atlas-14aia3-shard-0', canonicalAddress=SANDBOX_LOCATION:27017, hosts=[SANDBOX_LOCATION:27017, SANDBOX_LOCATION:27017, SANDBOX_LOCATION:27017], passives=[], arbiters=[], primary='SANDBOX_LOCATION:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=7fffffff000000000000020b, setVersion=10, topologyVersion=TopologyVersion{processId=6357f67f41bb24fc0e204756, counter=6}, lastWriteDate=Wed Oct 26 18:47:55 IST 2022, lastUpdateTimeNanos=31725277708200}
18:45:07.393 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=SANDBOX_LOCATION:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=13, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=1069773000, setName='atlas-14aia3-shard-0', canonicalAddress=SANDBOX_LOCATION:27017, hosts=[SANDBOX_LOCATION:27017, SANDBOX_LOCATION:27017, SANDBOX_LOCATION:27017], passives=[], arbiters=[], primary='SANDBOX_LOCATION:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=null, setVersion=10, topologyVersion=TopologyVersion{processId=6357efd39128363c5c6845f4, counter=4}, lastWriteDate=Wed Oct 26 18:47:55 IST 2022, lastUpdateTimeNanos=31725277361900}
18:45:07.393 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=SANDBOX_LOCATION:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=13, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=1068864000, setName='atlas-14aia3-shard-0', canonicalAddress=SANDBOX_LOCATION:27017, hosts=[SANDBOX_LOCATION:27017, SANDBOX_LOCATION:27017, SANDBOX_LOCATION:27017], passives=[], arbiters=[], primary='SANDBOX_LOCATION:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=null, setVersion=10, topologyVersion=TopologyVersion{processId=6357f880fe3872997c6064b0, counter=3}, lastWriteDate=Wed Oct 26 18:47:55 IST 2022, lastUpdateTimeNanos=31725276468500}
18:45:07.397 [cluster-rtt-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:6, serverValue:110945}] to SANDBOX_LOCATION:27017
18:45:07.399 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] DEBUG org.mongodb.driver.connection - Marking the connection pool for ServerId{clusterId=ClusterId{value='635932d941f8df4d23f8ee64', description='null'}, address=SANDBOX_LOCATION:27017} as 'ready'
18:45:07.401 [MaintenanceTimer-3-thread-1] DEBUG org.mongodb.driver.connection - Pruning pooled connections to SANDBOX_LOCATION:27017
18:45:07.402 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.cluster - Setting max election id to 7fffffff000000000000020b from replica set primary SANDBOX_LOCATION:27017
18:45:07.403 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.cluster - Setting max set version to 10 from replica set primary SANDBOX_LOCATION:27017
18:45:07.403 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] INFO org.mongodb.driver.cluster - Discovered replica set primary SANDBOX_LOCATION:27017
18:45:07.404 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] DEBUG org.mongodb.driver.cluster - Updating cluster description to {type=REPLICA_SET, servers=[{address=SANDBOX_LOCATION:27017, type=UNKNOWN, state=CONNECTING}, {address=SANDBOX_LOCATION:27017, type=UNKNOWN, state=CONNECTING}, {address=SANDBOX_LOCATION:27017, type=REPLICA_SET_PRIMARY, TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, roundTripTime=1070.1 ms, state=CONNECTED}]
18:45:07.404 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] DEBUG org.mongodb.driver.cluster - Checking status of SANDBOX_LOCATION:27017
18:45:07.405 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] DEBUG org.mongodb.driver.connection - Marking the connection pool for ServerId{clusterId=ClusterId{value='635932d941f8df4d23f8ee64', description='null'}, address=SANDBOX_LOCATION:27017} as 'ready'
18:45:07.405 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] DEBUG org.mongodb.driver.cluster - Updating cluster description to {type=REPLICA_SET, servers=[{address=SANDBOX_LOCATION:27017, type=UNKNOWN, state=CONNECTING}, {address=SANDBOX_LOCATION:27017, type=REPLICA_SET_SECONDARY, TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, roundTripTime=1069.8 ms, state=CONNECTED}, {address=SANDBOX_LOCATION:27017, type=REPLICA_SET_PRIMARY, TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, roundTripTime=1070.1 ms, state=CONNECTED}]
18:45:07.406 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] DEBUG org.mongodb.driver.cluster - Checking status of SANDBOX_LOCATION:27017
18:45:07.406 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] DEBUG org.mongodb.driver.connection - Marking the connection pool for ServerId{clusterId=ClusterId{value='635932d941f8df4d23f8ee64', description='null'}, address=SANDBOX_LOCATION:27017} as 'ready'
18:45:07.407 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] DEBUG org.mongodb.driver.cluster - Updating cluster description to {type=REPLICA_SET, servers=[{address=SANDBOX_LOCATION:27017, type=REPLICA_SET_SECONDARY, TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, roundTripTime=1068.9 ms, state=CONNECTED}, {address=SANDBOX_LOCATION:27017, type=REPLICA_SET_SECONDARY, TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, roundTripTime=1069.8 ms, state=CONNECTED}, {address=SANDBOX_LOCATION:27017, type=REPLICA_SET_PRIMARY, TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, roundTripTime=1070.1 ms, state=CONNECTED}]
18:45:07.407 [cluster-ClusterId{value='635932d941f8df4d23f8ee64', description='null'}-SANDBOX_LOCATION:27017] DEBUG org.mongodb.driver.cluster - Checking status of SANDBOX_LOCATION:27017
18:45:07.409 [MaintenanceTimer-2-thread-1] DEBUG org.mongodb.driver.connection - Pruning pooled connections to SANDBOX_LOCATION:27017
18:45:07.409 [MaintenanceTimer-4-thread-1] DEBUG org.mongodb.driver.connection - Pruning pooled connections to SANDBOX_LOCATION:27017
18:45:08.902 [main] DEBUG org.mongodb.driver.connection - Closing connection connectionId{localValue:7, serverValue:109450}
18:45:08.911 [main] DEBUG org.mongodb.driver.connection - Closed connection [connectionId{localValue:7, serverValue:109450}] to SANDBOX_LOCATION:27017 because there was a socket exception raised by this connection.
18:45:08.918 [main] DEBUG org.mongodb.driver.cluster - Updating cluster description to {type=REPLICA_SET, servers=[{address=SANDBOX_LOCATION:27017, type=REPLICA_SET_SECONDARY, TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, roundTripTime=1068.9 ms, state=CONNECTED}, {address=SANDBOX_LOCATION:27017, type=REPLICA_SET_SECONDARY, TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, roundTripTime=1069.8 ms, state=CONNECTED}, {address=SANDBOX_LOCATION:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating}, caused by {com.mongodb.MongoCommandException: Command failed with error 8000 (AtlasError): 'certificate validation failed' on server SANDBOX_LOCATION:27017. The full response is {"ok": 0, "errmsg": "certificate validation failed", "code": 8000, "codeName": "AtlasError"}}}]
18:45:08.924 [main] DEBUG org.mongodb.driver.connection - Invalidating the connection pool for ServerId{clusterId=ClusterId{value='635932d941f8df4d23f8ee64', description='null'}, address=SANDBOX_LOCATION:27017} and marking it as 'paused' due to com.mongodb.MongoSecurityException: Exception authenticating
18:45:08.925 [main] DEBUG org.mongodb.driver.connection - Closing connection connectionId{localValue:2, serverValue:109113}
18:45:08.925 [MaintenanceTimer-3-thread-1] DEBUG org.mongodb.driver.connection - Pruning pooled connections to SANDBOX_LOCATION:27017
18:45:08.931 [main] DEBUG org.mongodb.driver.operation - Unable to retry an operation due to the error "com.mongodb.MongoSecurityException: Exception authenticating"
Exception in thread "main" com.mongodb.MongoSecurityException: Exception authenticating
at com.mongodb.internal.connection.X509Authenticator.authenticate(X509Authenticator.java:57)
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.authenticate(InternalStreamConnectionInitializer.java:207)
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.finishHandshake(InternalStreamConnectionInitializer.java:81)
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:185)
at com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:54)
at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.open(DefaultConnectionPool.java:535)
at com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openWithConcurrencyLimit(DefaultConnectionPool.java:911)
at com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openOrGetAvailable(DefaultConnectionPool.java:852)
at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:178)
at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:167)
at com.mongodb.internal.connection.DefaultServer.getConnection(DefaultServer.java:103)
at com.mongodb.internal.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:175)
at com.mongodb.client.internal.ClientSessionBinding$SessionBindingConnectionSource.getConnection(ClientSessionBinding.java:192)
at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:592)
at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$3(OperationHelper.java:574)
at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:600)
at com.mongodb.internal.operation.OperationHelper.withSourceAndConnection(OperationHelper.java:573)
at com.mongodb.internal.operation.CommandOperationHelper.lambda$executeRetryableRead$5(CommandOperationHelper.java:211)
at com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:65)
at com.mongodb.internal.operation.CommandOperationHelper.executeRetryableRead(CommandOperationHelper.java:217)
at com.mongodb.internal.operation.CommandOperationHelper.executeRetryableRead(CommandOperationHelper.java:197)
at com.mongodb.internal.operation.AggregateOperationImpl.execute(AggregateOperationImpl.java:195)
at com.mongodb.internal.operation.AggregateOperation.execute(AggregateOperation.java:306)
at com.mongodb.internal.operation.CountDocumentsOperation.execute(CountDocumentsOperation.java:131)
at com.mongodb.internal.operation.CountDocumentsOperation.execute(CountDocumentsOperation.java:38)
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:191)
at com.mongodb.client.internal.MongoCollectionImpl.executeCount(MongoCollectionImpl.java:219)
at com.mongodb.client.internal.MongoCollectionImpl.countDocuments(MongoCollectionImpl.java:189)
at com.mongodb.client.internal.MongoCollectionImpl.countDocuments(MongoCollectionImpl.java:184)
at PROJECTNAME.capability.XXXXX.XXXXXXX.main(XXXXXXXX.java:57)
Caused by: com.mongodb.MongoCommandException: Command failed with error 8000 (AtlasError): 'certificate validation failed' on server SANDBOX_LOCATION:27017. The full response is {"ok": 0, "errmsg": "certificate validation failed", "code": 8000, "codeName": "AtlasError"}
at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:198)
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:413)
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:337)
at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:101)
at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:45)
at com.mongodb.internal.connection.X509Authenticator.authenticate(X509Authenticator.java:55)
... 29 more
Process finished with exit code 1
Thanks