Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Loading conflicting grants from same level. #53

@PrashamTrivedi

Description

@PrashamTrivedi

Two grants are loaded from database.

const role1 = {
    role: 'role1',
     resource: 'person',
     action: ['create', 'view', 'treat'],
     attributes: ['*']
}

and

const role2 = {
    role: 'role2',
    resource: 'person',
    action: ['update', 'greet', '!create'],
    attributes: ['*'],
}

With following test code.

const grantsToLoad = [role1, role2]
ac.setGrants(grantsToLoad)

const roles = ac.getRoles()
const permission = await ac.can(roles).execute('create').on('person')
expect(permission.granted).toEqual(false)

I expect create to be denied as it being explicitly mentioned in action of role2. But the desired result is the permission to create is granted. Thus explicit denial is not taken into consideration.

The code behind this behavior is in filter of getUnionAttrsOfRolesSync where role2 is being filtered out in favor of positive action.

public static getUnionAttrsOfRolesSync(grants: any, query: IQueryInfo): string[] {
const matchingGrants = (this.getUnionGrantsOfRolesSync(grants, query))
.filter((grant) => {
return this.anyMatch(query.resource, grant.resource)
&& this.anyMatch(query.action, grant.action);
});
return (this.filterGrantsAllowingSync(matchingGrants, query))
.map((grant) => {
return ArrayUtil.toStringArray(grant.attributes);
}).reduce(Notation.Glob.union, []);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions