@Test public void test_secret_is_well_read() throws Exception { when(spaceEnrollerConfigRepository.exists(SERVICE_INSTANCE_ID)).thenReturn(false); Map<String, Object> params = singletonMap(Config.ServiceInstanceParameters.SECRET, "password"); CreateServiceInstanceRequest createRequest = getCreateRequestWithArbitraryParams(params); CreateServiceInstanceResponse si = instanceService.createServiceInstance(createRequest); verify(passwordEncoder, times(1)).encode(eq("password")); assertThat(si, is(notNullValue())); assertThat(serviceInstances.size(), is(equalTo(1))); SpaceEnrollerConfig serviceInstance = serviceInstances.get(0); assertThat(serviceInstance.getSecret(), is(equalTo(passwordEncoded))); }
@Override public CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request) throws ServiceInstanceExistsException, ServiceBrokerException { String serviceId = request.getServiceInstanceId(); log.debug("createServiceInstance - {}", serviceId); rejectDuplicateServiceInstanceRequest(serviceId); Map<String, Object> createParameters = Optional .ofNullable(request.getParameters()) .orElse(Collections.emptyMap()); Enrollment autoEnrollment = consumeParameter(createParameters, true, autoEnrollmentReader); String secret = consumeParameter(createParameters, true, secretReader); Duration idleDuration = consumeParameter(createParameters, true, idleDurationReader); Pattern excludeFromAutoEnrollment = consumeParameter(createParameters, true, excludeFromAutoEnrollmentReader); Boolean ignoreRouteServiceError = consumeParameter(createParameters, true, ignoreRouteServiceErrorReader); rejectExtraUnknownParameters(createParameters); if (autoEnrollment == Enrollment.forced || autoEnrollment == Enrollment.transient_opt_out) { checkSecuredParameter(autoEnrollmentReader.getParameterName(), secret); } SpaceEnrollerConfig spaceEnrollerConfig = SpaceEnrollerConfig.builder() .id(request.getServiceInstanceId()) .serviceDefinitionId(request.getServiceDefinitionId()) .planId(request.getPlanId()) .organizationId(request.getOrganizationGuid()) .spaceId(request.getSpaceGuid()) .idleDuration(idleDuration) .ignoreRouteServiceError(ignoreRouteServiceError) .excludeFromAutoEnrollment(excludeFromAutoEnrollment) .enrollment(autoEnrollment) .secret(secret != null ? passwordEncoder.encode(secret) : null) .build(); spaceEnrollerConfigRepository.save(spaceEnrollerConfig); workerManager.registerSpaceEnroller(spaceEnrollerConfig); String firstUri = deployment == null ? null : deployment.getFirstUri(); if (firstUri == null) { firstUri = "local-deployment"; } return new CreateServiceInstanceResponse() .withDashboardUrl(firstUri + Config.Path.DASHBOARD_CONTEXT + "/" + serviceId) .withAsync(false); }
AutosleepServiceInstanceService implements ServiceInstanceService { @Override public CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request) throws ServiceInstanceExistsException, ServiceBrokerException { String serviceId = request.getServiceInstanceId(); log.debug("createServiceInstance - {}", serviceId); rejectDuplicateServiceInstanceRequest(serviceId); Map<String, Object> createParameters = Optional .ofNullable(request.getParameters()) .orElse(Collections.emptyMap()); Enrollment autoEnrollment = consumeParameter(createParameters, true, autoEnrollmentReader); String secret = consumeParameter(createParameters, true, secretReader); Duration idleDuration = consumeParameter(createParameters, true, idleDurationReader); Pattern excludeFromAutoEnrollment = consumeParameter(createParameters, true, excludeFromAutoEnrollmentReader); Boolean ignoreRouteServiceError = consumeParameter(createParameters, true, ignoreRouteServiceErrorReader); rejectExtraUnknownParameters(createParameters); if (autoEnrollment == Enrollment.forced || autoEnrollment == Enrollment.transient_opt_out) { checkSecuredParameter(autoEnrollmentReader.getParameterName(), secret); } SpaceEnrollerConfig spaceEnrollerConfig = SpaceEnrollerConfig.builder() .id(request.getServiceInstanceId()) .serviceDefinitionId(request.getServiceDefinitionId()) .planId(request.getPlanId()) .organizationId(request.getOrganizationGuid()) .spaceId(request.getSpaceGuid()) .idleDuration(idleDuration) .ignoreRouteServiceError(ignoreRouteServiceError) .excludeFromAutoEnrollment(excludeFromAutoEnrollment) .enrollment(autoEnrollment) .secret(secret != null ? passwordEncoder.encode(secret) : null) .build(); spaceEnrollerConfigRepository.save(spaceEnrollerConfig); workerManager.registerSpaceEnroller(spaceEnrollerConfig); String firstUri = deployment == null ? null : deployment.getFirstUri(); if (firstUri == null) { firstUri = "local-deployment"; } return new CreateServiceInstanceResponse() .withDashboardUrl(firstUri + Config.Path.DASHBOARD_CONTEXT + "/" + serviceId) .withAsync(false); } }
AutosleepServiceInstanceService implements ServiceInstanceService { @Override public CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request) throws ServiceInstanceExistsException, ServiceBrokerException { String serviceId = request.getServiceInstanceId(); log.debug("createServiceInstance - {}", serviceId); rejectDuplicateServiceInstanceRequest(serviceId); Map<String, Object> createParameters = Optional .ofNullable(request.getParameters()) .orElse(Collections.emptyMap()); Enrollment autoEnrollment = consumeParameter(createParameters, true, autoEnrollmentReader); String secret = consumeParameter(createParameters, true, secretReader); Duration idleDuration = consumeParameter(createParameters, true, idleDurationReader); Pattern excludeFromAutoEnrollment = consumeParameter(createParameters, true, excludeFromAutoEnrollmentReader); Boolean ignoreRouteServiceError = consumeParameter(createParameters, true, ignoreRouteServiceErrorReader); rejectExtraUnknownParameters(createParameters); if (autoEnrollment == Enrollment.forced || autoEnrollment == Enrollment.transient_opt_out) { checkSecuredParameter(autoEnrollmentReader.getParameterName(), secret); } SpaceEnrollerConfig spaceEnrollerConfig = SpaceEnrollerConfig.builder() .id(request.getServiceInstanceId()) .serviceDefinitionId(request.getServiceDefinitionId()) .planId(request.getPlanId()) .organizationId(request.getOrganizationGuid()) .spaceId(request.getSpaceGuid()) .idleDuration(idleDuration) .ignoreRouteServiceError(ignoreRouteServiceError) .excludeFromAutoEnrollment(excludeFromAutoEnrollment) .enrollment(autoEnrollment) .secret(secret != null ? passwordEncoder.encode(secret) : null) .build(); spaceEnrollerConfigRepository.save(spaceEnrollerConfig); workerManager.registerSpaceEnroller(spaceEnrollerConfig); String firstUri = deployment == null ? null : deployment.getFirstUri(); if (firstUri == null) { firstUri = "local-deployment"; } return new CreateServiceInstanceResponse() .withDashboardUrl(firstUri + Config.Path.DASHBOARD_CONTEXT + "/" + serviceId) .withAsync(false); }  }
AutosleepServiceInstanceService implements ServiceInstanceService { @Override public CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request) throws ServiceInstanceExistsException, ServiceBrokerException { String serviceId = request.getServiceInstanceId(); log.debug("createServiceInstance - {}", serviceId); rejectDuplicateServiceInstanceRequest(serviceId); Map<String, Object> createParameters = Optional .ofNullable(request.getParameters()) .orElse(Collections.emptyMap()); Enrollment autoEnrollment = consumeParameter(createParameters, true, autoEnrollmentReader); String secret = consumeParameter(createParameters, true, secretReader); Duration idleDuration = consumeParameter(createParameters, true, idleDurationReader); Pattern excludeFromAutoEnrollment = consumeParameter(createParameters, true, excludeFromAutoEnrollmentReader); Boolean ignoreRouteServiceError = consumeParameter(createParameters, true, ignoreRouteServiceErrorReader); rejectExtraUnknownParameters(createParameters); if (autoEnrollment == Enrollment.forced || autoEnrollment == Enrollment.transient_opt_out) { checkSecuredParameter(autoEnrollmentReader.getParameterName(), secret); } SpaceEnrollerConfig spaceEnrollerConfig = SpaceEnrollerConfig.builder() .id(request.getServiceInstanceId()) .serviceDefinitionId(request.getServiceDefinitionId()) .planId(request.getPlanId()) .organizationId(request.getOrganizationGuid()) .spaceId(request.getSpaceGuid()) .idleDuration(idleDuration) .ignoreRouteServiceError(ignoreRouteServiceError) .excludeFromAutoEnrollment(excludeFromAutoEnrollment) .enrollment(autoEnrollment) .secret(secret != null ? passwordEncoder.encode(secret) : null) .build(); spaceEnrollerConfigRepository.save(spaceEnrollerConfig); workerManager.registerSpaceEnroller(spaceEnrollerConfig); String firstUri = deployment == null ? null : deployment.getFirstUri(); if (firstUri == null) { firstUri = "local-deployment"; } return new CreateServiceInstanceResponse() .withDashboardUrl(firstUri + Config.Path.DASHBOARD_CONTEXT + "/" + serviceId) .withAsync(false); }  @Override CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request); @Override DeleteServiceInstanceResponse deleteServiceInstance(
            DeleteServiceInstanceRequest request); @Override GetLastServiceOperationResponse getLastOperation(GetLastServiceOperationRequest
                                                                    getLastServiceOperationRequest); @Override UpdateServiceInstanceResponse updateServiceInstance(
            UpdateServiceInstanceRequest request); }
