Skip to content

[DT-3788] Migrate eligible AuthUser resource endpoints to DuosUser#2979

Open
rushtong wants to merge 8 commits into
developfrom
gr-DT-3788-auth-to-duos-user
Open

[DT-3788] Migrate eligible AuthUser resource endpoints to DuosUser#2979
rushtong wants to merge 8 commits into
developfrom
gr-DT-3788-auth-to-duos-user

Conversation

@rushtong

@rushtong rushtong commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Addresses

https://broadworkbench.atlassian.net/browse/DT-3788

Summary

Migrates 51 of the 52 @Auth AuthUser resource endpoints to @Auth DuosUser across 12 resource
classes (EmailNotifierResource, DatasetResource, DacResource, MatchResource,
StudyResource, DraftResource, MailResource, UserResource, VoteResource,
FeatureFlagResource, DataAccessRequestResource, DACAutomationRuleResource), removing the
redundant UserService.findUserByEmail(authUser.getEmail()) lookup from each migrated method in
favor of duosUser.getUser() / duosUser.getUserId().

UserResource.createResearcher is the one endpoint left on AuthUser — it's the registration
flow and explicitly depends on the caller not having a Consent user yet, which DuosUser
doesn't allow.

No business logic moved into the resource layer as part of this cleanup; only the principal type
and the now-redundant lookup changed. Response bodies and success status codes are unchanged.

