From 429052a0dbe38cb5ec2351f5ca8c93d1d80b9c4c Mon Sep 17 00:00:00 2001 From: haio Date: Sat, 3 May 2014 11:43:03 +0800 Subject: [PATCH] Ensure roleId and principalId to be string in Role#isInRole --- lib/models/role.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/models/role.js b/lib/models/role.js index 86ff5cc3..8b64796f 100644 --- a/lib/models/role.js +++ b/lib/models/role.js @@ -373,8 +373,14 @@ Role.isInRole = function (role, context, callback) { async.some(context.principals, function (p, done) { var principalType = p.type || undefined; var principalId = p.id || undefined; + var roleId = result.id.toString(); + + if(principalId !== null && principalId !== undefined && (typeof principalId !== 'string') ) { + principalId = principalId.toString(); + } + if (principalType && principalId) { - roleMappingModel.findOne({where: {roleId: result.id, + roleMappingModel.findOne({where: {roleId: roleId, principalType: principalType, principalId: principalId}}, function (err, result) { debug('Role mapping found: %j', result);