Skip to content

Commit

Permalink
SERVER-2917: REST interface now authenticate user to db when user suc…
Browse files Browse the repository at this point in the history
…cessfully authenticates to web server
  • Loading branch information
Tony Hannan committed Oct 19, 2011
1 parent ad39dc9 commit 068cad4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions db/dbwebserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ namespace mongo {
}

bool allowed( const char * rq , vector<string>& headers, const SockAddr &from ) {
if ( from.isLocalHost() )
return true;

if ( ! _webUsers->haveAdminUsers() )
if ( from.isLocalHost() || !_webUsers->haveAdminUsers() ) {
cmdAuthenticate.authenticate( "admin", "RestUser", false );
return true;
}

string auth = getHeader( rq , "Authorization" );

Expand Down Expand Up @@ -118,8 +117,10 @@ namespace mongo {
r << ha2;
string r1 = md5simpledigest( r.str() );

if ( r1 == parms["response"] )
if ( r1 == parms["response"] ) {
cmdAuthenticate.authenticate( "admin", user["user"].str(), user[ "readOnly" ].isBoolean() && user[ "readOnly" ].boolean() );
return true;
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion db/security_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ namespace mongo {
virtual void help(stringstream& ss) const { ss << "internal"; }
CmdAuthenticate() : Command("authenticate") {}
bool run(const string& dbname , BSONObj& cmdObj, int options, string& errmsg, BSONObjBuilder& result, bool fromRepl);
void authenticate(const string& dbname, const string& user, const bool readOnly);
private:
bool getUserObj(const string& dbname, const string& user, BSONObj& userObj, string& pwd);
void authenticate(const string& dbname, const string& user, const bool readOnly);
};

extern CmdAuthenticate cmdAuthenticate;

class CmdLogout : public Command {
public:
Expand Down

0 comments on commit 068cad4

Please sign in to comment.