@Test(expected = SeedException.class) public void test_encryption_service_collect_with_wrong_qualifier_class() { prepareMock(); List<KeyPairConfig> keyPairConfigurations = prepareKeyPairWithQualifier( "org.seedstack.seed.core.internal.crypto.fixtures.BadAliasQualifier"); new EncryptionServiceBindingFactory().createBindings(keyPairConfigurations, keyStores); }
Map<Key<EncryptionService>, EncryptionService> createBindings(List<KeyPairConfig> keyPairConfigurations, Map<String, KeyStore> keyStores) { Map<Key<EncryptionService>, EncryptionService> encryptionServices = new HashMap<>(); Map<String, EncryptionServiceFactory> encryptionServiceFactories = new HashMap<>(); if (keyPairConfigurations != null && keyStores != null) { for (KeyPairConfig keyPairConfig : keyPairConfigurations) { String keyStoreName = keyPairConfig.getKeyStoreName(); if (!encryptionServiceFactories.containsKey(keyStoreName)) { EncryptionServiceFactory factory = new EncryptionServiceFactory(keyStores.get(keyStoreName)); encryptionServiceFactories.put(keyStoreName, factory); } EncryptionServiceFactory serviceFactory = encryptionServiceFactories.get(keyStoreName); EncryptionService encryptionService; if (keyPairConfig.getPassword() != null) { encryptionService = serviceFactory.create(keyPairConfig.getAlias(), keyPairConfig.getPassword().toCharArray()); } else { encryptionService = serviceFactory.create(keyPairConfig.getAlias()); } if (keyPairConfig.getQualifier() != null) { encryptionServices.put(createKeyFromQualifier(keyPairConfig.getQualifier()), encryptionService); } else { encryptionServices.put(Key.get(EncryptionService.class, Names.named(keyPairConfig.getAlias())), encryptionService); } } } return encryptionServices; }
EncryptionServiceBindingFactory { Map<Key<EncryptionService>, EncryptionService> createBindings(List<KeyPairConfig> keyPairConfigurations, Map<String, KeyStore> keyStores) { Map<Key<EncryptionService>, EncryptionService> encryptionServices = new HashMap<>(); Map<String, EncryptionServiceFactory> encryptionServiceFactories = new HashMap<>(); if (keyPairConfigurations != null && keyStores != null) { for (KeyPairConfig keyPairConfig : keyPairConfigurations) { String keyStoreName = keyPairConfig.getKeyStoreName(); if (!encryptionServiceFactories.containsKey(keyStoreName)) { EncryptionServiceFactory factory = new EncryptionServiceFactory(keyStores.get(keyStoreName)); encryptionServiceFactories.put(keyStoreName, factory); } EncryptionServiceFactory serviceFactory = encryptionServiceFactories.get(keyStoreName); EncryptionService encryptionService; if (keyPairConfig.getPassword() != null) { encryptionService = serviceFactory.create(keyPairConfig.getAlias(), keyPairConfig.getPassword().toCharArray()); } else { encryptionService = serviceFactory.create(keyPairConfig.getAlias()); } if (keyPairConfig.getQualifier() != null) { encryptionServices.put(createKeyFromQualifier(keyPairConfig.getQualifier()), encryptionService); } else { encryptionServices.put(Key.get(EncryptionService.class, Names.named(keyPairConfig.getAlias())), encryptionService); } } } return encryptionServices; } }
EncryptionServiceBindingFactory { Map<Key<EncryptionService>, EncryptionService> createBindings(List<KeyPairConfig> keyPairConfigurations, Map<String, KeyStore> keyStores) { Map<Key<EncryptionService>, EncryptionService> encryptionServices = new HashMap<>(); Map<String, EncryptionServiceFactory> encryptionServiceFactories = new HashMap<>(); if (keyPairConfigurations != null && keyStores != null) { for (KeyPairConfig keyPairConfig : keyPairConfigurations) { String keyStoreName = keyPairConfig.getKeyStoreName(); if (!encryptionServiceFactories.containsKey(keyStoreName)) { EncryptionServiceFactory factory = new EncryptionServiceFactory(keyStores.get(keyStoreName)); encryptionServiceFactories.put(keyStoreName, factory); } EncryptionServiceFactory serviceFactory = encryptionServiceFactories.get(keyStoreName); EncryptionService encryptionService; if (keyPairConfig.getPassword() != null) { encryptionService = serviceFactory.create(keyPairConfig.getAlias(), keyPairConfig.getPassword().toCharArray()); } else { encryptionService = serviceFactory.create(keyPairConfig.getAlias()); } if (keyPairConfig.getQualifier() != null) { encryptionServices.put(createKeyFromQualifier(keyPairConfig.getQualifier()), encryptionService); } else { encryptionServices.put(Key.get(EncryptionService.class, Names.named(keyPairConfig.getAlias())), encryptionService); } } } return encryptionServices; }  }
EncryptionServiceBindingFactory { Map<Key<EncryptionService>, EncryptionService> createBindings(List<KeyPairConfig> keyPairConfigurations, Map<String, KeyStore> keyStores) { Map<Key<EncryptionService>, EncryptionService> encryptionServices = new HashMap<>(); Map<String, EncryptionServiceFactory> encryptionServiceFactories = new HashMap<>(); if (keyPairConfigurations != null && keyStores != null) { for (KeyPairConfig keyPairConfig : keyPairConfigurations) { String keyStoreName = keyPairConfig.getKeyStoreName(); if (!encryptionServiceFactories.containsKey(keyStoreName)) { EncryptionServiceFactory factory = new EncryptionServiceFactory(keyStores.get(keyStoreName)); encryptionServiceFactories.put(keyStoreName, factory); } EncryptionServiceFactory serviceFactory = encryptionServiceFactories.get(keyStoreName); EncryptionService encryptionService; if (keyPairConfig.getPassword() != null) { encryptionService = serviceFactory.create(keyPairConfig.getAlias(), keyPairConfig.getPassword().toCharArray()); } else { encryptionService = serviceFactory.create(keyPairConfig.getAlias()); } if (keyPairConfig.getQualifier() != null) { encryptionServices.put(createKeyFromQualifier(keyPairConfig.getQualifier()), encryptionService); } else { encryptionServices.put(Key.get(EncryptionService.class, Names.named(keyPairConfig.getAlias())), encryptionService); } } } return encryptionServices; }   }
EncryptionServiceBindingFactory { Map<Key<EncryptionService>, EncryptionService> createBindings(List<KeyPairConfig> keyPairConfigurations, Map<String, KeyStore> keyStores) { Map<Key<EncryptionService>, EncryptionService> encryptionServices = new HashMap<>(); Map<String, EncryptionServiceFactory> encryptionServiceFactories = new HashMap<>(); if (keyPairConfigurations != null && keyStores != null) { for (KeyPairConfig keyPairConfig : keyPairConfigurations) { String keyStoreName = keyPairConfig.getKeyStoreName(); if (!encryptionServiceFactories.containsKey(keyStoreName)) { EncryptionServiceFactory factory = new EncryptionServiceFactory(keyStores.get(keyStoreName)); encryptionServiceFactories.put(keyStoreName, factory); } EncryptionServiceFactory serviceFactory = encryptionServiceFactories.get(keyStoreName); EncryptionService encryptionService; if (keyPairConfig.getPassword() != null) { encryptionService = serviceFactory.create(keyPairConfig.getAlias(), keyPairConfig.getPassword().toCharArray()); } else { encryptionService = serviceFactory.create(keyPairConfig.getAlias()); } if (keyPairConfig.getQualifier() != null) { encryptionServices.put(createKeyFromQualifier(keyPairConfig.getQualifier()), encryptionService); } else { encryptionServices.put(Key.get(EncryptionService.class, Names.named(keyPairConfig.getAlias())), encryptionService); } } } return encryptionServices; }    }