To support exact specification of user-IDs, `AuthenticationInfo` now contains a `source_identifier`. This will identify the authentication source that was used. All `AuthenticationSource`s are instantiated with a `source_identifier`, chosen by the caller. Add user-id -> policy mapping to collection configuration Adapt code to extended user ID information, i.e. to (authentication_instance_id, user_id), feat: add policy handling to SQLite backend This commit implements policy handling in the SQLite backend. That means, result records are filtered by an optional default policy, a set of active policies, and the policies that are set in the annotations of a record.
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""Use configuration information to fetch token permissions, ids, and incoming_label"""
|
|
|
|
from dump_things_service.abstract_config import (
|
|
Configuration,
|
|
get_token_config_for_representation_and_collection,
|
|
get_token_permissions,
|
|
)
|
|
from dump_things_service.auth import (
|
|
AuthenticationInfo,
|
|
AuthenticationSource,
|
|
InvalidTokenError,
|
|
)
|
|
|
|
|
|
class ConfigAuthenticationSource(AuthenticationSource):
|
|
def __init__(
|
|
self,
|
|
abstract_configuration: Configuration,
|
|
collection_name: str,
|
|
):
|
|
super().__init__('config')
|
|
self.abstract_configuration = abstract_configuration
|
|
self.collection_name = collection_name
|
|
|
|
def authenticate(
|
|
self,
|
|
token_representation: str,
|
|
) -> AuthenticationInfo:
|
|
result = get_token_config_for_representation_and_collection(
|
|
self.abstract_configuration,
|
|
self.collection_name,
|
|
token_representation,
|
|
)
|
|
|
|
if not result:
|
|
msg = f'Token not valid for collection `{self.collection_name}`'
|
|
raise InvalidTokenError(msg)
|
|
|
|
_, token_config, token_collection_config = result
|
|
return AuthenticationInfo(
|
|
source_identifier=self.source_identifier,
|
|
token_permission=get_token_permissions(token_collection_config.mode),
|
|
user_id=token_config.user_id,
|
|
incoming_label=token_collection_config.incoming_label,
|
|
)
|