Behavior change (documented, not a bug): for role-restricted endpoints, an authenticated
caller who has no Consent user row now gets 401 from DuosUserAuthenticator at the
authentication layer, instead of whatever status the resource/authorizer produced before (usually
403, from AuthorizationHelper.authorize() silently swallowing the lookup failure). Role
authorization already performed its own independent findUserByEmail lookup regardless of the
resource's principal type, so this migration doesn't introduce new lookup risk — it only shifts
when the "no Consent user" case is caught. src/main/resources/assets/paths/*.yaml (and the
inline paths in api-docs.yaml) have been updated to document 401 on the ~24 affected operations
that didn't already list it.

Tests: updated ~15 resource test files to use DuosUser fixtures in place of AuthUser,
dropping now-dead findUserByEmail stubs (would otherwise trip Mockito's
UnnecessaryStubbingException) and the handful of tests that specifically exercised the
resource-level NotFoundException catch — that scenario is now handled upstream by the
authenticator and is already covered generically in AuthorizationHelperTest. Added a
filterUsers test to DacResourceTest (previously untested). Full suite: 3379 tests, 0
failures/errors.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request migrates eligible authenticated resource endpoints from @Auth AuthUser to @Auth DuosUser, removing redundant UserService.findUserByEmail(...) lookups in resources and documenting the resulting 401 Unauthorized behavior when a caller has no Consent User row.

Changes:

  • Updated resource method signatures/constructors to accept DuosUser and use duosUser.getUser() / getUserId() instead of re-looking up by email.
  • Updated resource tests to pass DuosUser principals and removed now-dead findUserByEmail stubbing paths.
  • Updated OpenAPI path docs (and inline api-docs.yaml) to include 401 Unauthorized on affected operations.

Reviewed changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/test/java/org/broadinstitute/consent/http/resources/VoteResourceTest.java Switches tests to DuosUser and removes UserService stubbing.
src/test/java/org/broadinstitute/consent/http/resources/UserResourceTest.java Updates user-resource tests to pass DuosUser and removes user-not-found cases now handled at auth.
src/test/java/org/broadinstitute/consent/http/resources/StudyResourceTest.java Updates study-resource tests to pass DuosUser and removes UserService dependency.
src/test/java/org/broadinstitute/consent/http/resources/MatchResourceTest.java Uses DuosUser for the admin reprocess endpoint test.
src/test/java/org/broadinstitute/consent/http/resources/MailResourceTest.java Updates mail-resource tests to call endpoints with DuosUser.
src/test/java/org/broadinstitute/consent/http/resources/FeatureFlagResourceTest.java Updates feature-flag tests to use DuosUser and removes UserService dependency.
src/test/java/org/broadinstitute/consent/http/resources/EmailNotifierResourceTest.java Updates email-notifier tests to pass DuosUser.
src/test/java/org/broadinstitute/consent/http/resources/DraftResourceTest.java Updates draft-resource tests to pass DuosUser and removes UserService dependency.
src/test/java/org/broadinstitute/consent/http/resources/DatasetResourceTest.java Updates dataset-resource tests to pass DuosUser (including data use and indexing endpoints).
src/test/java/org/broadinstitute/consent/http/resources/DataAccessRequestResourceTest.java Updates DAR v2 tests to pass DuosUser (including “user-with-cards” fixtures).
src/test/java/org/broadinstitute/consent/http/resources/DacResourceTest.java Updates DAC tests to pass DuosUser and adds filterUsers coverage.
src/test/java/org/broadinstitute/consent/http/resources/DACAutomationRuleResourceTest.java Updates automation-rule tests to pass DuosUser and removes UserService dependency.
src/main/resources/assets/paths/votesRationale.yaml Documents 401 Unauthorized for vote rationale updates.
src/main/resources/assets/paths/votes.yaml Documents 401 Unauthorized for vote updates.
src/main/resources/assets/paths/userInstitutionSigningOfficials.yaml Documents 401 Unauthorized for signing officials lookup.
src/main/resources/assets/paths/userInstitutionByInstitutionId.yaml Documents 401 Unauthorized for users-by-institution endpoint.
src/main/resources/assets/paths/studyByIdCustodians.yaml Documents 401 Unauthorized for updating custodians.
src/main/resources/assets/paths/studyById.yaml Documents 401 Unauthorized for update/delete study operations.
src/main/resources/assets/paths/progressReport.yaml Documents 401 Unauthorized for progress report creation.
src/main/resources/assets/paths/getDatasetsFromUserDacsV2.yaml Documents 401 Unauthorized for DAC dataset listing v2.
src/main/resources/assets/paths/getDatasetsFromUserDacs.yaml Documents 401 Unauthorized for DAC dataset listing v1.
src/main/resources/assets/paths/datasetV3.yaml Documents 401 Unauthorized for dataset registration.
src/main/resources/assets/paths/datasetIndexById.yaml Documents 401 Unauthorized for per-dataset indexing operations.
src/main/resources/assets/paths/datasetIndex.yaml Documents 401 Unauthorized for bulk dataset indexing.
src/main/resources/assets/paths/datasetByIdDataUse.yaml Documents 401 Unauthorized for updating dataset data use.
src/main/resources/assets/paths/darV2ByReferenceId.yaml Documents 401 Unauthorized for DAR update-by-reference-id.
src/main/resources/assets/paths/darV2.yaml Documents 401 Unauthorized for DAR v2 create/list operations.
src/main/resources/assets/paths/dacById.yaml Documents 401 Unauthorized for DAC-by-id.
src/main/resources/assets/paths/dac.yaml Documents 401 Unauthorized for DAC list.
src/main/resources/assets/paths/adminFeatureById.yaml Documents 401 Unauthorized for feature flag create/delete.
src/main/resources/assets/api-docs.yaml Adds inline 401 Unauthorized docs for affected operations.
src/main/java/org/broadinstitute/consent/http/resources/VoteResource.java Switches vote endpoints to DuosUser and removes UserService lookup/dependency.
src/main/java/org/broadinstitute/consent/http/resources/UserResource.java Switches selected user endpoints to DuosUser and removes redundant lookups.
src/main/java/org/broadinstitute/consent/http/resources/StudyResource.java Switches custodians/update/delete study endpoints to DuosUser and removes UserService dependency.
src/main/java/org/broadinstitute/consent/http/resources/MatchResource.java Switches admin reprocess endpoint to DuosUser.
src/main/java/org/broadinstitute/consent/http/resources/MailResource.java Switches admin mail endpoints to DuosUser.
src/main/java/org/broadinstitute/consent/http/resources/FeatureFlagResource.java Switches feature flag endpoints to DuosUser and removes UserService dependency.
src/main/java/org/broadinstitute/consent/http/resources/EmailNotifierResource.java Switches notifier endpoints to DuosUser.
src/main/java/org/broadinstitute/consent/http/resources/DraftResource.java Switches draft endpoints to DuosUser and removes UserService dependency.
src/main/java/org/broadinstitute/consent/http/resources/DatasetResource.java Switches dataset registration/index/datause endpoints to DuosUser and uses duosUser.getUser().
src/main/java/org/broadinstitute/consent/http/resources/DataAccessRequestResource.java Switches DAR v2 endpoints to DuosUser and removes internal email lookup helper.
src/main/java/org/broadinstitute/consent/http/resources/DacResource.java Switches DAC list/get/filterUsers endpoints to DuosUser.
src/main/java/org/broadinstitute/consent/http/resources/DACAutomationRuleResource.java Switches DAC automation-rule endpoints to DuosUser and removes UserService dependency.

rushtong and others added 4 commits July 17, 2026 13:33
Addresses Copilot review feedback on PR #2979: tests were passing a
mocked DuosUser without stubbing getUser(), defaulting to null and
making the tests less representative of production callers.

DraftResource always dereferences duosUser.getUser() as the first
statement in every method, so the default is added once in
initResource() and used by every test. StudyResource's
patchStudyById/getStudyById short-circuit before touching the user on
some not-found paths, so a blanket default there would trip Mockito's
strict-stubbing check; only the three updateCustodians tests (which
unconditionally consume the user) got an explicit stub.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
# Conflicts:
#	src/main/java/org/broadinstitute/consent/http/resources/DatasetResource.java
#	src/main/java/org/broadinstitute/consent/http/resources/StudyResource.java
#	src/test/java/org/broadinstitute/consent/http/resources/StudyResourceTest.java
… change

The develop merge (DT-3595/3596/3597) switched updateStudyByRegistration
to fetch the existing study via datasetService.getStudyWithDatasetsById
instead of datasetRegistrationService.findStudyById. Three tests were
still stubbing the old lookup method, and one was missing the
duosUser.getUser() stub entirely, causing Mockito strict-stubbing
argument-mismatch exceptions (surfaced as unexpected 500s).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@rushtong
rushtong marked this pull request as ready for review July 17, 2026 18:26
@rushtong
rushtong requested a review from a team as a code owner July 17, 2026 18:26
@rushtong
rushtong requested review from fboulnois, kevinmarete and otchet-broad and removed request for a team July 17, 2026 18:26

@kevinmarete kevinmarete left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean, handle the nit sonar warnings and all good!

@sonarqubecloud

Copy link
Copy Markdown

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.

3 participants