Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@
"devDependencies": {
"@commitlint/cli": "^16.1.0",
"@commitlint/config-conventional": "^16.0.0",
"@comunica/bus-rdf-parse-html": "^4.4.0",
"@types/node": "^20.19.1",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"@vitest/coverage-v8": "^3.2.4",
"chalk": "^5.4.1",
"componentsjs-generator": "^3.1.2",
"componentsjs-generator": "^4.3.0",
"eslint": "^8.10.0",
"jest-rdf": "^1.8.1",
"rdf-parse": "^4.0.0",
"shx": "^0.3.4",
"syncpack": "^13.0.2",
"tsx": "^4.19.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/css/config/default.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
],
"import": [
Expand Down
2 changes: 1 addition & 1 deletion packages/css/config/demo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
],
"import": [
Expand Down
5 changes: 3 additions & 2 deletions packages/css/config/ldp/authorization/readers/uma.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/asynchronous-handlers/^1.0.0/components/context.jsonld"
],
"@graph": [
{
Expand Down
9 changes: 6 additions & 3 deletions packages/css/config/ldp/authorization/uma.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/asynchronous-handlers/^1.0.0/components/context.jsonld"
],
"import": [
"uma-css:config/ldp/authorization/readers/uma.json"
Expand All @@ -10,7 +11,9 @@
{
"comment": "There are no auth-specific resources, but this ID still has to exist.",
"@id": "urn:solid-server:default:AuthResourceHttpHandler",
"@type": "UnsupportedAsyncHandler"
"@type": "StaticThrowHandler",
"onlyHandle": false,
"factory": { "@id": "urn:solid-server:default:UnsupportedErrorFactory" }
}
]
}
5 changes: 3 additions & 2 deletions packages/css/config/uma/demo.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/asynchronous-handlers/^1.0.0/components/context.jsonld"
],
"@graph": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
],
"@graph": [
Expand Down
7 changes: 2 additions & 5 deletions packages/css/config/uma/overrides/authorizer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
],
"@graph": [
Expand All @@ -13,10 +13,7 @@
"overrideParameters": {
"@type": "UmaAuthorizer",
"authorizer": {
"@type": "PermissionBasedAuthorizer",
"resourceSet": {
"@id": "urn:solid-server:default:CachedResourceSet"
}
"@type": "PermissionBasedAuthorizer"
},
"umaClient": {
"@id": "urn:solid-server:default:UmaClient"
Expand Down
4 changes: 2 additions & 2 deletions packages/css/config/uma/overrides/jwks.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
],
"@graph": [
Expand All @@ -11,7 +11,7 @@
"overrideInstance": { "@id": "urn:solid-server:default:BaseHttpHandler" },
"overrideSteps": [{
"@type": "OverrideListInsertAt",
"overrideParameter": { "@id": "WaterfallHandler:_handlers" },
"overrideParameter": { "@id": "StatusWaterfallHandler:_handlers" },
"overrideTarget": 0,
"overrideValue": {
"@id": "urn:solid-server:default:JwksRouterHandler",
Expand Down
5 changes: 3 additions & 2 deletions packages/css/config/uma/overrides/modes.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/asynchronous-handlers/^1.0.0/components/context.jsonld"
],
"@graph": [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/css/config/uma/parts/cli.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
],
"@graph": [
Expand Down
2 changes: 1 addition & 1 deletion packages/css/config/uma/parts/client.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
],
"@graph": [
Expand Down
2 changes: 1 addition & 1 deletion packages/css/config/uma/parts/owner-util.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
],
"@graph": [
Expand Down
5 changes: 3 additions & 2 deletions packages/css/config/uma/parts/resource-registrar.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/asynchronous-handlers/^1.0.0/components/context.jsonld"
],
"@graph": [
{
Expand Down
5 changes: 3 additions & 2 deletions packages/css/config/uma/parts/server-configurator.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld"
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma-css/^0.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/asynchronous-handlers/^1.0.0/components/context.jsonld"
],
"@graph": [
{
Expand Down
7 changes: 5 additions & 2 deletions packages/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@
"demo:start": "yarn run community-solid-server -m . -c ./config/demo.json -f ./tmp -a http://localhost:4000/"
},
"dependencies": {
"@solid/community-server": "^7.1.7",
"@solid/community-server": "^8.0.0-alpha.1",
"@solidlab/policy-engine": "^0.0.2",
"@solidlab/uma": "workspace:^",
"@types/n3": "^1.16.4",
"componentsjs": "^5.5.1",
"asynchronous-handlers": "^1.0.2",
"componentsjs": "^6.3.0",
"fetch-retry": "^6.0.0",
"global-logger-factory": "^1.0.0",
"http-message-signatures": "^1.0.4",
"jose": "^5.2.2",
"n3": "^1.17.2"
Expand Down
10 changes: 8 additions & 2 deletions packages/css/src/authentication/UmaTokenExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import {
CredentialsExtractor, getLoggerFor, HttpRequest,
NotImplementedHttpError, BadRequestHttpError, Credentials, TargetExtractor, createErrorMessage
BadRequestHttpError,
createErrorMessage,
Credentials,
CredentialsExtractor,
HttpRequest,
NotImplementedHttpError,
TargetExtractor,
} from '@solid/community-server';
import { getLoggerFor } from 'global-logger-factory';
import { UmaClaims, UmaClient } from '../uma/UmaClient';
import { OwnerUtil } from '../util/OwnerUtil';

Expand Down
8 changes: 4 additions & 4 deletions packages/css/src/authorization/ParentCreateExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
AccessMap,
AccessMode,
IdentifierSetMultiMap,
IdentifierStrategy,
InternalServerError,
Expand All @@ -9,6 +8,7 @@ import {
ResourceIdentifier,
ResourceSet
} from '@solid/community-server';
import { PERMISSIONS } from '@solidlab/policy-engine';

/**
* Transforms the result of the wrapped {@link ModesExtractor} to only return modes for existing resources.
Expand Down Expand Up @@ -37,11 +37,11 @@ export class ParentCreateExtractor extends ModesExtractor {

public async handle(input: Operation): Promise<AccessMap> {
const result = await this.source.handle(input);
const updatedResult = new IdentifierSetMultiMap<AccessMode>();
const updatedResult: AccessMap = new IdentifierSetMultiMap();
for (const [ id, modes ] of result.entrySets()) {
if (modes.has(AccessMode.create)) {
if (modes.has(PERMISSIONS.Create)) {
const parent = await this.findFirstExistingParent(id);
updatedResult.add(parent, AccessMode.create);
updatedResult.add(parent, PERMISSIONS.Create);
} else {
updatedResult.add(id, modes);
}
Expand Down
15 changes: 10 additions & 5 deletions packages/css/src/authorization/UmaAuthorizer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import type { AccessMap, AuthorizerInput } from '@solid/community-server';
import {
Authorizer, createErrorMessage, ForbiddenHttpError, getLoggerFor, InternalServerError, UnauthorizedHttpError
Authorizer,
createErrorMessage,
ForbiddenHttpError,
InternalServerError,
UnauthorizedHttpError
} from '@solid/community-server';
import type { AccessMap, AuthorizerInput } from '@solid/community-server';
import { OwnerUtil } from '../util/OwnerUtil';
import { UmaClient } from '../uma/UmaClient';
import { getLoggerFor } from 'global-logger-factory';
import { DataFactory } from 'n3';
import { UmaClient } from '../uma/UmaClient';
import { OwnerUtil } from '../util/OwnerUtil';

const { blankNode, namedNode, literal } = DataFactory;
const { namedNode, literal } = DataFactory;

export const WWW_AUTH = namedNode('urn:css:http:headers:www-authenticate');

Expand Down
25 changes: 19 additions & 6 deletions packages/css/src/authorization/UmaPermissionReader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { getLoggerFor, PermissionReader, PermissionReaderInput,
PermissionMap, PermissionSet, IdentifierMap } from '@solid/community-server';
import { IdentifierMap, MultiPermissionMap, PermissionReader, PermissionReaderInput } from '@solid/community-server';
import { PermissionMap } from '@solidlab/policy-engine';
import { getLoggerFor } from 'global-logger-factory';
import { VocabularyValue } from 'rdf-vocabulary';
import { toCssMode } from '../uma/ScopeUtil';
import { UmaClaims } from '../uma/UmaClient';
import { MODES } from '../util/Vocabularies';

/**
* PermissionReader using input from UMA Token to authorize the request.
Expand All @@ -13,9 +17,12 @@ export class UmaPermissionReader extends PermissionReader {
* @param {PermissionReaderInput} input
* @return {Promise<PermissionMap>}
*/
public async handle(input: PermissionReaderInput): Promise<PermissionMap> {
public async handle(input: PermissionReaderInput): Promise<MultiPermissionMap> {
const now = Date.now() / 1000;
const result = new IdentifierMap<PermissionSet>();
const result = new IdentifierMap<PermissionMap>();
if (!input.credentials.uma || !(input.credentials.uma as { rpt: UmaClaims }).rpt) {
return result;
}
const { rpt } = input.credentials['uma'] as { rpt: UmaClaims };
const { permissions, iat: t_iat, exp: t_exp, nbf: t_nbf } = rpt;

Expand All @@ -32,15 +39,21 @@ export class UmaPermissionReader extends PermissionReader {

for (const { resource_id, resource_scopes, iat: p_iat, exp: p_exp, nbf: p_nbf } of permissions ?? []) {
const permissionSet = Object.fromEntries(resource_scopes.map(scope => {
if (!scope.startsWith(MODES.namespace)) {
this.logger.error(`Received unknown scope ${scope}`);
return [];
}

try {
if (p_iat && p_iat >= now) throw new Error(`UMA permission seems to be issued in the future at ${p_iat}.`);
if (p_exp && p_exp <= now) throw new Error(`UMA permission is expired since ${p_exp}.`);
if (p_nbf && p_nbf > now) throw new Error(`UMA permission is not valid before ${p_nbf}.`);
} catch (error) {
this.logger.warn(`Invalid UMA permission: ${error instanceof Error ? error.message : ''}`);
return [scope.replace('urn:example:css:modes:', ''), false];

return [toCssMode(scope as VocabularyValue<typeof MODES>), false];
}
return [scope.replace('urn:example:css:modes:', ''), true];
return [toCssMode(scope as VocabularyValue<typeof MODES>), true];
}));

result.set({ path: resource_id }, permissionSet);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
MetadataWriter, getLoggerFor, HttpResponse, RepresentationMetadata, HTTP, addHeader
} from '@solid/community-server';
import { addHeader, HTTP, HttpResponse, MetadataWriter, RepresentationMetadata } from '@solid/community-server';
import { getLoggerFor } from 'global-logger-factory';
import { WWW_AUTH } from '../../../authorization/UmaAuthorizer';

/**
Expand All @@ -18,7 +17,7 @@ export class UmaTicketMetadataWriter extends MetadataWriter {
metadata: RepresentationMetadata;
}): Promise<void> {
const statusCode = input.metadata.get(HTTP.terms.statusCodeNumber)?.value;

if (statusCode === '401' || statusCode === '403') {
const authHeader = input.metadata.get(WWW_AUTH)?.value;
if (authHeader) {
Expand Down
1 change: 1 addition & 0 deletions packages/css/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './init/UmaSeededAccountInitializer';
export * from './server/middleware/JwksHandler';

export * from './uma/ResourceRegistrar';
export * from './uma/ScopeUtil';
export * from './uma/UmaClient';

export * from './util/OwnerUtil';
Expand Down
2 changes: 1 addition & 1 deletion packages/css/src/init/EmptyContainerInitializer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
BasicRepresentation,
ensureTrailingSlash,
getLoggerFor,
Initializer,
joinUrl,
ResourceIdentifier,
ResourceStore
} from '@solid/community-server';
import { getLoggerFor } from 'global-logger-factory';

/**
* Creates an empty container with the given identifier.
Expand Down
2 changes: 1 addition & 1 deletion packages/css/src/init/UmaSeededAccountInitializer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
AccountStore,
createErrorMessage,
getLoggerFor,
Initializer,
PasswordStore,
PodCreator,
URL_SCHEMA
} from '@solid/community-server';
import { readJson } from 'fs-extra';
import { getLoggerFor } from 'global-logger-factory';
import { array, object, string } from 'yup';
import {
ACCOUNT_SETTINGS_AUTHZ_SERVER,
Expand Down
11 changes: 3 additions & 8 deletions packages/css/src/uma/ResourceRegistrar.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import {
ActivityEmitter,
AS,
createErrorMessage,
getLoggerFor,
ResourceIdentifier,
StaticHandler
} from '@solid/community-server';
import { ActivityEmitter, AS, createErrorMessage, ResourceIdentifier } from '@solid/community-server';
import { StaticHandler } from 'asynchronous-handlers';
import { getLoggerFor } from 'global-logger-factory';
import { OwnerUtil } from '../util/OwnerUtil';
import type { UmaClient } from './UmaClient';

Expand Down
Loading