-
Notifications
You must be signed in to change notification settings - Fork 3
Policy Endpoints #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
woutslabbinck
merged 66 commits into
SolidLabResearch:feat/policy-endpoint
from
lennertdr:main
Aug 4, 2025
Merged
Policy Endpoints #57
Changes from 16 commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
ecd6839
Basic POST /policies created
lennertdr 846fcac
Practical addRule implementation to test the POST endpoint
lennertdr 1c377a7
added Get One Policy endpoint, need a way to fix the ID (encoding?)
lennertdr e60eb75
getOnePolicy works if a good encoding of ID's is implemented
lennertdr 6f0916f
follow implementation from Main
lennertdr a183107
test content type
lennertdr 89eb900
feat: Allow APIs with raw input
joachimvh f2de8ad
Format checks removed, they are already in N3 Parser
lennertdr 56727e8
Merge remote-tracking branch 'upstream/main' into policyEndpoints
lennertdr f6dc977
fix: Correctly handle multiple routing classes
joachimvh 8295dbf
Change to Memory structure for better testing on this branch
lennertdr 3d110ce
Merge remote-tracking branch 'upstream/main' into policyEndpoints
lennertdr 3ee80a6
POST with proper content types
lennertdr 90ff950
Memory based tests
lennertdr 64ae909
Merge remote-tracking branch 'origin/policyEndpoints'
lennertdr b5dab70
import fix
lennertdr 2dad0f7
GET /uma/policies/<id> first finished implementation
lennertdr 2f43a30
Add extra checks to POST
lennertdr 73d32d8
More generic url handling and POST with sanitize function (to be comp…
lennertdr 9e1102b
excessive documentation
lennertdr e11cc43
test doc and very primitive way to detect fails
lennertdr 9f78328
DELETE endpoint implemented, still needs tests
lennertdr 944b52e
fix: Export OperationLogger
joachimvh 4c05231
fix: Prevent contract creation errors from stopping the request
joachimvh 1b08acb
fix: Request subject resource permissions for auxiliaries
joachimvh 0f0e025
feat: Allow relative URIs when using DirectoryUCRulesStorage
joachimvh 0d91822
refactor: Remove unused seeding fields
joachimvh 1e3c9e1
feat: Make containerURL of ContainerUCRulesStorage configurable
joachimvh 3e7d7b6
feat: Make App the root configured component
joachimvh b7588c7
chore: Remove unused dependencies
joachimvh a746efe
chore: Replace ts-node completely with tsx
joachimvh 3f8c388
test: Add integration tests with vitest
joachimvh 4cde160
test: Add testing to CI
joachimvh de2fab0
chore: Build startup scripts instead of using tsx
joachimvh 3be468a
Tests for DELETE endpoint
lennertdr de05066
edit policy setup
lennertdr 778ca15
Basic edit implementation
lennertdr f06de50
added simple tests for PATCH
lennertdr aecd278
patch + tests
lennertdr f0ea4c7
extra check for PATCH
lennertdr c807bb7
remove console.logs
lennertdr 308e6c1
Seperate rule definitions for a policy based on the client
lennertdr f98fbc9
PATCH safety fix, GET duplicate fix
lennertdr 15d4619
cleanup, fix PUT, less redundant GET
lennertdr d16071b
extra PUT checks, extra documentation
lennertdr a67b3d4
doc layout fix
lennertdr 615a9a9
detailed documentation
lennertdr d66d1f4
Stronger POST checks
lennertdr bb08a83
DELETE idea, need to adjust tests
lennertdr 29b8eaa
fixed small bug
lennertdr 4c1cc6f
Merge remote-tracking branch 'upstream/main', kept memory storage in …
lennertdr 9c189ec
doc update
lennertdr 7cbbedc
doc update
lennertdr 0ba8846
typos
lennertdr 36934e8
temporary header against CORS, not the right solution
lennertdr ed76ee6
script to seed for specific id
lennertdr 155169e
options for other requests
lennertdr 6eaf6f2
some requested changes
lennertdr b8de385
undo wrong import
lennertdr 10c7247
quick workaround
lennertdr dc950da
demo script
lennertdr 80bf03b
script shortcut
lennertdr e6044f7
added test again
lennertdr eb605dc
Removed logs and finetuned docs
lennertdr 46c177f
docfix
lennertdr 9a5f4e8
TODO's
lennertdr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <http://example.org/usagePolicy4> a <http://www.w3.org/ns/odrl/2/Agreement>; | ||
| <http://www.w3.org/ns/odrl/2/permission> <http://example.org/permission4>. | ||
| <http://example.org/permission4> a <http://www.w3.org/ns/odrl/2/Permission>; | ||
| <http://www.w3.org/ns/odrl/2/action> <http://www.w3.org/ns/odrl/2/read>; | ||
| <http://www.w3.org/ns/odrl/2/target> <http://localhost:3000/alice/other/resource.txt>; | ||
| <http://www.w3.org/ns/odrl/2/assignee> <https://woslabbi.pod.knows.idlab.ugent.be/profile/card#me>; | ||
| <http://www.w3.org/ns/odrl/2/assigner> <https://pod.example.com/profile/card#me>. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 63 additions & 1 deletion
64
packages/uma/src/util/routeSpecific/policies/CreatePolicies.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,63 @@ | ||
| //TODO | ||
| import { Store } from "n3"; | ||
| import { HttpHandlerRequest, HttpHandlerResponse } from "../../http/models/HttpHandler"; | ||
| import { namedNode, odrlAssigner } from "./PolicyUtil"; | ||
| import { BadRequestHttpError, InternalServerError } from "@solid/community-server"; | ||
| import { parseStringAsN3Store } from "koreografeye"; | ||
| import { UCRulesStorage } from "@solidlab/ucp"; | ||
|
|
||
| export async function addPolicies(request: HttpHandlerRequest, store: Store, storage: UCRulesStorage, clientId: string): Promise<HttpHandlerResponse<any>> { | ||
|
|
||
| // 1. Parse the requested policy | ||
|
|
||
| const contentType = request.headers['content-type'] ?? 'turtle'; | ||
| // Regex check for content type (awaiting server implementation) | ||
| if (!/(?:n3|trig|turtle|nquads?|ntriples?)$/i.test(contentType)) { | ||
| throw new BadRequestHttpError(`Content-Type ${contentType} is not supported.`); | ||
| } | ||
|
|
||
| console.log("Requested Policy:", request.body) | ||
| let requestedPolicy; | ||
| if (Buffer.isBuffer(request.body)) { | ||
| requestedPolicy = request.body.toString('utf-8'); | ||
| console.log('RDF body:', requestedPolicy); | ||
| } else { | ||
| throw new Error("Expected Buffer body"); | ||
| } | ||
| let parsedPolicy: Store; | ||
| try { | ||
| parsedPolicy = await parseStringAsN3Store(requestedPolicy, { format: contentType }); | ||
| } catch (error) { | ||
| throw new BadRequestHttpError(`Policy string can not be parsed: ${error}`) | ||
| } | ||
|
|
||
| // 2. Check if assigner is client | ||
| const matchingClient = parsedPolicy.getQuads(null, odrlAssigner, namedNode(clientId), null); | ||
| if (matchingClient.length === 0) { | ||
| throw new BadRequestHttpError(`Policy is not authorized correctly`); | ||
| } | ||
|
|
||
| // Making sure there are no rules added with other assigners then yourself | ||
| const allAssigners = parsedPolicy.getQuads(null, odrlAssigner, null, null); | ||
| if (allAssigners.length !== matchingClient.length) { | ||
| throw new BadRequestHttpError(`Policy is incorrectly built`); | ||
| } | ||
lennertdr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // TODO: 3. Perform other validity checks | ||
|
|
||
| // Check if assigner of the policy has access to the target | ||
| // Check if there is at least one permission/prohibition/duty | ||
| // Check if every rule has a target | ||
lennertdr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // ... | ||
|
|
||
| // 4. Add the policy to the rule storage | ||
| try { | ||
| await storage.addRule(parsedPolicy); | ||
| } catch (error) { | ||
| throw new InternalServerError("Failed to add policy"); | ||
| } | ||
|
|
||
|
|
||
| return { | ||
| status: 201 | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this an artefact of using the earliest POST method in combination with the FileStorage solution?
If so, I think this can be removed