示例#1
0
def pdp_main(db_session, pdp_request):
    check_request(pdp_request)
    jwt_payload = get_jwt_payload(pdp_request['jwt'])
    user_id = jwt_payload['userid']

    # try to retrieve the veredict from cache
    cached_veredict = cache.get_key(user_id, pdp_request['action'],
                                    pdp_request['resource'])
    # Return the cached answer if it exist
    if cached_veredict:
        LOGGER.info('user ' + str(user_id) + ' ' + cached_veredict + ' to ' +
                    pdp_request['action'] + ' on ' + pdp_request['resource'] +
                    ' from cache')
        return cached_veredict

    user_groups = [
        g.group_id for g in UserGroup.query.filter_by(user_id=user_id).all()
    ]

    veredict = iterate_permissions(user_id, user_groups, pdp_request['action'],
                                   pdp_request['resource'])
    # Registry this veredict on cache
    cache.set_key(user_id, pdp_request['action'], pdp_request['resource'],
                  veredict)

    LOGGER.info('user ' + str(user_id) + ' ' + veredict + ' to ' +
                pdp_request['action'] + ' on ' + pdp_request['resource'] +
                ' registered on cache')
    return veredict
示例#2
0
def pdp_main(db_session, pdp_request):
    check_request(pdp_request)
    jwt_payload = get_jwt_payload(pdp_request['jwt'])
    user_id = jwt_payload['userid']

    # try to retrieve the veredict from cache
    cached_veredict = cache.get_key(user_id, pdp_request['action'],
                                    pdp_request['resource'])
    # Return the cached answer if it exist
    if cached_veredict:
        log().info('user ' + str(user_id) + ' ' + cached_veredict + ' to ' +
                   pdp_request['action'] + ' on ' + pdp_request['resource'])
        return cached_veredict

    veredict = iterate_permissions(user_id, jwt_payload['groups'],
                                   pdp_request['action'],
                                   pdp_request['resource'])
    # Registry this veredict on cache
    cache.set_key(user_id, pdp_request['action'], pdp_request['resource'],
                  veredict)

    log().info('user ' + str(user_id) + ' ' + veredict + ' to ' +
               pdp_request['action'] + ' on ' + pdp_request['resource'])
    return veredict