use of org.pmiops.workbench.model.AuditProjectAccessRequest in project workbench by all-of-us.
the class CloudTaskUserControllerTest method testBulkProjectAudit.
@Test
public void testBulkProjectAudit() throws Exception {
doReturn(ImmutableList.of()).when(mockCloudResourceManagerService).getAllProjectsForUser(userA);
doReturn(ImmutableList.of(new Project().setName("aou-rw-test-123").setParent(new ResourceId().setType("folder").setId("123")))).when(mockCloudResourceManagerService).getAllProjectsForUser(userB);
controller.auditProjectAccess(new AuditProjectAccessRequest().addUserIdsItem(userA.getUserId()).addUserIdsItem(userB.getUserId()));
verify(mockCloudResourceManagerService, times(2)).getAllProjectsForUser(any());
}
use of org.pmiops.workbench.model.AuditProjectAccessRequest in project workbench by all-of-us.
the class CloudTaskUserController method auditProjectAccess.
@Override
public ResponseEntity<Void> auditProjectAccess(AuditProjectAccessRequest request) {
int errorCount = 0;
for (long userId : request.getUserIds()) {
DbUser user = userDao.findUserByUserId(userId);
// TODO(RW-2062): Move to using the gcloud api for list all resources when it is available.
try {
List<String> unauthorizedLogs = cloudResourceManagerService.getAllProjectsForUser(user).stream().filter(project -> project.getParent() == null || !(ALLOWED_PARENT_IDS.contains(project.getParent().getId()))).map(project -> String.format("%s in %s %s", project.getName(), Optional.ofNullable(project.getParent()).map(ResourceId::getType).orElse("[type unknown]"), Optional.ofNullable(project.getParent()).map(ResourceId::getId).orElse("[id unknown]"))).collect(Collectors.toList());
if (unauthorizedLogs.size() > 0) {
log.warning("User " + user.getUsername() + " has access to projects: " + String.join(", ", unauthorizedLogs));
}
} catch (IOException e) {
log.log(Level.SEVERE, "failed to audit project access for user " + user.getUsername(), e);
errorCount++;
}
}
if (errorCount > 0) {
log.severe(String.format("encountered errors on %d/%d users", errorCount, request.getUserIds().size()));
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
log.info(String.format("successfully audited %d users", request.getUserIds().size()));
return ResponseEntity.noContent().build();
}
use of org.pmiops.workbench.model.AuditProjectAccessRequest in project workbench by all-of-us.
the class TaskQueueService method groupAndPushAuditProjectsTasks.
public void groupAndPushAuditProjectsTasks(List<Long> userIds) {
WorkbenchConfig workbenchConfig = workbenchConfigProvider.get();
List<List<Long>> groups = CloudTasksUtils.partitionList(userIds, workbenchConfig.offlineBatch.usersPerAuditTask);
for (List<Long> group : groups) {
createAndPushTask(AUDIT_PROJECTS_QUEUE_NAME, AUDIT_PROJECTS_PATH, new AuditProjectAccessRequest().userIds(group));
}
}
use of org.pmiops.workbench.model.AuditProjectAccessRequest in project workbench by all-of-us.
the class OfflineUserControllerTest method testBulkAuditProjectAccess.
@Test
public void testBulkAuditProjectAccess() {
offlineUserController.bulkAuditProjectAccess();
// Batch size is 2, so we expect 2 groups.
List<AuditProjectAccessRequest> expectedRequests = ImmutableList.of(new AuditProjectAccessRequest().userIds(ImmutableList.of(1L, 2L)), new AuditProjectAccessRequest().userIds(ImmutableList.of(3L, 4L)));
for (AuditProjectAccessRequest expected : expectedRequests) {
verify(mockCloudTasksClient).createTask(matches(Pattern.compile(".*/auditProjectQueue$")), argThat(taskRequest -> expected.equals(cloudTaskToAuditProjectAccessRequest(taskRequest))));
}
verifyNoMoreInteractions(mockCloudTasksClient);
}
use of org.pmiops.workbench.model.AuditProjectAccessRequest in project workbench by all-of-us.
the class TaskQueueService method groupAndPushSynchronizeAccessTasks.
public List<String> groupAndPushSynchronizeAccessTasks(List<Long> userIds) {
WorkbenchConfig workbenchConfig = workbenchConfigProvider.get();
List<List<Long>> groups = CloudTasksUtils.partitionList(userIds, workbenchConfig.offlineBatch.usersPerSynchronizeAccessTask);
List<String> tasknames = new ArrayList<>();
for (List<Long> group : groups) {
tasknames.add(createAndPushTask(SYNCHRONIZE_ACCESS_QUEUE_NAME, SYNCHRONIZE_ACCESS_PATH, new AuditProjectAccessRequest().userIds(group)));
}
return tasknames;
}
Aggregations