@Test public void test_update_succeeds_when_autoenrollment_with_secret() throws Exception { final SpaceEnrollerConfig existingServiceInstance = service_exist_in_database(); when(passwordEncoder.matches(anyString(), anyString())).thenReturn(true); Map<String, Object> parameters = new HashMap<>(); parameters.put(Config.ServiceInstanceParameters.SECRET, "secret"); parameters.put(Config.ServiceInstanceParameters.AUTO_ENROLLMENT, Enrollment.standard.name()); UpdateServiceInstanceRequest updateRequest = getUpdateRequestWithArbitraryParams(parameters); UpdateServiceInstanceResponse response = instanceService.updateServiceInstance(updateRequest); verify(spaceEnrollerConfigRepository, times(1)).save(any(SpaceEnrollerConfig.class)); assertThat(response, is(notNullValue())); assertFalse(existingServiceInstance.getEnrollment() == Enrollment.forced); }
@Override public UpdateServiceInstanceResponse updateServiceInstance( UpdateServiceInstanceRequest request) throws ServiceInstanceUpdateNotSupportedException, ServiceBrokerException, ServiceInstanceDoesNotExistException { String spaceEnrollerConfigId = request.getServiceInstanceId(); log.debug("updateServiceInstance - {}", spaceEnrollerConfigId); SpaceEnrollerConfig spaceEnrollerConfig = spaceEnrollerConfigRepository.findOne(spaceEnrollerConfigId); if (spaceEnrollerConfig == null) { throw new ServiceInstanceDoesNotExistException(spaceEnrollerConfigId); } else if (!spaceEnrollerConfig.getPlanId().equals(request.getPlanId())) { throw new ServiceInstanceUpdateNotSupportedException("Service plan updates not supported."); } else { Map<String, Object> updateParameters = Optional .ofNullable(request.getParameters()) .orElse(Collections.emptyMap()); Enrollment autoEnrollment = consumeParameter(updateParameters, false, autoEnrollmentReader); String secret = consumeParameter(updateParameters, false, secretReader); if (!updateParameters.isEmpty()) { String parameterNames = String.join(", ", updateParameters.keySet().iterator().next()); log.debug("updateServiceInstance - extra parameters are not accepted: {}", parameterNames); throw new InvalidParameterException(parameterNames, "Unknown parameters for update"); } else if (autoEnrollment != null) { checkSecuredParameter(autoEnrollmentReader.getParameterName(), secret); if (spaceEnrollerConfig.getSecret() != null && !( passwordEncoder.matches(secret, spaceEnrollerConfig.getSecret()) || secret.equals(environment.getProperty(Config.EnvKey.SECURITY_PASSWORD)) )) { throw new InvalidParameterException(Config.ServiceInstanceParameters.SECRET, "Provided secret does not match the one provided on creation nor the " + Config.EnvKey.SECURITY_PASSWORD + " value."); } spaceEnrollerConfig.setEnrollment(autoEnrollment); spaceEnrollerConfigRepository.save(spaceEnrollerConfig); } return new UpdateServiceInstanceResponse().withAsync(false); } }
AutosleepServiceInstanceService implements ServiceInstanceService { @Override public UpdateServiceInstanceResponse updateServiceInstance( UpdateServiceInstanceRequest request) throws ServiceInstanceUpdateNotSupportedException, ServiceBrokerException, ServiceInstanceDoesNotExistException { String spaceEnrollerConfigId = request.getServiceInstanceId(); log.debug("updateServiceInstance - {}", spaceEnrollerConfigId); SpaceEnrollerConfig spaceEnrollerConfig = spaceEnrollerConfigRepository.findOne(spaceEnrollerConfigId); if (spaceEnrollerConfig == null) { throw new ServiceInstanceDoesNotExistException(spaceEnrollerConfigId); } else if (!spaceEnrollerConfig.getPlanId().equals(request.getPlanId())) { throw new ServiceInstanceUpdateNotSupportedException("Service plan updates not supported."); } else { Map<String, Object> updateParameters = Optional .ofNullable(request.getParameters()) .orElse(Collections.emptyMap()); Enrollment autoEnrollment = consumeParameter(updateParameters, false, autoEnrollmentReader); String secret = consumeParameter(updateParameters, false, secretReader); if (!updateParameters.isEmpty()) { String parameterNames = String.join(", ", updateParameters.keySet().iterator().next()); log.debug("updateServiceInstance - extra parameters are not accepted: {}", parameterNames); throw new InvalidParameterException(parameterNames, "Unknown parameters for update"); } else if (autoEnrollment != null) { checkSecuredParameter(autoEnrollmentReader.getParameterName(), secret); if (spaceEnrollerConfig.getSecret() != null && !( passwordEncoder.matches(secret, spaceEnrollerConfig.getSecret()) || secret.equals(environment.getProperty(Config.EnvKey.SECURITY_PASSWORD)) )) { throw new InvalidParameterException(Config.ServiceInstanceParameters.SECRET, "Provided secret does not match the one provided on creation nor the " + Config.EnvKey.SECURITY_PASSWORD + " value."); } spaceEnrollerConfig.setEnrollment(autoEnrollment); spaceEnrollerConfigRepository.save(spaceEnrollerConfig); } return new UpdateServiceInstanceResponse().withAsync(false); } } }
AutosleepServiceInstanceService implements ServiceInstanceService { @Override public UpdateServiceInstanceResponse updateServiceInstance( UpdateServiceInstanceRequest request) throws ServiceInstanceUpdateNotSupportedException, ServiceBrokerException, ServiceInstanceDoesNotExistException { String spaceEnrollerConfigId = request.getServiceInstanceId(); log.debug("updateServiceInstance - {}", spaceEnrollerConfigId); SpaceEnrollerConfig spaceEnrollerConfig = spaceEnrollerConfigRepository.findOne(spaceEnrollerConfigId); if (spaceEnrollerConfig == null) { throw new ServiceInstanceDoesNotExistException(spaceEnrollerConfigId); } else if (!spaceEnrollerConfig.getPlanId().equals(request.getPlanId())) { throw new ServiceInstanceUpdateNotSupportedException("Service plan updates not supported."); } else { Map<String, Object> updateParameters = Optional .ofNullable(request.getParameters()) .orElse(Collections.emptyMap()); Enrollment autoEnrollment = consumeParameter(updateParameters, false, autoEnrollmentReader); String secret = consumeParameter(updateParameters, false, secretReader); if (!updateParameters.isEmpty()) { String parameterNames = String.join(", ", updateParameters.keySet().iterator().next()); log.debug("updateServiceInstance - extra parameters are not accepted: {}", parameterNames); throw new InvalidParameterException(parameterNames, "Unknown parameters for update"); } else if (autoEnrollment != null) { checkSecuredParameter(autoEnrollmentReader.getParameterName(), secret); if (spaceEnrollerConfig.getSecret() != null && !( passwordEncoder.matches(secret, spaceEnrollerConfig.getSecret()) || secret.equals(environment.getProperty(Config.EnvKey.SECURITY_PASSWORD)) )) { throw new InvalidParameterException(Config.ServiceInstanceParameters.SECRET, "Provided secret does not match the one provided on creation nor the " + Config.EnvKey.SECURITY_PASSWORD + " value."); } spaceEnrollerConfig.setEnrollment(autoEnrollment); spaceEnrollerConfigRepository.save(spaceEnrollerConfig); } return new UpdateServiceInstanceResponse().withAsync(false); } }  }
AutosleepServiceInstanceService implements ServiceInstanceService { @Override public UpdateServiceInstanceResponse updateServiceInstance( UpdateServiceInstanceRequest request) throws ServiceInstanceUpdateNotSupportedException, ServiceBrokerException, ServiceInstanceDoesNotExistException { String spaceEnrollerConfigId = request.getServiceInstanceId(); log.debug("updateServiceInstance - {}", spaceEnrollerConfigId); SpaceEnrollerConfig spaceEnrollerConfig = spaceEnrollerConfigRepository.findOne(spaceEnrollerConfigId); if (spaceEnrollerConfig == null) { throw new ServiceInstanceDoesNotExistException(spaceEnrollerConfigId); } else if (!spaceEnrollerConfig.getPlanId().equals(request.getPlanId())) { throw new ServiceInstanceUpdateNotSupportedException("Service plan updates not supported."); } else { Map<String, Object> updateParameters = Optional .ofNullable(request.getParameters()) .orElse(Collections.emptyMap()); Enrollment autoEnrollment = consumeParameter(updateParameters, false, autoEnrollmentReader); String secret = consumeParameter(updateParameters, false, secretReader); if (!updateParameters.isEmpty()) { String parameterNames = String.join(", ", updateParameters.keySet().iterator().next()); log.debug("updateServiceInstance - extra parameters are not accepted: {}", parameterNames); throw new InvalidParameterException(parameterNames, "Unknown parameters for update"); } else if (autoEnrollment != null) { checkSecuredParameter(autoEnrollmentReader.getParameterName(), secret); if (spaceEnrollerConfig.getSecret() != null && !( passwordEncoder.matches(secret, spaceEnrollerConfig.getSecret()) || secret.equals(environment.getProperty(Config.EnvKey.SECURITY_PASSWORD)) )) { throw new InvalidParameterException(Config.ServiceInstanceParameters.SECRET, "Provided secret does not match the one provided on creation nor the " + Config.EnvKey.SECURITY_PASSWORD + " value."); } spaceEnrollerConfig.setEnrollment(autoEnrollment); spaceEnrollerConfigRepository.save(spaceEnrollerConfig); } return new UpdateServiceInstanceResponse().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 UpdateServiceInstanceResponse updateServiceInstance( UpdateServiceInstanceRequest request) throws ServiceInstanceUpdateNotSupportedException, ServiceBrokerException, ServiceInstanceDoesNotExistException { String spaceEnrollerConfigId = request.getServiceInstanceId(); log.debug("updateServiceInstance - {}", spaceEnrollerConfigId); SpaceEnrollerConfig spaceEnrollerConfig = spaceEnrollerConfigRepository.findOne(spaceEnrollerConfigId); if (spaceEnrollerConfig == null) { throw new ServiceInstanceDoesNotExistException(spaceEnrollerConfigId); } else if (!spaceEnrollerConfig.getPlanId().equals(request.getPlanId())) { throw new ServiceInstanceUpdateNotSupportedException("Service plan updates not supported."); } else { Map<String, Object> updateParameters = Optional .ofNullable(request.getParameters()) .orElse(Collections.emptyMap()); Enrollment autoEnrollment = consumeParameter(updateParameters, false, autoEnrollmentReader); String secret = consumeParameter(updateParameters, false, secretReader); if (!updateParameters.isEmpty()) { String parameterNames = String.join(", ", updateParameters.keySet().iterator().next()); log.debug("updateServiceInstance - extra parameters are not accepted: {}", parameterNames); throw new InvalidParameterException(parameterNames, "Unknown parameters for update"); } else if (autoEnrollment != null) { checkSecuredParameter(autoEnrollmentReader.getParameterName(), secret); if (spaceEnrollerConfig.getSecret() != null && !( passwordEncoder.matches(secret, spaceEnrollerConfig.getSecret()) || secret.equals(environment.getProperty(Config.EnvKey.SECURITY_PASSWORD)) )) { throw new InvalidParameterException(Config.ServiceInstanceParameters.SECRET, "Provided secret does not match the one provided on creation nor the " + Config.EnvKey.SECURITY_PASSWORD + " value."); } spaceEnrollerConfig.setEnrollment(autoEnrollment); spaceEnrollerConfigRepository.save(spaceEnrollerConfig); } return new UpdateServiceInstanceResponse().withAsync(false); } }  @Override CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request); @Override DeleteServiceInstanceResponse deleteServiceInstance(
            DeleteServiceInstanceRequest request); @Override GetLastServiceOperationResponse getLastOperation(GetLastServiceOperationRequest
                                                                    getLastServiceOperationRequest); @Override UpdateServiceInstanceResponse updateServiceInstance(
            UpdateServiceInstanceRequest request);  }