package com.ofg.infrastructure.property;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.core.io.Resource;
import org.springframework.security.crypto.encrypt.TextEncryptor;

@Configuration
@Profile("!test")
public class ExternalPropertiesConfiguration implements ApplicationContextInitializer<ConfigurableApplicationContext>, Ordered {

    @Autowired(required = false)
    private TextEncryptor textEncryptor;

    @Value("${microservice.config.file:classpath:microservice.json}")
    private Resource microserviceConfig;

    @Bean
    public FileSystemLocator fileSystemLocator() {
        return new FileSystemLocator(
                PropertiesFolderFinder.find(),
                appCoordinates(),
                textEncryptor == null ? new FailsafeTextEncryptor() : textEncryptor);
    }

    @Bean
    public AppCoordinates appCoordinates() {
        return AppCoordinates.defaults(microserviceConfig);
    }

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
    }

    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE;
    }

    /**
     * TextEncryptor that just fails, so that users don't get a false sense of security
     * adding ciphers to config files and not getting them decrypted.
     * <p/>
     * Based on FailsafeTextEncryptor from spring-cloud-config by Dave Syer.
     */
    static class FailsafeTextEncryptor implements TextEncryptor {

        @Override
        public String encrypt(String text) {
            throw new UnsupportedOperationException("Encryption is not supported. Did you configure the encryption key/keystore correctly?");
        }

        @Override
        public String decrypt(String encryptedText) {
            throw new UnsupportedOperationException("Decryption is not supported. Did you configure the encryption key/keystore correctly?");
        }
    }
}

@@ -35,16 +35,114 @@
 perty;%0A%0A
+import com.ofg.infrastructure.property.decrypt.JceUnlimitedStrengthUtil;%0Aimport org.slf4j.Logger;%0A
 import o
@@ -192,24 +192,24 @@
 .Autowired;%0A
-
 import org.s
@@ -709,16 +709,119 @@
 yptor;%0A%0A
+import static java.lang.invoke.MethodHandles.lookup;%0Aimport static org.slf4j.LoggerFactory.getLogger;%0A%0A
 @Configu
@@ -971,24 +971,98 @@
  Ordered %7B%0A%0A
+    private static final Logger log = getLogger(lookup().lookupClass());%0A%0A
     @Autowir
@@ -1637,32 +1637,32 @@
 %0A%0A    @Override%0A
-
     public void 
@@ -1721,24 +1721,105 @@
 nContext) %7B%0A
+        JceUnlimitedStrengthUtil.printWarningIfStrongEncryptionIsNotSupported();%0A
     %7D%0A%0A    @

Add warning message at application context startup