BI-2255 - Experimental Collaborator Micronaut Changes#388
Conversation
mlm483
left a comment
There was a problem hiding this comment.
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_ROLEScurrently includesProgramSecuredRole.EXPERIMENTAL_COLLABORATORand it should not.
| public enum ExperimentCollaboratorSecuredRole { | ||
| EXPERIMENTAL_COLLABORATOR("Experimental Collaborator"); |
There was a problem hiding this comment.
I'm concerned that defining EXPERIMENTAL_COLLABORATOR here as well as in the ProgramSecuredRole enum could lead to confusion.
There was a problem hiding this comment.
After seeing how this is used, I recommend deleting this file and using ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR in ExperimentCollaboratorSecuredAnnotationRule::isExperimentCoordinator instead.
| 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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thanks, I now understand the new role.
The recommended changes have been made.
| @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) { |
There was a problem hiding this comment.
Does the Experimental Collaborator role need access to this endpoint? I think this change should be reverted.
There was a problem hiding this comment.
The code has been reverted.
| @Secured(SecurityRule.IS_ANONYMOUS) | ||
| @ProgramSecured(roles = {ProgramSecuredRole.PROGRAM_ADMIN, ProgramSecuredRole.SYSTEM_ADMIN}) | ||
| public HttpResponse<Response<DataResponse<ImportMapping>>> getSystemMappings(@Nullable @QueryValue String importName) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
It also looks like the ImportControllerIntegrationTest::getSystemMappings test is failing
There was a problem hiding this comment.
The @ProgramSecured should not have been added. I have removed it.
There was a problem hiding this comment.
@nickpalladino yes it was causing a failure
| private boolean isExperimentCoordinator(ProgramUser programUser){ | ||
| List<Role> roles = programUser.getRoles(); | ||
| return (roles.size()==1 && | ||
| ProgramSecuredRole.getEnum(roles.get(0).getDomain())==ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR); | ||
|
|
||
| } |
There was a problem hiding this comment.
Remove if unused. (I think I wrote this method... it doesn't seem to be needed).
There was a problem hiding this comment.
Looks like it was probably moved to ExperimentCollaboratorSecuredAnnotationRule and updated
| 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; | ||
| } |
There was a problem hiding this comment.
Revert the changes that add SecurityService if it's not used.
There was a problem hiding this comment.
SecurityService is not used. It has been removed.
| return experimentId; | ||
| } | ||
|
|
||
| private SecurityRuleResult processExperiment(AuthenticatedUser authenticatedUser, String experimentId, String programId) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
renamed checkAuthorization
src/main/java/org/breedinginsight/api/v1/controller/ProgramController.java
Show resolved
Hide resolved
| @Produces(MediaType.APPLICATION_JSON) | ||
| @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) | ||
| @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES}) | ||
| public HttpResponse<Response<DataResponse<List<BrAPIStudy>>>> getStudies( |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
The roles now includes ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR
| @Produces(MediaType.APPLICATION_JSON) | ||
| @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) | ||
| @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES}) | ||
| public HttpResponse<Response<DataResponse<List<BrAPITrial>>>> getExperiments( |
There was a problem hiding this comment.
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.
nickpalladino
left a comment
There was a problem hiding this comment.
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.
src/main/java/org/breedinginsight/api/v1/controller/ProgramController.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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 |
Description
BI-2255 - Experimental Collaborator Micronaut Changes
EXPERIMENTAL_COLLABORATORto the enumProgramSecuredRoleProgramSecuredRoleGroup.ALLtoProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES.ProgramSecuredRole.EXPERIMENTAL_COLLABORATORtoProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES@ExperimentCollaboratorSecuredannotation for endpoints with experimentId (or traitId)Testing
see Acceptance Criteria in BI-2255
Checklist: