def authorize(user, action, resource, resource_id, payload):
    'Authorize user/action/resource'
    del payload
    _LOGGER.info('Authorize: %s %s %s %s', user, action, resource, resource_id)
    proid = None
    if resource_id:
        proid = resource_id.partition('.')[0]
    why = []
    for group_template in groups:
        group_name = _group(group_template, action=action, resource=resource, proid=proid)
        _LOGGER.info('Check authorization group: %s', group_name)
        try:
            group = grp.getgrnam(group_name)
            username = user.partition('@')[0]
            members = group.gr_mem
            _LOGGER.info('Authorized: User %s is member of %s.', username, group_name)
            if (username in members):
                return (True, why)
            else:
                why.append('{} not member of {}'.format(username, group_name))
        except KeyError:
            _LOGGER.info('Group does not exist: %s', group_name)
            why.append('no such group: {}'.format(group_name))
    return (False, why)
Authorize user/action/resource
def authorize(user, action, resource, resource_id, payload):
    
    del payload
    _LOGGER.info('Authorize: %s %s %s %s', user, action, resource, resource_id)
    proid = None
    if resource_id:
        proid = resource_id.partition('.')[0]
    why = []
    for group_template in groups:
        group_name = _group(group_template, action=action, resource=resource, proid=proid)
        _LOGGER.info('Check authorization group: %s', group_name)
        try:
            group = grp.getgrnam(group_name)
            username = user.partition('@')[0]
            members = group.gr_mem
            _LOGGER.info('Authorized: User %s is member of %s.', username, group_name)
            if (username in members):
                return (True, why)
            else:
                why.append('{} not member of {}'.format(username, group_name))
        except KeyError:
            _LOGGER.info('Group does not exist: %s', group_name)
            why.append('no such group: {}'.format(group_name))
    return (False, why)