AutosleepServiceInstanceService implements ServiceInstanceService { @Override public CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request) throws ServiceInstanceExistsException, ServiceBrokerException { String serviceId = request.getServiceInstanceId(); log.debug("createServiceInstance - {}", serviceId); rejectDuplicateServiceInstanceRequest(serviceId); Map<String, Object> createParameters = Optional .ofNullable(request.getParameters()) .orElse(Collections.emptyMap()); Enrollment autoEnrollment = consumeParameter(createParameters, true, autoEnrollmentReader); String secret = consumeParameter(createParameters, true, secretReader); Duration idleDuration = consumeParameter(createParameters, true, idleDurationReader); Pattern excludeFromAutoEnrollment = consumeParameter(createParameters, true, excludeFromAutoEnrollmentReader); Boolean ignoreRouteServiceError = consumeParameter(createParameters, true, ignoreRouteServiceErrorReader); rejectExtraUnknownParameters(createParameters); if (autoEnrollment == Enrollment.forced || autoEnrollment == Enrollment.transient_opt_out) { checkSecuredParameter(autoEnrollmentReader.getParameterName(), secret); } SpaceEnrollerConfig spaceEnrollerConfig = SpaceEnrollerConfig.builder() .id(request.getServiceInstanceId()) .serviceDefinitionId(request.getServiceDefinitionId()) .planId(request.getPlanId()) .organizationId(request.getOrganizationGuid()) .spaceId(request.getSpaceGuid()) .idleDuration(idleDuration) .ignoreRouteServiceError(ignoreRouteServiceError) .excludeFromAutoEnrollment(excludeFromAutoEnrollment) .enrollment(autoEnrollment) .secret(secret != null ? passwordEncoder.encode(secret) : null) .build(); spaceEnrollerConfigRepository.save(spaceEnrollerConfig); workerManager.registerSpaceEnroller(spaceEnrollerConfig); String firstUri = deployment == null ? null : deployment.getFirstUri(); if (firstUri == null) { firstUri = "local-deployment"; } return new CreateServiceInstanceResponse() .withDashboardUrl(firstUri + Config.Path.DASHBOARD_CONTEXT + "/" + serviceId) .withAsync(false); }  @Override CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request); @Override DeleteServiceInstanceResponse deleteServiceInstance(
            DeleteServiceInstanceRequest request); @Override GetLastServiceOperationResponse getLastOperation(GetLastServiceOperationRequest
                                                                    getLastServiceOperationRequest); @Override UpdateServiceInstanceResponse updateServiceInstance(
            UpdateServiceInstanceRequest request);  }