@Test void synchronizeUser() { Operation operation = mock(Operation.class); when(userSyncService.synchronizeUsersWithCustomPermissionCheck(any(), any(), any(), any(), any())).thenReturn(operation); SyncOperationStatus status = mock(SyncOperationStatus.class); when(operationToSyncOperationStatus.convert(operation)).thenReturn(status); SynchronizeUserRequest request = mock(SynchronizeUserRequest.class); assertEquals(status, ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.synchronizeUser(request))); UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(USER_CRN), Set.of(), Optional.empty()); verify(userSyncService, times(1)).synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, Set.of(), userSyncFilter, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT); }
@Override @CustomPermissionCheck public SyncOperationStatus synchronizeUser(SynchronizeUserRequest request) { String userCrn = checkActorCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); LOGGER.debug("synchronizeUser() requested for user {} in account {}", userCrn, accountId); Set<String> environmentCrnFilter = request == null ? Set.of() : nullToEmpty(request.getEnvironments()); Set<String> userCrnFilter = Set.of(); Set<String> machineUserCrnFilter = Set.of(); Crn crn = Crn.safeFromString(userCrn); switch (crn.getResourceType()) { case USER: userCrnFilter = Set.of(userCrn); break; case MACHINE_USER: machineUserCrnFilter = Set.of(userCrn); break; default: throw new BadRequestException(String.format("UserCrn %s is not of resoure type USER or MACHINE_USER", userCrn)); } UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(userCrnFilter, machineUserCrnFilter, Optional.empty()); Operation syncOperation = userSyncService.synchronizeUsersWithCustomPermissionCheck(accountId, userCrn, environmentCrnFilter, userSyncFilter, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT); return checkOperationRejected(operationToSyncOperationStatus.convert(syncOperation)); }
UserV1Controller implements UserV1Endpoint { @Override @CustomPermissionCheck public SyncOperationStatus synchronizeUser(SynchronizeUserRequest request) { String userCrn = checkActorCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); LOGGER.debug("synchronizeUser() requested for user {} in account {}", userCrn, accountId); Set<String> environmentCrnFilter = request == null ? Set.of() : nullToEmpty(request.getEnvironments()); Set<String> userCrnFilter = Set.of(); Set<String> machineUserCrnFilter = Set.of(); Crn crn = Crn.safeFromString(userCrn); switch (crn.getResourceType()) { case USER: userCrnFilter = Set.of(userCrn); break; case MACHINE_USER: machineUserCrnFilter = Set.of(userCrn); break; default: throw new BadRequestException(String.format("UserCrn %s is not of resoure type USER or MACHINE_USER", userCrn)); } UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(userCrnFilter, machineUserCrnFilter, Optional.empty()); Operation syncOperation = userSyncService.synchronizeUsersWithCustomPermissionCheck(accountId, userCrn, environmentCrnFilter, userSyncFilter, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT); return checkOperationRejected(operationToSyncOperationStatus.convert(syncOperation)); } }
UserV1Controller implements UserV1Endpoint { @Override @CustomPermissionCheck public SyncOperationStatus synchronizeUser(SynchronizeUserRequest request) { String userCrn = checkActorCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); LOGGER.debug("synchronizeUser() requested for user {} in account {}", userCrn, accountId); Set<String> environmentCrnFilter = request == null ? Set.of() : nullToEmpty(request.getEnvironments()); Set<String> userCrnFilter = Set.of(); Set<String> machineUserCrnFilter = Set.of(); Crn crn = Crn.safeFromString(userCrn); switch (crn.getResourceType()) { case USER: userCrnFilter = Set.of(userCrn); break; case MACHINE_USER: machineUserCrnFilter = Set.of(userCrn); break; default: throw new BadRequestException(String.format("UserCrn %s is not of resoure type USER or MACHINE_USER", userCrn)); } UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(userCrnFilter, machineUserCrnFilter, Optional.empty()); Operation syncOperation = userSyncService.synchronizeUsersWithCustomPermissionCheck(accountId, userCrn, environmentCrnFilter, userSyncFilter, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT); return checkOperationRejected(operationToSyncOperationStatus.convert(syncOperation)); }  }
UserV1Controller implements UserV1Endpoint { @Override @CustomPermissionCheck public SyncOperationStatus synchronizeUser(SynchronizeUserRequest request) { String userCrn = checkActorCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); LOGGER.debug("synchronizeUser() requested for user {} in account {}", userCrn, accountId); Set<String> environmentCrnFilter = request == null ? Set.of() : nullToEmpty(request.getEnvironments()); Set<String> userCrnFilter = Set.of(); Set<String> machineUserCrnFilter = Set.of(); Crn crn = Crn.safeFromString(userCrn); switch (crn.getResourceType()) { case USER: userCrnFilter = Set.of(userCrn); break; case MACHINE_USER: machineUserCrnFilter = Set.of(userCrn); break; default: throw new BadRequestException(String.format("UserCrn %s is not of resoure type USER or MACHINE_USER", userCrn)); } UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(userCrnFilter, machineUserCrnFilter, Optional.empty()); Operation syncOperation = userSyncService.synchronizeUsersWithCustomPermissionCheck(accountId, userCrn, environmentCrnFilter, userSyncFilter, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT); return checkOperationRejected(operationToSyncOperationStatus.convert(syncOperation)); }  @Override @CustomPermissionCheck SyncOperationStatus synchronizeUser(SynchronizeUserRequest request); @Override @CustomPermissionCheck SyncOperationStatus synchronizeAllUsers(SynchronizeAllUsersRequest request); @Override @CustomPermissionCheck @CheckPermissionByAccount(action = AuthorizationResourceAction.ENVIRONMENT_READ) SyncOperationStatus setPassword(SetPasswordRequest request); @Override @CheckPermissionByAccount(action = AuthorizationResourceAction.GET_OPERATION_STATUS) SyncOperationStatus getSyncOperationStatus(@NotNull String operationId); @Override @CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_ENVIRONMENT) EnvironmentUserSyncState getUserSyncState(@ResourceCrn @TenantAwareParam @NotEmpty String environmentCrn); }
UserV1Controller implements UserV1Endpoint { @Override @CustomPermissionCheck public SyncOperationStatus synchronizeUser(SynchronizeUserRequest request) { String userCrn = checkActorCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); LOGGER.debug("synchronizeUser() requested for user {} in account {}", userCrn, accountId); Set<String> environmentCrnFilter = request == null ? Set.of() : nullToEmpty(request.getEnvironments()); Set<String> userCrnFilter = Set.of(); Set<String> machineUserCrnFilter = Set.of(); Crn crn = Crn.safeFromString(userCrn); switch (crn.getResourceType()) { case USER: userCrnFilter = Set.of(userCrn); break; case MACHINE_USER: machineUserCrnFilter = Set.of(userCrn); break; default: throw new BadRequestException(String.format("UserCrn %s is not of resoure type USER or MACHINE_USER", userCrn)); } UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(userCrnFilter, machineUserCrnFilter, Optional.empty()); Operation syncOperation = userSyncService.synchronizeUsersWithCustomPermissionCheck(accountId, userCrn, environmentCrnFilter, userSyncFilter, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT); return checkOperationRejected(operationToSyncOperationStatus.convert(syncOperation)); }  @Override @CustomPermissionCheck SyncOperationStatus synchronizeUser(SynchronizeUserRequest request); @Override @CustomPermissionCheck SyncOperationStatus synchronizeAllUsers(SynchronizeAllUsersRequest request); @Override @CustomPermissionCheck @CheckPermissionByAccount(action = AuthorizationResourceAction.ENVIRONMENT_READ) SyncOperationStatus setPassword(SetPasswordRequest request); @Override @CheckPermissionByAccount(action = AuthorizationResourceAction.GET_OPERATION_STATUS) SyncOperationStatus getSyncOperationStatus(@NotNull String operationId); @Override @CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_ENVIRONMENT) EnvironmentUserSyncState getUserSyncState(@ResourceCrn @TenantAwareParam @NotEmpty String environmentCrn);  }