mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: add simple permissions related handlers
This commit is contained in:
16
src/authentication/SimpleCredentialsExtractor.ts
Normal file
16
src/authentication/SimpleCredentialsExtractor.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
14
src/authorization/SimpleAuthorizer.ts
Normal file
14
src/authorization/SimpleAuthorizer.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
18
src/ldp/permissions/SimplePermissionsExtractor.ts
Normal file
18
src/ldp/permissions/SimplePermissionsExtractor.ts
Normal 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',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user