Search in sources :

Example 11 with EncryptionOperationNotPossibleException

use of org.jasypt.exceptions.EncryptionOperationNotPossibleException in project fabric8 by jboss-fuse.

the class FabricServiceImpl method substituteConfigurations.

/**
 * Performs substitution to configuration based on the registered {@link PlaceholderResolver} instances.
 */
public Map<String, Map<String, String>> substituteConfigurations(final Map<String, Map<String, String>> configurations) {
    final Map<String, PlaceholderResolver> resolversSnapshot = new HashMap<String, PlaceholderResolver>(placeholderResolvers);
    // Check that all resolvers are available
    Set<String> requiredSchemes = getSchemesForProfileConfigurations(configurations);
    Set<String> availableSchemes = resolversSnapshot.keySet();
    if (!availableSchemes.containsAll(requiredSchemes)) {
        StringBuilder sb = new StringBuilder();
        sb.append("Missing Placeholder Resolvers:");
        for (String scheme : requiredSchemes) {
            if (!availableSchemes.contains(scheme)) {
                sb.append(" ").append(scheme);
            }
        }
        throw new FabricException(sb.toString());
    }
    final Map<String, Map<String, String>> mutableConfigurations = new HashMap<>();
    for (Entry<String, Map<String, String>> entry : configurations.entrySet()) {
        String key = entry.getKey();
        Map<String, String> value = new HashMap<>(entry.getValue());
        mutableConfigurations.put(key, value);
    }
    final FabricService fabricService = this;
    for (Map.Entry<String, Map<String, String>> entry : mutableConfigurations.entrySet()) {
        final String pid = entry.getKey();
        Map<String, String> props = entry.getValue();
        Map<String, String> original = new HashMap<>(props);
        for (Map.Entry<String, String> e : original.entrySet()) {
            final String key = e.getKey();
            final String value = e.getValue();
            try {
                props.put(key, InterpolationHelper.substVars(value, key, null, props, new InterpolationHelper.SubstitutionCallback() {

                    public String getValue(String toSubstitute) {
                        if (toSubstitute != null && toSubstitute.contains(":")) {
                            String scheme = toSubstitute.substring(0, toSubstitute.indexOf(":"));
                            return resolversSnapshot.get(scheme).resolve(fabricService, mutableConfigurations, pid, key, toSubstitute);
                        }
                        return substituteBundleProperty(toSubstitute, bundleContext);
                    }
                }));
            } catch (EncryptionOperationNotPossibleException exception) {
                LOGGER.warn("Error resolving " + key, exception);
            }
        }
    }
    return mutableConfigurations;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FabricException(io.fabric8.api.FabricException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) FabricService(io.fabric8.api.FabricService) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) PlaceholderResolver(io.fabric8.api.PlaceholderResolver)

Example 12 with EncryptionOperationNotPossibleException

use of org.jasypt.exceptions.EncryptionOperationNotPossibleException in project cloudbreak by hortonworks.

the class EncryptedStringConfig method register.

@PostConstruct
public void register() {
    HibernatePBEEncryptorRegistry registry = HibernatePBEEncryptorRegistry.getInstance();
    registry.registerPBEStringEncryptor("hibernateStringEncryptor", new PBEStringEncryptor() {

        @Override
        public String encrypt(String message) {
            StringEncryptor encryptor = (StringEncryptor) applicationContext.getBean("PBEStringCleanablePasswordEncryptor");
            return encryptor.encrypt(message);
        }

        @Override
        public String decrypt(String encryptedMessage) {
            StringEncryptor encryptor = (StringEncryptor) applicationContext.getBean("PBEStringCleanablePasswordEncryptor");
            try {
                return encryptor.decrypt(encryptedMessage);
            } catch (EncryptionOperationNotPossibleException e) {
                StringEncryptor legacyEncryptor = (StringEncryptor) applicationContext.getBean("LegacyPBEStringCleanablePasswordEncryptor");
                try {
                    return legacyEncryptor.decrypt(encryptedMessage);
                } catch (EncryptionOperationNotPossibleException ignored) {
                    return encryptedMessage;
                }
            }
        }

        @Override
        public void setPassword(String password) {
        }
    });
}
Also used : EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) PBEStringEncryptor(org.jasypt.encryption.pbe.PBEStringEncryptor) PBEStringEncryptor(org.jasypt.encryption.pbe.PBEStringEncryptor) StringEncryptor(org.jasypt.encryption.StringEncryptor) HibernatePBEEncryptorRegistry(org.jasypt.hibernate4.encryptor.HibernatePBEEncryptorRegistry) PostConstruct(javax.annotation.PostConstruct)

Example 13 with EncryptionOperationNotPossibleException

use of org.jasypt.exceptions.EncryptionOperationNotPossibleException in project simba-os by cegeka.

the class DatabaseLoginModule method verifyLoginData.

@Override
protected boolean verifyLoginData() throws FailedLoginException {
    debug("Verifying credentials for user: " + getUsername());
    boolean validCredentials = false;
    try {
        validCredentials = credentialService.checkCredentials(getUsername(), getPassword());
    } catch (EncryptionOperationNotPossibleException legacyPasswordException) {
        debug("Authentication failed");
        throw new FailedLoginException(getUsername());
    }
    if (validCredentials) {
        debug("Authentication succeeded");
        return true;
    }
    debug("Authentication failed");
    throw new FailedLoginException(getUsername());
}
Also used : FailedLoginException(javax.security.auth.login.FailedLoginException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException)

Aggregations

EncryptionOperationNotPossibleException (org.jasypt.exceptions.EncryptionOperationNotPossibleException)13 IOException (java.io.IOException)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 SQLException (java.sql.SQLException)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 FabricException (io.fabric8.api.FabricException)2 BufferedWriter (java.io.BufferedWriter)2 FileNotFoundException (java.io.FileNotFoundException)2 FileWriter (java.io.FileWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Properties (java.util.Properties)2 FailedLoginException (javax.security.auth.login.FailedLoginException)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)2 StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)2 EncryptableProperties (org.jasypt.properties.EncryptableProperties)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 FabricService (io.fabric8.api.FabricService)1