use of io.fabric8.api.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);
}
}
}
use of io.fabric8.api.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);
}
use of io.fabric8.api.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);
}
use of io.fabric8.api.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);
}
use of io.fabric8.api.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);
}
Aggregations