mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Allow custom root ACL.
This commit is contained in:
committed by
Joachim Van Herwegen
parent
87f1450d0d
commit
e544e6dc11
@@ -9,6 +9,7 @@ import { TEXT_TURTLE } from '../util/ContentTypes';
|
||||
import { ensureTrailingSlash, joinFilePath } from '../util/PathUtil';
|
||||
import { Initializer } from './Initializer';
|
||||
|
||||
const DEFAULT_ACL_PATH = joinFilePath(__dirname, '../../templates/root/.acl');
|
||||
/**
|
||||
* Ensures that a root ACL is present.
|
||||
*/
|
||||
@@ -17,16 +18,19 @@ export class AclInitializer extends Initializer {
|
||||
private readonly store: ResourceStore;
|
||||
private readonly aclManager: AclManager;
|
||||
private readonly root: ResourceIdentifier;
|
||||
private readonly aclPath: string;
|
||||
|
||||
public constructor(
|
||||
baseUrl: string,
|
||||
store: ResourceStore,
|
||||
aclManager: AclManager,
|
||||
) {
|
||||
public constructor(settings: {
|
||||
store: ResourceStore;
|
||||
aclManager: AclManager;
|
||||
baseUrl: string;
|
||||
aclPath?: string;
|
||||
}) {
|
||||
super();
|
||||
this.store = store;
|
||||
this.aclManager = aclManager;
|
||||
this.root = { path: ensureTrailingSlash(baseUrl) };
|
||||
this.store = settings.store;
|
||||
this.aclManager = settings.aclManager;
|
||||
this.root = { path: ensureTrailingSlash(settings.baseUrl) };
|
||||
this.aclPath = settings.aclPath ?? DEFAULT_ACL_PATH;
|
||||
}
|
||||
|
||||
public async handle(): Promise<void> {
|
||||
@@ -42,7 +46,7 @@ export class AclInitializer extends Initializer {
|
||||
// The associated ACL document MUST include an authorization policy with acl:Control access privilege."
|
||||
// https://solid.github.io/specification/protocol#storage
|
||||
protected async setRootAclDocument(rootAcl: ResourceIdentifier): Promise<void> {
|
||||
const acl = await fsPromises.readFile(joinFilePath(__dirname, '../../templates/root/.acl'), 'utf8');
|
||||
const acl = await fsPromises.readFile(this.aclPath, 'utf8');
|
||||
this.logger.debug(`Installing root ACL document at ${rootAcl.path}`);
|
||||
await this.store.setRepresentation(rootAcl, new BasicRepresentation(acl, rootAcl, TEXT_TURTLE));
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ import namedNode = DataFactory.namedNode;
|
||||
*/
|
||||
export class RootContainerInitializer extends Initializer {
|
||||
protected readonly logger = getLoggerFor(this);
|
||||
private readonly baseId: ResourceIdentifier;
|
||||
private readonly store: ResourceStore;
|
||||
private readonly baseId: ResourceIdentifier;
|
||||
|
||||
public constructor(baseUrl: string, store: ResourceStore) {
|
||||
public constructor(settings: { store: ResourceStore; baseUrl: string }) {
|
||||
super();
|
||||
this.baseId = { path: ensureTrailingSlash(baseUrl) };
|
||||
this.store = store;
|
||||
this.store = settings.store;
|
||||
this.baseId = { path: ensureTrailingSlash(settings.baseUrl) };
|
||||
}
|
||||
|
||||
public async handle(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user