Java Driver
  1. Java Driver
  2. JAVA-247

authenticate method declares throw MongoException but doesn't actually throw it

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor - P4 Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: 2.5
    • Component/s: API
    • Labels:
      None
    • Backward Breaking:
      No
    • # Replies:
      3
    • Last comment by Customer:
      false

      Description

      The current signature in DB is like
      public boolean authenticate(String username, char[] passwd ) throws MongoException

      however the only things thrown by the method are NPE & IllegalStateException. It is confusing to suppose the failure to authenticate could throw an exception while in fact it only returns a boolean

        Activity

        Hide
        Antoine Girbal
        added a comment -

        it is actually possible that MongoException is thrown in the _doauth() call.
        this happens if it cannot get the auth message from server.

        Show
        Antoine Girbal
        added a comment - it is actually possible that MongoException is thrown in the _doauth() call. this happens if it cannot get the auth message from server.
        Hide
        Antoine Girbal
        added a comment -

        agreed with reporter that the existing authenticate() behavior is not consistent with rest of driver.
        In case the authentication returns an error from server, this method just returns false which means caller cannot know the error code and message.
        Added a new method below that will throw a MongoException in case the authentication fails.

        /**

        • Authenticates to db with the given name and password
          *
        • @param username name of user for this database
        • @param passwd password of user for this database
        • @return the CommandResult from authenticate command
        • @throws MongoException if authentication failed due to invalid user/pass, or other exceptions like I/O
        • @dochub authenticate
          */
          public CommandResult authenticateCommand(String username, char[] passwd )
        Show
        Antoine Girbal
        added a comment - agreed with reporter that the existing authenticate() behavior is not consistent with rest of driver. In case the authentication returns an error from server, this method just returns false which means caller cannot know the error code and message. Added a new method below that will throw a MongoException in case the authentication fails. /** Authenticates to db with the given name and password * @param username name of user for this database @param passwd password of user for this database @return the CommandResult from authenticate command @throws MongoException if authentication failed due to invalid user/pass, or other exceptions like I/O @dochub authenticate */ public CommandResult authenticateCommand(String username, char[] passwd )
        Hide
        auto
        added a comment -

        Author:

        {u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

        Message: JAVA-247: additional authenticate method
        https://github.com/mongodb/mongo-java-driver/commit/56e7a91ea90f6f0a45f1995b98906df10a089c80

        Show
        auto
        added a comment - Author: {u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'} Message: JAVA-247 : additional authenticate method https://github.com/mongodb/mongo-java-driver/commit/56e7a91ea90f6f0a45f1995b98906df10a089c80

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since reply:
              3 years, 9 weeks, 3 days ago
              Date of 1st Reply: