[JAVA-247] authenticate method declares throw MongoException but doesn't actually throw it Created: 03/Jan/11  Updated: 17/Mar/11  Resolved: 15/Feb/11

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 2.4
Fix Version/s: 2.5

Type: Improvement Priority: Minor - P4
Reporter: Koen Serry Assignee: Antoine Girbal
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 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



 Comments   
Comment by auto [ 15/Feb/11 ]

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

Comment by Antoine Girbal [ 15/Feb/11 ]

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 )
Comment by Antoine Girbal [ 04/Feb/11 ]

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

Generated at Thu Feb 08 08:51:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.