Search in sources :

Example 1 with PlaceholderResolver

use of io.fabric8.karaf.core.properties.PlaceholderResolver in project fabric8 by jboss-fuse.

the class EncryptedPropertyResolver method initialize.

/**
 * When {@link FabricService} becomes available, we can initialize this {@link PlaceholderResolver}
 * @param fabricService
 */
public void initialize(FabricService fabricService) {
    this.fabricService = fabricService;
    encryptor = getEncryptor(fabricService);
    if (bundleContext != null) {
        seRegistration = bundleContext.registerService(PBEStringEncryptor.class, encryptor, null);
        BundleContext context = FrameworkUtil.getBundle(PersistenceManager.class).getBundleContext();
        encryptingPersistenceManager = new EncryptingPersistenceManager(context, context.getProperty(ConfigurationManager.CM_CONFIG_DIR), encryptor);
        originalPersistenceManager = inject(configAdmin, encryptingPersistenceManager);
        passwordNodeCache = new NodeCacheExtended(fabricService.adapt(CuratorFramework.class), AUTHENTICATION_CRYPT_PASSWORD.getPath());
        passwordNodeCache.getListenable().addListener(this);
        alogrithmNodeCache = new NodeCacheExtended(fabricService.adapt(CuratorFramework.class), AUTHENTICATION_CRYPT_ALGORITHM.getPath());
        alogrithmNodeCache.getListenable().addListener(this);
        try {
            passwordNodeCache.start();
            alogrithmNodeCache.start();
        } catch (Exception e) {
            throw new FabricException(e);
        }
    }
}
Also used : NodeCacheExtended(org.apache.curator.framework.recipes.cache.NodeCacheExtended) EncryptingPersistenceManager(org.apache.felix.cm.file.EncryptingPersistenceManager) PersistenceManager(org.apache.felix.cm.PersistenceManager) FabricException(io.fabric8.api.FabricException) PBEStringEncryptor(org.jasypt.encryption.pbe.PBEStringEncryptor) StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) EncryptingPersistenceManager(org.apache.felix.cm.file.EncryptingPersistenceManager) FabricException(io.fabric8.api.FabricException) IOException(java.io.IOException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) BundleContext(org.osgi.framework.BundleContext)

Example 2 with PlaceholderResolver

use of io.fabric8.karaf.core.properties.PlaceholderResolver in project fabric8 by jboss-fuse.

the class ContainerPlaceholderResolverTest method testResolveAttributeCase.

@Test
public void testResolveAttributeCase() throws Exception {
    PlaceholderResolver resolver = getContainerPlaceholderResolver();
    assertEquals(ip, resolver.resolve(fabricService, null, null, null, "container:root/IP"));
    assertEquals(localhostname, resolver.resolve(fabricService, null, null, null, "container:root/LocalHostName"));
    assertEquals(bindaddress, resolver.resolve(fabricService, null, null, null, "container:root/Bindaddress"));
    assertEquals(containerResolver, resolver.resolve(fabricService, null, null, null, "container:root/Resolver"));
    verify(fabricService);
    verify(dataStore);
}
Also used : PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Example 3 with PlaceholderResolver

use of io.fabric8.karaf.core.properties.PlaceholderResolver in project fabric8 by jboss-fuse.

the class ContainerPlaceholderResolverTest method testResolveCurrentName.

@Test
@Ignore("[FABRIC-1110] Mocked test makes invalid assumption on the implementation")
public void testResolveCurrentName() throws Exception {
    final FabricService fabricService = createMock(FabricService.class);
    final DataStore dataStore = createMock(DataStore.class);
    expect(fabricService.getCurrentContainerName()).andReturn("root").anyTimes();
    expect(fabricService.getContainer(EasyMock.<String>anyObject())).andReturn(new ContainerImpl(null, "root", fabricService));
    replay(fabricService);
    replay(dataStore);
    PlaceholderResolver resolver = getContainerPlaceholderResolver();
    assertEquals("root", resolver.resolve(fabricService, null, null, null, "container:name"));
    verify(fabricService);
    verify(dataStore);
}
Also used : FabricService(io.fabric8.api.FabricService) ContainerImpl(io.fabric8.internal.ContainerImpl) DataStore(io.fabric8.api.DataStore) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with PlaceholderResolver

