feat: add simple permissions related handlers

This commit is contained in:
Joachim Van Herwegen
2020-06-23 10:13:23 +02:00
parent e0343fca54
commit d983fca8f5
7 changed files with 133 additions and 1 deletions

View File

@@ -0,0 +1,16 @@
import { Credentials } from './Credentials';
import { CredentialsExtractor } from './CredentialsExtractor';
import { HttpRequest } from '../server/HttpRequest';
export class SimpleCredentialsExtractor extends CredentialsExtractor {
public async canHandle(): Promise<void> {
return undefined;
}
public async handle(input: HttpRequest): Promise<Credentials> {
if (input.headers.authorization) {
return { webID: input.headers.authorization };
}
return undefined;
}
}

View File

@@ -0,0 +1,14 @@
import { UnsupportedHttpError } from '../util/errors/UnsupportedHttpError';
import { Authorizer, AuthorizerArgs } from './Authorizer';
export class SimpleAuthorizer extends Authorizer {
public async canHandle(input: AuthorizerArgs): Promise<void> {
if (!input.identifier || !input.permissions) {
throw new UnsupportedHttpError('Authorizer requires an identifier and permissions.');
}
}
public async handle(): Promise<void> {
return undefined;
}
}

View File

@@ -0,0 +1,18 @@
import { Operation } from '../operations/Operation';
import { PermissionSet } from './PermissionSet';
import { PermissionsExtractor } from './PermissionsExtractor';
export class SimplePermissionsExtractor extends PermissionsExtractor {
public async canHandle(): Promise<void> {
return undefined;
}
public async handle(input: Operation): Promise<PermissionSet> {
return {
read: input.method === 'GET',
append: false,
write: input.method === 'POST' || input.method === 'PUT',
delete: input.method === 'DELETE',
};
}
}