Skip to content

CLARIN-DSpace v9/Deny reads of ownerless CLARIN user records and anonymous CLARIN searches - #1495

Open
milanmajchrak wants to merge 2 commits into
dtq-dev-93from
fix/clarin-user-data-ownerless-records-9
Open

milanmajchrak wants to merge 2 commits into
dtq-dev-93from
fix/clarin-user-data-ownerless-records-9

Conversation

@milanmajchrak

@milanmajchrak milanmajchrak commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

References

Ports this dtq-dev PR:

DSpace PR 1588 ports the same dtq-dev PR. Only one of the two should be merged.

Description

A CLARIN allowance or user-metadata record without a user registration is now readable only by an admin. The CLARIN searches byEPerson, byUserRegistrationAndBitstream and byBitstreamAndUser need a signed-in user, so an anonymous call gets 401 instead of 500.

Instructions for Reviewers

List of changes in this PR:

  • authorize…Action helpers in ClarinLicenseResourceUserAllowanceServiceImpl, ClarinUserMetadataServiceImpl and ClarinUserRegistrationServiceImpl: only the owner or an admin passes. A record without a user registration (from an anonymous download) passes only for an admin. An anonymous caller is denied instead of hitting a NullPointerException.
  • The three search methods get @PreAuthorize("hasAuthority('AUTHENTICATED')"), and AuthorizeException becomes RESTAuthorizationException. Anonymous gets 401, another user 403.
  • The link repositories already map the exception on this branch, so they are untouched.
  • Tests: new ClarinLicenseResourceUserAllowanceRestRepositoryIT, plus findOneWithoutUserRegistrationTest, findByUserRegistrationAndBitstreamTest, findByEPersonTest and linksTest in the existing ITs. Each search test also sends an anonymous search that matches nothing and expects 401.

How to test:

  1. Run the ITs (12 tests pass):
    mvn verify -pl dspace-server-webapp,dspace -am -DskipUnitTests=true -DskipIntegrationTests=false -Dit.test=ClarinLicenseResourceUserAllowanceRestRepositoryIT,ClarinUserMetadataRestRepositoryIT,ClarinUserRegistrationRestRepositoryIT -Dfailsafe.failIfNoSpecifiedTests=false
    
  2. Download a file with a licence as an anonymous user. GET /api/core/clarinlruallowances/{id} of that record answers 403 for a normal user and 200 for an admin.
  3. GET /api/core/clarinuserregistrations/search/byEPerson?userUUID={uuid} without a token answers 401.
  4. The licence agreement page and the download still work, anonymously and signed in. The page already ignores the error from byEPerson for anonymous users.

Codex review (gpt-6.2-sol, high), 2 rounds: 1 finding fixed (the search tests did not cover an anonymous search without a match), the last round found nothing.

Checklist

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & integration tests). Exceptions may be made if previously agreed upon.
  • My PR passes Checkstyle validation based on the Code Style Guide.
  • My PR includes Javadoc for all new (or modified) public methods and classes. It also includes Javadoc for large or complex private methods.
  • My PR passes all tests and includes new/updated Unit or Integration Tests based on the Code Testing Guide.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in any pom.xml), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR modifies REST API endpoints, I've opened a separate REST Contract PR related to this change.
  • If my PR includes new configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

🤖 Generated with Claude Code

…ymous CLARIN searches

Allowance and user-metadata records created by an anonymous download have
no user registration. The authorize helpers let any signed-in user read
them by ID, including the form data, IP address and download token.
Now only an admin may read them.

The CLARIN search methods (byEPerson, byBitstreamAndUser and, where it
exists, byUserRegistrationAndBitstream) had no PreAuthorize, so an
anonymous request ended with a NullPointerException and a 500. They now
require an authenticated user and map AuthorizeException to 401 or 403.
The link repositories map it the same way instead of returning a 500.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@milanmajchrak
milanmajchrak changed the base branch from dtq-dev-9-base to dtq-dev-93 November 17, 2026 15:57
Without a matching record the services check nothing, so only the endpoint authorization can refuse these searches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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.

1 participant