diff --git a/multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/Messages.java b/multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/Messages.java index 37b4e633ba..748a134eaa 100644 --- a/multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/Messages.java +++ b/multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/Messages.java @@ -25,6 +25,8 @@ public final class Messages { public static final String MISSING_PROPERTIES_FOR_CREATING_THE_SPECIFIC_PROVIDER = "Missing properties for creating the specific provider!"; public static final String DEPLOY_FROM_URL_WRONG_CREDENTIALS = "Credentials to {0} are wrong. Make sure that they are correct."; + public static final String FAILED_TO_CREATE_BLOB_STORE_CONTEXT = "Failed to create BlobStoreContext"; + // Audit log messages public static final String USER_TRYING_TO_LOGIN_AUDIT_LOG_MESSAGE = "\"{0}\" is trying to login in space \"{1}\""; public static final String USER_SUCCESSFULLY_LOGGED_IN_AUDIT_LOG_MESSAGE = "\"{0}\" successfully logged in space \"{1}\""; diff --git a/multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/configuration/bean/factory/ObjectStoreFileStorageFactoryBean.java b/multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/configuration/bean/factory/ObjectStoreFileStorageFactoryBean.java index 929a7d567b..410af21209 100644 --- a/multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/configuration/bean/factory/ObjectStoreFileStorageFactoryBean.java +++ b/multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/configuration/bean/factory/ObjectStoreFileStorageFactoryBean.java @@ -1,5 +1,11 @@ package org.cloudfoundry.multiapps.controller.web.configuration.bean.factory; +import java.text.MessageFormat; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import io.pivotal.cfenv.core.CfService; import org.apache.commons.lang3.StringUtils; import org.cloudfoundry.multiapps.controller.core.util.UriUtil; @@ -15,12 +21,6 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import java.text.MessageFormat; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - public class ObjectStoreFileStorageFactoryBean implements FactoryBean, InitializingBean { private static final Logger LOGGER = LoggerFactory.getLogger(ObjectStoreFileStorageFactoryBean.class); @@ -44,16 +44,13 @@ private ObjectStoreFileStorage createObjectStoreFileStorage() { if (providersServiceInfo.isEmpty()) { return null; } + Map exceptions = new HashMap<>(); + for (ObjectStoreServiceInfo objectStoreServiceInfo : providersServiceInfo) { - BlobStoreContext context = getBlobStoreContext(objectStoreServiceInfo); - if (context == null) { - exceptions.put(objectStoreServiceInfo.getProvider(), - new IllegalArgumentException(Messages.MISSING_PROPERTIES_FOR_CREATING_THE_SPECIFIC_PROVIDER)); - continue; - } - ObjectStoreFileStorage fileStorage = createFileStorage(objectStoreServiceInfo, context); try { + BlobStoreContext context = getBlobStoreContext(objectStoreServiceInfo); + ObjectStoreFileStorage fileStorage = createFileStorage(objectStoreServiceInfo, context); fileStorage.testConnection(); LOGGER.info(MessageFormat.format(Messages.OBJECT_STORE_WITH_PROVIDER_0_CREATED, objectStoreServiceInfo.getProvider())); return fileStorage; @@ -61,9 +58,11 @@ private ObjectStoreFileStorage createObjectStoreFileStorage() { exceptions.put(objectStoreServiceInfo.getProvider(), e); } } + exceptions.forEach( - (provider, exception) -> LOGGER.error(MessageFormat.format(Messages.CANNOT_CREATE_OBJECT_STORE_CLIENT_WITH_PROVIDER_0, provider), - exception)); + (provider, exception) -> LOGGER.error( + MessageFormat.format(Messages.CANNOT_CREATE_OBJECT_STORE_CLIENT_WITH_PROVIDER_0, provider), + exception)); throw new IllegalStateException(Messages.NO_VALID_OBJECT_STORE_CONFIGURATION_FOUND); } @@ -77,15 +76,31 @@ private List getProvidersServiceInfo() { private BlobStoreContext getBlobStoreContext(ObjectStoreServiceInfo serviceInfo) { ContextBuilder contextBuilder = ContextBuilder.newBuilder(serviceInfo.getProvider()); + applyCredentials(serviceInfo, contextBuilder); + + resolveContextEndpoint(serviceInfo, contextBuilder); + + BlobStoreContext context = contextBuilder.buildView(BlobStoreContext.class); + if (context == null) { + throw new IllegalStateException(Messages.FAILED_TO_CREATE_BLOB_STORE_CONTEXT); + } + + return context; + } + + private void applyCredentials(ObjectStoreServiceInfo serviceInfo, ContextBuilder contextBuilder) { if (serviceInfo.getCredentialsSupplier() != null) { contextBuilder.credentialsSupplier(serviceInfo.getCredentialsSupplier()); - } else if (serviceInfo.getIdentity() != null && serviceInfo.getCredential() != null) { - contextBuilder.credentials(serviceInfo.getIdentity(), serviceInfo.getCredential()); } else { - return null; + String identity = serviceInfo.getIdentity(); + String credential = serviceInfo.getCredential(); + + if (StringUtils.isBlank(identity) || StringUtils.isBlank(credential)) { + throw new IllegalArgumentException(Messages.MISSING_PROPERTIES_FOR_CREATING_THE_SPECIFIC_PROVIDER); + } + + contextBuilder.credentials(identity, credential); } - resolveContextEndpoint(serviceInfo, contextBuilder); - return contextBuilder.buildView(BlobStoreContext.class); } private void resolveContextEndpoint(ObjectStoreServiceInfo serviceInfo, ContextBuilder contextBuilder) { diff --git a/pom.xml b/pom.xml index b033db447d..db1d51785d 100644 --- a/pom.xml +++ b/pom.xml @@ -15,49 +15,49 @@ cloudfoundry ../multiapps-controller-coverage/target/site/jacoco-aggregate/jacoco.xml - 5.12.1 + 5.12.2 1.12.1 - 5.14.2 + 5.17.0 10.16.1.1 2.2.224 6.1.0 2.24.3 2.0.17 - 2.18.0 - 4.4 - 2.3 + 2.19.0 + 4.5.0 + 2.4 4.5.14 4.4.16 3.0.4 6.8.0 3.5.19 - 6.2.4 - 6.4.5 + 6.2.7 + 6.5.0 2.5.2 - 6.2.1 - 2.18.3 - 2.18.3 - 4.29.1 - 5.0.0 - 2.55.0 - 1.6.14 - 2.6.0 + 6.3.0 + 2.19.0 + 2.19.0 + 4.31.1 + 5.1.0 + 2.56.0 + 1.6.15 + 2.7.0 33.4.6-jre - 2.2.0 + 2.3.0 2.10.1 - 1.12.5 - 3.17.4 + 1.15.0 + 3.18.2 1.1.1 - 1.16.1 + 1.18.0 2.32.0 - 3.1.5 + 3.4.0 4.0.2 4.0.5 4.0.5 2.0.1 3.0.0 - 1.78 + 1.80 1.27.1 3.1.0