Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sync_gateway couchbase requireRole

I have a problem with the roles of Sync_gateway. My sync_function throws an missing role error at requireRole("adminSync");.

I'm accessing with user admin1 that is configured as it follows:

  "name": "admin1",
  "all_channels": {},
  "passwordhash_bcrypt": "**************",
  "explicit_roles": {
    "adminSync": 1
  },
  "rolesSince": {
    "adminSync": 1
  }

Also I have the role configured as:

{
  "name": "adminSync",
  "admin_channels": {
    "CH_HORAS": 1,
    "CH_PERSONAS": 1,
    "CH_PROYECTOS": 1
  },
  "all_channels": {
    "CH_HORAS": 1,
    "CH_PERSONAS": 1,
    "CH_PROYECTOS": 1
  }
}

Any idea of this error??

Thanks.

like image 453
pikap Avatar asked Jun 09 '14 14:06

pikap


1 Answers

Re, I found out what was wrong,

The variable realUserCtx.roles is a map, so according to the requireRole(..) which needs to compare two arrays, it always return false.

So I needed to change the source code of src/channels/sync_runner.go to convert this map into an array before the comparison.

function mapToArray(mapObject){
        var _array = [];
        if(mapObject){
            for (var property in mapObject) {
                _array.push(property);
            }
        }
        return _array;
    }

then..

function requireRole(roles) {
    ...
    if (!anyInArray(mapToArray(realUserCtx.roles), roles))
    }

If you need more explanations you can contact me in private message. Good luck

like image 56
Karl V. Avatar answered Oct 29 '22 16:10

Karl V.