How to override osgi config for OOTB component partially? - java

I want to override standart osgi cq component configuration for
com.adobe.granite.ui.clientlibs.impl.HtmlLibraryManagerImpl.xml
Default configuration is fine for me but I want to change only one option.
I don't want to override full configuration but override only single option(minify should be set as false) .

As per the documentation, it should be fine to create a configuration node & only override the value that you wish to change:
For each parameter that you want to configure create a property on
this node:
Name: the parameter name as shown in the Felix Console; the name is
shown in brackets at the end of the field description. For example,
for Create Version on Activation use
versionmanager.createVersionOnActivation
Type: as appropriate.
Value:
as required.
You only need to create properties for the parameters that you want to configure, others will still take the default values as set by CQ. [emphasis mine]
Just make sure not to override values with blank defaults, e.g.:
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
cq.homeaclsetup.privileges.user="jcr:all"/>
Should leave the cq.homeaclsetup.privileges.group value at its default, as it hasn't been included in the config node at all.
As far as I'm aware though, it will choose the default value for the component, rather than the default value for AEM — there could be an out-of-the-box OSGi config node in the libs/ folder that you may override, so be careful of this.
In that case, you'd need to copy config into your node so that it is not lost.

Create a node named "com.adobe.granite.ui.clientlibs.impl.HtmlLibraryManagerImpl" under /apps/system/config and make changes as you need

Related

Can you override a library's Spring property placeholders?

We are working on moving our application to use only Spring-Boot application.properties files. The old way we were doing was that each library/dependency would have their properties stored in a dedicated properties file like res/environment/some-library-override.properties. The values would then be retrieved in the library using #Value("$some-library-{PROPERTY_NAME}").
However, since moving all of these override properties to dedicated application.properties files, it is no longer resolving the properties and we get errors like java.lang.NumberFormatException: For input string: "$some-library-{PROPERTY_NAME}".
I assume this is because it is still expecting the property to be in that dedicated properties file.
Is there a solution to this that doesn't involve modifying the library/dependency? Is it possible to have it ignore the prefix and only look for the PROPERTY_NAME in the application.properties files?
if you have declared propertie var likeproperty.name=XXXX or added environment var like PROPERTY_NAME=XXXX.
you need to use this way
#Value("some-library-${property.name}")
// will inject value "some-library" + "XXXX"

merging multiple levels of configuration using typesafe/akka config

I'm looking at:
https://github.com/typesafehub/config
Let's say I want to have a default configuration, e.g. reference.conf, and then I want to have dev/prod overrides (two different application.conf's), and then I also wanted to have host-specific overrides that inherited from both the application.conf and ultimately the default reference.conf. How would I do this?
e.g., I'm imagining a directory structure something like:
resources/reference.conf
resources/prod/application.conf
resources/prod/master.conf
resources/prod/slave.conf
resources/dev/application.conf
resources/dev/master.conf
resources/dev/slave.conf
Or maybe it would be resources/dev/master/application.conf?
Somewhere I would specify an environment, i.e. maybe extracted from the hostname the application was started on.
If the application was master.dev.example.com, I'm expecting I should be able to do something like:
getConfigurations("dev/master.conf").withDefaultsFrom(
getConfigurations("dev/application.conf").withDefaultsFrom(
getConfigurations("resource.conf"))
But I'm having a hard time understanding what exactly that would look like using the given library.
I see I could set a config.resource system property, but it looks like that would only allow for one level of overrides, dev-application.conf -> resources.conf, not something like master-node.conf -> dev-application.conf -> resources.conf.
I see a .withFallback method, but that seems to be if I wanted to mix two kinds of configuration in a single file, not to chain resources/files together.
Use multiple withFallback with the configs that have the highest priority first. For example:
Config finalConfig =
ConfigFactory.systemProperties().
withFallback(masterConfig).
withFallback(applicationConfig).
withFallback(referenceConfig)
Each of the configs like masterConfig would have been loaded with Config.parseFile. You can also use ConfigFactor.load as a convenience, but the parseXXX methods give you more control over your hierarchy.

Overriding dependencies property value in Spring

In my Spring project I am using a dependency project developed in Spring. This dependency has its own properties file and have defined a property which points to localhost. Now in my setup, I want this property to be pointing to another URL but not localhost. I am trying to override this in my properties file using addFirst method of property sources, but the dependency still loads the original property value.
ConfigurableEnvironment environment = applicationContext.getEnvironment();
//here i overload the props
environment.getPropertySources().addFirst(
new ResourcePropertySource("classpath:conf/app.properties"));
LOG.debug("dependency property: " + applicationContext.getEnvironment().
getProperty("server.hostname")); // here it prints the overloaded value in app.properties
When I print the overloaded property I get the overloaded property value, but when the program gets executed it points to localhost. Is this the way to override dependent properties ? Spring version is 3.2
The point is, that in the ProperySources the last one wins.
(Its like in a Database, the last one that writes wins).
Try to use simply add.

Set a Java Security Property to null

I have seen that one can null (or clear) a System property by using System.clearProperty("propertyName"). However, I am unable to locate a similar mechanism for Security.
How does one perform the equivalent of Security.clearProperty("propertyName")?
Obviously, using Security.setProperty("propertyName", null) does not work for the same reasons it does not work for System.setProperty("propertyName", null).
I would like to do this as there are optional security properties that may not be updated when required properties are changed. I would like the optional properties to reset to their default values when a change is made to the required properties.
Apologies having re-looked into this I believe
System.clearProperty
will not work for security properties. I'm not sure how to do it programmatically however you can create a new security policy file with your required settings within it and use that:
Djava.security.manager -Djava.security.policy=/path/to/new/policy_file

How to Change init-parameters at Runtime?

If I modify the XML to change the value of init parameter
I see the changes only when web-app is redeployed.
My question is cant I get around this by setting the values at run time.Is there any API that allow me to change the values dynamically.
It's called init-parameter for a reason. So, you can't.
But you can change values at runtime, that's no problem.
After reading the init parameters put them as attributes of the ServletContext (ctx.setAttribute("name", value))
Create a small (password-protected) page that lists all attributes of the ServletContext and gives the ability to change them.
Maybe you could use apache commons configuration, specifically have a look at Automatic Reloading...
Make use of properties files instead and write code so that it 1) reads the value from it everytime, or 2) can reload the value on command, or 3) reloads the file automatically at certain intervals.
If you put the properties file somewhere in the webapp's runtime classpath or add its path to the webapp's runtime classpath, then you can easily access/load it as follows:
Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("filename.properties"));
String value = properties.get("key");

Categories