def protect(func):
    """
    This is a decorator which checks permission before calling the method.
    To get permission, the caller must pass the correct `auth_key`.
    """
    def wrapper(self, *args, **kargs):
        key = kargs.pop('auth_key', None)
        if not self.authorize(key):
            raise IOError('Permission denied.')
        return func(self, *args, **kargs)
    return wrapper