db.addUser( { user: "author", userSource: "users", roles: [ "readWrite" ] } )
db.addUser( "guest", "pass", { readOnly: true } )
db.addUser( "guest", "pass", { readOnly: false} )
java.lang.NullPointerException
at \\...\\ .\\हिñçêČάй語简??한\\.Hꅇꁕ⣈ᡬ.a(Unknown Source)
at \\...\\ .\\हिñçêČάй語简??한\\.Hꅇꁕ⣈ᡬ.a(Unknown Source)
at \\...\\ .\\हिñçêČάй語简??한\\.B᛭⡖ꇋꑭ private finally.a(Unknown Source)
at \\...\\ .\\हिñçêČάй語简??한\\.Hꅇꁕ⣈ᡬ.aq(Unknown Source)
at \\...\\ .\\हिñçêČάй語简??한\\.Gᜱꐬꂣꉖ catch.iM(Unknown Source)
at \\...\\ .\\हिñçêČάй語简??한\\.Gᜱꐬꂣꉖ catch.execute(Unknown Source)
at \\...\\ .\\हिñçêČάй語简??한\\.M⠹ꎀꄍꏣ float enum.execute(Unknown Source)
at com.common.ui.tree.r⢇⡫ꌏꊺ protected.cH(Unknown Source)
at com.common.ui.tree.Cꀓꎋ⡬͝ return.process(Unknown Source)
at com.common.ui.util.BackgroundThread.run(Unknown Source)
|
110 KB
I was able to reproduce the error on a different server in Windows when i created a new user using the command db.addUser( "guest", "pass", { readOnly: true } )
OK, I'll fix the ClassCastException, but I think that in your scenario the readOnly parameter is wrongly fed to the addUser() method. The MongoDB documentation for this method mentions the legacy version of it:
Parameters:
- user (string) – Specifies the username.
- password (string) – Specifies the corresponding password.
- readOnly (boolean) – Optional. Defaults to false. Grants users a restricted privilege set that only allows the user to read the this database.
db.addUser( "<username>", "<password>", { readOnly: <boolean> } )
The readOnly parameter is not a JSON object, but a boolean one. I think the curly braces have in this case the sense of "optional parameter".
The JavaScript definition of this method (you can see it by calling > db.<functionName>
under MongoShell without the round braces) proves my statement:
> db.addUser
function () {
if (arguments.length == 0) {
throw Error("No arguments provided to addUser");
}
if (typeof arguments[0] == "object") {
this._addUser.apply(this, arguments);
} else {
this._addUserV22.apply(this, arguments);
}
}
> db._addUserV22
function ( username , pass, readOnly, replicatedTo, timeout ) {
if ( pass == null || pass.length == 0 )
throw "password can't be empty";
readOnly = readOnly || false; // <---- evaluated as boolean parameter
var c = this.getCollection( "system.users" );
var u = c.findOne({user : username, userSource:null}) || { user : username };
u.readOnly = readOnly;
u.pwd = _hashPassword(username, pass);
this._createUser(u, replicatedTo, timeout);
}
Compare it with the newer (2.4.x) version of this function, whose first argument is a JSON object:
> db._addUser
function (userObj, replicatedTo, timeout) {
var roles = userObj['roles']; // <-------- userObj argument evaluated as JSON object ( associative array )
var oldPwd;
....
Therefore, your call should be:
> db.addUser( "guest", "pass", true)
OK, I'll fix the ClassCastException, but I think that in your scenario the readOnly parameter is wrongly fed to the addUser() method. The MongoDB documentation for this method mentions the legacy version of it:
Parameters:
- user (string) – Specifies the username.
- password (string) – Specifies the corresponding password.
- readOnly (boolean) – Optional. Defaults to false. Grants users a restricted privilege set that only allows the user to read the this database.
db.addUser( "<username>", "<password>", { readOnly: <boolean> } )
The readOnly parameter is not a JSON object, but a boolean one. I think the curly braces have in this case the sense of "optional parameter".
The JavaScript definition of this method (you can see it by calling > db.<functionName>
under MongoShell without the round braces) proves my statement:
> db.addUser
function () {
if (arguments.length == 0) {
throw Error("No arguments provided to addUser");
}
if (typeof arguments[0] == "object") {
this._addUser.apply(this, arguments);
} else {
this._addUserV22.apply(this, arguments);
}
}
> db._addUserV22
function ( username , pass, readOnly, replicatedTo, timeout ) {
if ( pass == null || pass.length == 0 )
throw "password can't be empty";
readOnly = readOnly || false; // <---- evaluated as boolean parameter
var c = this.getCollection( "system.users" );
var u = c.findOne({user : username, userSource:null}) || { user : username };
u.readOnly = readOnly;
u.pwd = _hashPassword(username, pass);
this._createUser(u, replicatedTo, timeout);
}
Compare it with the newer (2.4.x) version of this function, whose first argument is a JSON object:
> db._addUser
function (userObj, replicatedTo, timeout) {
var roles = userObj['roles']; // <-------- userObj argument evaluated as JSON object ( associative array )
var oldPwd;
....
Therefore, your call should be:
> db.addUser( "guest", "pass", true)
The ClassCastException has been fixed on nosql-jdbc v1.1.1 .
The ClassCastException has been fixed on nosql-jdbc v1.1.1 .
Issue #8628 |
Closed |
Fixed |
Resolved |
Completion |
No due date |
Fixed Build nosql-jdbc 1.1.1 |
No time estimate |
1 issue link |
relates to #8848
Issue #8848User with readOnly is displayed with READWRITE ticked in user properties |
I was able to reproduce the error on a different server in Windows when i created a new user using the command db.addUser( "guest", "pass", { readOnly: true } )