Skip to content
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

feat: add example application #33

Closed
wants to merge 3 commits into from
Closed

feat: add example application #33

wants to merge 3 commits into from

Conversation

jimmyjames
Copy link
Collaborator

@jimmyjames jimmyjames commented Apr 8, 2024

Description

Adds a simple example application that uses the FGA Spring Boot Starter. Features:

  • Uses an in-memory database and loads two document objects on application startup (document:1 and document:2).
  • Creates a new store and simple authorization model on application startup, along with a single tuple granting user:anne the viewer relation to document:1.
  • Exposes an endpoint (/documents/{id}) which uses the fga bean in a @PreAuthorize expression to ensure that the user (hard-coded to anne in this example) has the can_read relation to the requested document. If the FGA check returns true, the document is returned to the caller. If the FGA check fails, it will result in a 403.
  • Also exposes an endpoint to create a document, which will write an authorization tuple to FGA defining user:anne as having the owner relation to the document.

This change does not add any tests; https://github.com/jimmyjames/fga-spring-examples has some great examples of writing tests and using the FGA test container; we'll create another issue to do something similar here (may be a good opportunity for a community contribution 😄).

Closes #5

References

#5

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@jimmyjames
Copy link
Collaborator Author

Fossa checks failing, likely false warnings re. licenses, will need to review them.

@jimmyjames jimmyjames marked this pull request as ready for review April 8, 2024 23:30
@jimmyjames jimmyjames requested a review from a team as a code owner April 8, 2024 23:30
@jimmyjames
Copy link
Collaborator Author

Due to some fossa license issues with hibernate (uses LPGL), using spring-data-jpa and its h2 is likely going to be problematic (until/if hibernate switches to apache 2.0 as discussed). Closing this PR to rework to remove those dependencies, and also because this PR uses the multi-module structure which we removed due to nexus plugin issues.

@jimmyjames jimmyjames closed this Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Servlet example
1 participant