Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4389

Getting com.mongodb.MongoSecurityException: Failed to login Subject when connecting mongoDB

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Authentication

      Hi,

      To replace mongodb-java-driver 3.12.8, I am trying to make my code work this the following jars:

      mongodb-driver-sync-4.3.3.jar

      mongodb-driver-core-4.3.3.jar

      mongodb-driver-legacy-4.3.3.jar

      bson-4.3.3.jar

      I use the following code to connect:

       

       System.setProperty("java.security.krb5.conf", "krb5.conf"); 

      System.setProperty("java.security.krb5.conf", "krb5.conf");     System.setProperty("java.security.krb5.realm", "<<my-domain>>");     System.setProperty("java.security.krb5.kdc", "<<my-domain>>"");     System.setProperty("javax.security.auth.useSubjectCredsOnly","false");     System.setProperty("java.security.auth.login.config", "jaas.conf");    

      return new MongoClient(serverAddresses, MongoCredential.createGSSAPICredential("<<my-kerberos-id>>@<<my-domain>>"), options);

       

      my jaas.conf is as follows:

      com.sun.security.jgss.initiate

      { com.sun.security.auth.module.Krb5LoginModule required useKeyTab=true useTicketCache=false doNotPrompt=true debug=true keyTab="mykeytab.kt" principal="<<my-kerberos-id>>@<<my-domain>>; }

      ;

       

      I am getting below errors:

       

      INFO: Creating new LoginContext and logging in the principalException in thread "main" com.mongodb.MongoSecurityException: Failed to login Subject at com.mongodb.internal.connection.SaslAuthenticator.getSubject(SaslAuthenticator.java:200) at com.mongodb.internal.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:278) at com.mongodb.internal.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:57) at com.mongodb.internal.connection.InternalStreamConnectionInitializer.authenticate(InternalStreamConnectionInitializer.java:205) at com.mongodb.internal.connection.InternalStreamConnectionInitializer.finishHandshake(InternalStreamConnectionInitializer.java:79) at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:170) at com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:53) at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.open(DefaultConnectionPool.java:495) at com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openOrGetAvailable(DefaultConnectionPool.java:855) at com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter.openOrGetAvailable(DefaultConnectionPool.java:805) at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:154) at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:144) at com.mongodb.internal.connection.DefaultServer.getConnection(DefaultServer.java:92) at com.mongodb.internal.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:141) at com.mongodb.client.internal.ClientSessionBinding$SessionBindingConnectionSource.getConnection(ClientSessionBinding.java:163) at com.mongodb.internal.operation.ListCollectionsOperation$1.call(ListCollectionsOperation.java:233) at com.mongodb.internal.operation.ListCollectionsOperation$1.call(ListCollectionsOperation.java:230) at com.mongodb.internal.operation.OperationHelper.withReadConnectionSource(OperationHelper.java:583) at com.mongodb.internal.operation.ListCollectionsOperation.execute(ListCollectionsOperation.java:230) at com.mongodb.internal.operation.ListCollectionsOperation.execute(ListCollectionsOperation.java:86) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:184) at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135) at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92) at com.mongodb.client.internal.MappingIterable.iterator(MappingIterable.java:39) at com.mongodb.client.internal.MappingIterable.iterator(MappingIterable.java:27) at MyGFMongoTest.main(MyGFMongoTest.java:81)Caused by: javax.security.auth.login.LoginException: No LoginModules configured for com.sun.security.jgss.krb5.initiate at javax.security.auth.login.LoginContext.init(LoginContext.java:264) at javax.security.auth.login.LoginContext.<init>(LoginContext.java:348) at com.mongodb.KerberosSubjectProvider.getSubject(KerberosSubjectProvider.java:84) at com.mongodb.internal.connection.SaslAuthenticator.getSubject(SaslAuthenticator.java:198) ... 25 more

       

       

      The same code works with mongodb-java-driver-3.12.8.jar

       

      Please advise.

       

       

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            amy Amy Cui
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: