orchestracities / anubis

Anubis: a flexible policy enforcement solution for NGSI APIs (and beyond!)
https://anubis-pep.readthedocs.org
Apache License 2.0
8 stars 4 forks source link

read policy when a token is passed should return policies controlled by the user #150

Open github-actions[bot] opened 2 years ago

github-actions[bot] commented 2 years ago

https://github.com/orchestracities/anubis/blob/10a293c0a67a0bd320d0c1ce1d0a14dac5070894/anubis-management-api/anubis/policies/routers.py#L339


      - Resource
      - Resource Type
    In case an JWT token is passed over, user id, roles and groups are used to
    filter policies that are only valid for him. Unless the user is super admin or tenant admin.
    To return policies from a service path tree, you can used the wildchar "#".
    For example, using `/Path1/#` you will obtain policies for all subpaths,
    such as: `/Path1/SubPath1` or `/Path1/SubPath1/SubSubPath1`.
    """
    user_info = parse_auth_token(token)
    owner = None
    if user_info and user_info['is_super_admin']:
        owner = None
    elif user_info and user_info['tenants'] and fiware_service in user_info['tenants'] and "roles" in user_info['tenants'][fiware_service] and "tenant-admin" in user_info['tenants'][fiware_service]["roles"]:
        owner = None
    elif user_info and user_info['email']:
        owner = user_info['email']
    # we don't filter policies in case super admin or tenant admin
    # TODO CHANGE LOGIC IT SHOULD LIST POLICIES I CONTROL
    if agent_type and agent_type not in default.DEFAULT_AGENTS and agent_type not in default.DEFAULT_AGENT_TYPES:
        raise HTTPException(
            status_code=422,