Skip to content

BI-2255 - Experimental Collaborator Micronaut Changes#388

Merged
davedrp merged 22 commits intodevelopfrom
feature/BI-2255
Aug 20, 2024
Merged

BI-2255 - Experimental Collaborator Micronaut Changes#388
davedrp merged 22 commits intodevelopfrom
feature/BI-2255

Conversation

@davedrp
Copy link
Contributor

@davedrp davedrp commented Aug 13, 2024

Description

BI-2255 - Experimental Collaborator Micronaut Changes

  • Added EXPERIMENTAL_COLLABORATOR to the enum ProgramSecuredRole
  • Changed ProgramSecuredRoleGroup.ALL to ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES.
  • Added ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR to ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES
  • Created the @ExperimentCollaboratorSecured annotation for endpoints with experimentId (or traitId)

Testing

see Acceptance Criteria in BI-2255

Checklist:

  • I have performed a self-review of my own code
  • I have tested my code and ensured it meets the acceptance criteria of the story
  • I have tested that my code works with both the brapi-java-server and BreedBase
  • I have create/modified unit tests to cover this change
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to documentation
  • I have run TAF: <please include a link to TAF run>

@davedrp davedrp requested review from a team, dmeidlin and nickpalladino and removed request for a team August 13, 2024 15:50
@davedrp davedrp marked this pull request as ready for review August 13, 2024 17:30
@mlm483 mlm483 self-requested a review August 13, 2024 18:58
Copy link
Contributor

@mlm483 mlm483 left a comment

Choose a reason for hiding this comment

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

I haven't tested functionality yet, I wanted to get my change requests in ASAP.

See comments for changes, the most important of which is:

  • ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES currently includes ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR and it should not.