use of io.fabric8.karaf.core.properties.PlaceholderResolver in project fabric8 by jboss-fuse.

the class EncryptedPropertyResolverTest method testResolve.

@Test
public void testResolve() throws Exception {
    CuratorFramework curator = createMock(CuratorFramework.class);
    GetDataBuilder getDataBuilder = createMock(GetDataBuilder.class);
    expect(curator.getData()).andReturn(getDataBuilder).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_ALGORITHM.getPath())).andReturn("PBEWithMD5AndDES".getBytes()).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_PASSWORD.getPath())).andReturn("mypassword".getBytes()).anyTimes();
    replay(curator);
    replay(getDataBuilder);
    FabricService fabricService = createMock(FabricService.class);
    expect(fabricService.adapt(CuratorFramework.class)).andReturn(curator).anyTimes();
    replay(fabricService);
    PlaceholderResolver resolver = getEncryptedPropertyResolver();
    assertEquals("encryptedpassword", resolver.resolve(fabricService, null, null, null, "crypt:URdoo9++D3tsoC9ODrTfLNK5WzviknO3Ig6qbI2HuvQ="));
    verify(curator);
    verify(getDataBuilder);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) FabricService(io.fabric8.api.FabricService) GetDataBuilder(org.apache.curator.framework.api.GetDataBuilder) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Example 5 with PlaceholderResolver

use of io.fabric8.karaf.core.properties.PlaceholderResolver in project fabric8 by jboss-fuse.

the class EncryptedPropertyResolverTest method testResolveZkEnc.

@Test
public void testResolveZkEnc() throws Exception {
    CuratorFramework curator = createMock(CuratorFramework.class);
    GetDataBuilder getDataBuilder = createMock(GetDataBuilder.class);
    expect(curator.getData()).andReturn(getDataBuilder).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_ALGORITHM.getPath())).andReturn("PBEWithMD5AndDES".getBytes()).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_PASSWORD.getPath())).andReturn("ZKENC=bXlwYXNzd29yZA==".getBytes()).anyTimes();
    replay(curator);
    replay(getDataBuilder);
    FabricService fabricService = createMock(FabricService.class);
    expect(fabricService.adapt(CuratorFramework.class)).andReturn(curator).anyTimes();
    replay(fabricService);
    PlaceholderResolver resolver = getEncryptedPropertyResolver();
    assertEquals("encryptedpassword", resolver.resolve(fabricService, null, null, null, "crypt:URdoo9++D3tsoC9ODrTfLNK5WzviknO3Ig6qbI2HuvQ="));
    verify(curator);
    verify(getDataBuilder);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) FabricService(io.fabric8.api.FabricService) GetDataBuilder(org.apache.curator.framework.api.GetDataBuilder) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Aggregations

PlaceholderResolver (io.fabric8.api.PlaceholderResolver)7 Test (org.junit.Test)6 FabricService (io.fabric8.api.FabricService)4 FabricException (io.fabric8.api.FabricException)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 GetDataBuilder (org.apache.curator.framework.api.GetDataBuilder)2 EncryptionOperationNotPossibleException (org.jasypt.exceptions.EncryptionOperationNotPossibleException)2 DataStore (io.fabric8.api.DataStore)1 ContainerImpl (io.fabric8.internal.ContainerImpl)1 PlaceholderResolver (io.fabric8.karaf.core.properties.PlaceholderResolver)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 NodeCacheExtended (org.apache.curator.framework.recipes.cache.NodeCacheExtended)1 PersistenceManager (org.apache.felix.cm.PersistenceManager)1 EncryptingPersistenceManager (org.apache.felix.cm.file.EncryptingPersistenceManager)1 PBEStringEncryptor (org.jasypt.encryption.pbe.PBEStringEncryptor)1