Comment on lines +20 to +21
public enum ExperimentCollaboratorSecuredRole {
EXPERIMENTAL_COLLABORATOR("Experimental Collaborator");
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm concerned that defining EXPERIMENTAL_COLLABORATOR here as well as in the ProgramSecuredRole enum could lead to confusion.

Copy link
Contributor

Choose a reason for hiding this comment

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

After seeing how this is used, I recommend deleting this file and using ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR in ExperimentCollaboratorSecuredAnnotationRule::isExperimentCoordinator instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Comment on lines +22 to +23
public enum ProgramSecuredRoleGroup {
ALL_PROGRAM_ROLES(List.of(ProgramSecuredRole.READ_ONLY, ProgramSecuredRole.PROGRAM_ADMIN)),
ALL(ListUtils.union(ALL_PROGRAM_ROLES.getProgramRoles(), List.of(ProgramSecuredRole.SYSTEM_ADMIN)));
PROGRAM_SCOPED_ROLES(List.of(ProgramSecuredRole.SYSTEM_ADMIN, ProgramSecuredRole.READ_ONLY, ProgramSecuredRole.PROGRAM_ADMIN, ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR));
Copy link
Contributor

Choose a reason for hiding this comment

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

Per the Jira story, PROGRAM_SCOPED_ROLES should NOT include ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR, it should look like this:

PROGRAM_SCOPED_ROLES(List.of(ProgramSecuredRole.SYSTEM_ADMIN, ProgramSecuredRole.MEMBER, ProgramSecuredRole.BREEDER));

Technically, ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR is also program scoped... if you think of a better name than PROGRAM_SCOPED_ROLES, I'd take it.

What I was imagining when I wrote the story was that everywhere that previously used the ALL group would use the PROGRAM_SCOPED_ROLES group, and then the handful of endpoints that the Experimental Collaborator needs access to would explicitly list all of the roles. Later on, we could refactor and add back ALL to this enum to simplify those endpoints that explicitly list all of the roles, but I wanted to make sure we get the authorization logic right first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I now understand the new role.
The recommended changes have been made.

Comment on lines 87 to 89
@AddMetadata
@ProgramSecured(roles = {ProgramSecuredRole.PROGRAM_ADMIN, ProgramSecuredRole.SYSTEM_ADMIN})
@ProgramSecured(roles = {ProgramSecuredRole.PROGRAM_ADMIN, ProgramSecuredRole.SYSTEM_ADMIN, ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR})
public HttpResponse<Response<DataResponse<ImportMapping>>> getMappings(@PathVariable UUID programId,
@QueryValue(defaultValue = "false") Boolean draft) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the Experimental Collaborator role need access to this endpoint? I think this change should be reverted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code has been reverted.

Comment on lines 193 to 195
@Secured(SecurityRule.IS_ANONYMOUS)
@ProgramSecured(roles = {ProgramSecuredRole.PROGRAM_ADMIN, ProgramSecuredRole.SYSTEM_ADMIN})
public HttpResponse<Response<DataResponse<ImportMapping>>> getSystemMappings(@Nullable @QueryValue String importName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the addition of @ProgramSecured(...) have any effect here, given the @Secured(SecurityRule.IS_ANONYMOUS) annotation? I think this change should be reverted, or, if this endpoint actually needs to be secured (I don't think it does), the @Secured(SecurityRule.IS_ANONYMOUS) annotation should be removed.

Copy link
Member

@nickpalladino nickpalladino Aug 14, 2024

Choose a reason for hiding this comment

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

It also looks like the ImportControllerIntegrationTest::getSystemMappings test is failing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The @ProgramSecured should not have been added. I have removed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nickpalladino yes it was causing a failure

Comment on lines +124 to +129
private boolean isExperimentCoordinator(ProgramUser programUser){
List<Role> roles = programUser.getRoles();
return (roles.size()==1 &&
ProgramSecuredRole.getEnum(roles.get(0).getDomain())==ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR);

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove if unused. (I think I wrote this method... it doesn't seem to be needed).

Copy link
Member

Choose a reason for hiding this comment

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

Looks like it was probably moved to ExperimentCollaboratorSecuredAnnotationRule and updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment on lines 39 to 52
public class BrAPITrialsController {

private final String referenceSource;
private final SecurityService securityService;
private final BrAPITrialService experimentService;
private final ExperimentQueryMapper experimentQueryMapper;

@Inject
public BrAPITrialsController(BrAPITrialService experimentService, ExperimentQueryMapper experimentQueryMapper, @Property(name = "brapi.server.reference-source") String referenceSource) {
public BrAPITrialsController(SecurityService securityService, BrAPITrialService experimentService, ExperimentQueryMapper experimentQueryMapper, @Property(name = "brapi.server.reference-source") String referenceSource) {
this.securityService = securityService;
this.experimentService = experimentService;
this.experimentQueryMapper = experimentQueryMapper;
this.referenceSource = referenceSource;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert the changes that add SecurityService if it's not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SecurityService is not used. It has been removed.

return experimentId;
}

private SecurityRuleResult processExperiment(AuthenticatedUser authenticatedUser, String experimentId, String programId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you rename this method? We use the term "process" in a lot of our import code, and I think for that reason it is confusing to use it here. Something like checkAuthorization or getSecurityRuleResult would be more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed checkAuthorization

Comment on lines 77 to 78
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES})
public HttpResponse<Response<DataResponse<List<BrAPIStudy>>>> getStudies(
Copy link
Contributor

Choose a reason for hiding this comment

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

Ultimately this method needs to allow Experimental Collaborator role access. You can either do that in this PR or I will make the change in BI-2258 (where I have also implemented filtering in this method).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The roles now includes ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR

Comment on lines 53 to 57
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES})
public HttpResponse<Response<DataResponse<List<BrAPITrial>>>> getExperiments(
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to allow Experimental Collaborator role access. You could do that in the PR or else I'll do it in BI-2258 where I've implemented filtering in this method.

Copy link
Member

@nickpalladino nickpalladino left a comment

Choose a reason for hiding this comment

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

I'm seeing some integration tests failing that will need to be resolved. Some of them might be fixed by some of the suggested changes in this PR.

@davedrp davedrp requested a review from mlm483 August 15, 2024 19:41
@davedrp davedrp requested a review from nickpalladino August 15, 2024 19:41
Copy link
Contributor

@dmeidlin dmeidlin left a comment

Choose a reason for hiding this comment

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

When navigating to the system Programs section as a SysAdmin the back end returns a 500 response to GET calls to /v1/programs, resulting in no programs being listed.
ERROR o.b.a.v.c.InternalServerErrorHandler - Error Id: 91a2d7e4-f1a9-4527-906e-5caa9a9d0eb3
io.micronaut.http.server.exceptions.HttpServerException: Endpoint does not have program id to check roles against
at org.breedinginsight.api.auth.rules.ProgramSecuredAnnotationRule.check(ProgramSecuredAnnotationRule.java:66)
Same error also when loggin in as Program Admin and Read Only.

@davedrp
Copy link
Contributor Author

davedrp commented Aug 19, 2024

When navigating to the system Programs section as a SysAdmin the back end returns a 500 response to GET calls to /v1/programs, resulting in no programs being listed. ERROR o.b.a.v.c.InternalServerErrorHandler - Error Id: 91a2d7e4-f1a9-4527-906e-5caa9a9d0eb3 io.micronaut.http.server.exceptions.HttpServerException: Endpoint does not have program id to check roles against at org.breedinginsight.api.auth.rules.ProgramSecuredAnnotationRule.check(ProgramSecuredAnnotationRule.java:66) Same error also when loggin in as Program Admin and Read Only.

Fixed

@davedrp davedrp merged commit ff9abc7 into develop Aug 20, 2024
@davedrp davedrp deleted the feature/BI-2255 branch August 20, 2024 20:25
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.

6 participants