We wanted to work on the Templates and tried to get the system properties that we set earlier in the standalone.xml file like this.
</extensions>
<system-properties>
<property name="testProp" value="TestVal"/>
</system-properties>
In the Docs of Keycloak its described like the following.
${some.system.property} - for system properties
${env.ENV_VAR} - for environment variables.
But nothing worked for us. We always get the following error Message “An internal server error has occurred”.
What is the right way to get the system properties and the environment variables in the Freemarker Template?
Keycloak Theme Property Documentation
is missing how to add them in the template.
It is however just a bit lower in the same document
So in theme.properties could be
customPropInThemeProperties=${env.SOME_OTHER_RESOURCE_URL}
Then uses in .ftl as
${properties.customPropInThemeProperties}
In order to use system properties in the freemarker template of keycloak, do the following configuration.
Declare your system properties in the standalone.xml
<system-properties>
<property name="UATLogin" value="http://localhost:9090" />
</system-properties>
Add variable inside theme.properties to access the system property.
UATURL=${UATLogin}
As an example, I have done the testing with register.ftl
<span>${kcSanitize(msg("backToLogin"))?no_esc}</span>
Related
I have added system-properties tag in standalone-full.xml, but its not working in standalone mode. However, if I add the same tag in domain.xml it's working for domain mode.
<?xml version='1.0' encoding='UTF-8'?>
<server xmlns="urn:jboss:domain:2.2">
<extensions>
....
</extensions>
<system-properties>
<property name="java.util.Arrays.useLegacyMergeSort" value="true"/>
</system-properties>
</server>
According to this article on jBoss General configuration concepts
System property values can be set in a number of places in domain.xml, host.xml and standalone.xml.
Then what about standalone-full.xml?
I don't want to set it through command line and not even in java code.
In standalone it's probably too late to set it in the configuration files. You'll need to add it to the standalone.conf or standalone.conf.bat in the JAVA_OPTS environment variable. A global property like that needs to be set before anything else attempts to use java.util.Arrays.
If you have started the Wildfly server with standalone-full.xml instead of standalone.xml(the default) than this should be reflected in the start of the server:
standalone.sh -b <hostIP> -c standalone-full.xml -Dorg...
Then this will have effect on first start.
If you change something in this config file, you will need to reload Wildfly(configuration) from jboss cli:
[standalone#localhost:9990 /] :reload
For Wildfly 10 it's working nontheless. I was able to read the property for an instance started with the standalone-full.xml containing some properties.
The manual must be outdated then I guess? Because even Wildfly itself inserts a new property in the standalone-full.xml when using the Wildfly admin webinterface: http://localhost:9990 > Configuration > System Properties (Wildfly will add the property of course to the xml config which was used to start the instance). That's enough proof for me.
I'm using log4j2 and have a rolling file configured in log4j2.xml as
<RollingFile name="a2.log" append="true"
fileName="C:/Dev/error_log/local_error_log_app_name.log"
filePattern="C:/Dev/error_log/local_error_log_app_name_-%d{MM-dd-yyyy}-%i.txt.gz">
This is good for local Eclipse Development but when I deploy to a JBOSS server I'd like the path and filename to be appropriate for that file system, without having to remember to edit the log4j2.xml file before deploying.
fileName="/www/logs/error_log/error_log_app_name.log"
I've seen the following posts
How to give dynamic file name in the appender in log4j.xml
Log4J2 - assigning file appender filename at runtime
and tried
fileName="$${sys:logFilename}" and fileName="${sys:logFilename}" but all that did was put a file ${sys in the Jboss bin folder `jboss-as-7.1.1.Final\bin'
Have you tried declaring a property in your config file?
The log4j2 docs have an example here:
http://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution
If this does not work, please raise a ticket in the log4j2 issue tracker:
https://issues.apache.org/jira/browse/LOG4J2
When declaring a property in log4j2.xml, use double dollar signs $$
<Properties>
<Property name="filenameVariable">$${sys:errorLogFileName}</Property>
<Property name="filePatternVariable">$${sys:errorLogFilePattern}</Property>
</Properties>
and reference using single dollar sign $
<RollingFile name="a2.log" append="true"
fileName="${filename}"
filePattern="${filePattern}">
However it is not necessary to use a property. Just reference the system property directly, again with just single dollar sign
<RollingFile name="a2.log" append="true"
fileName="${sys:errorLogFileName}"
filePattern="${sys:errorLogFilePattern}">
And to the answer to my actual issue how to dynamically specify log file based on whether I am running locally in Eclipse or deployed to our server, I'm using
#Singleton
#Startup
public class StartupBean {
#PostConstruct
private void startup() {
if (File("C:/").exists()) {
System.setProperty("errorLogFileName", "C:/path/to/error_log.txt");
System.setProperty("errorLogFilePattern", "C:/path/to/error_log-%d{MM-dd-yyyy}-%i.txt.gz");
} else {
System.setProperty("errorLogFileName", "/unix/path/to/error_log.txt");
System.setProperty("errorLogFilePattern", "/unix/path/to/error_log-%d{MM-dd-yyyy}-%i.txt.gz");
}
}
}
Important! Without a system property set System.setProperty("whatever") the lookup in your log4j2.xml will fail and instead log4j will write to a file named as the first part of your lookup before the semicolon i.e. ${sys
Can I dump a properties file somewhere in one of the JBoss 6 directories, and pick it up from the classpath?
Or even better, does anybody know the mechanism behind a configuration file like $JBOSS_HOME/server/default/deploy/jboss-logging.xml? Changes to this file seem to trigger an event, so that a running instance can process the modifications (without having to bounce the AS).
A possibility is to configure SystemPropertiesService in ./conf/jboss-service.xml.
This allows you to configure system properties in-place, or load them from a properties file:
<server>
<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss.util:type=Service,name=SystemProperties">
<!-- Load properties from each of the given comma seperated URLs -->
<attribute name="URLList">
http://somehost/some-location.properties,
./conf/somelocal.properties
</attribute>
<!-- Set propertuies using the properties file style. -->
<attribute name="Properties">
property1=This is the value of my property
property2=This is the value of my other property
</attribute>
</mbean>
</server>
For more details, refer to: http://docs.jboss.org/jbossas/admindevel326/html/ch10.html
They have made this even easier in JBoss EAP 6 (AS 7).
Pass Property File as Startup Parameter
This can be added within the main start up script or passed as parameter
./standalone.sh --properties=/Users/john.galt/dev/config/ds/jboss.properties
If these properties are read, they will be rendered in the server log as the first statement.
3:58:41,633 DEBUG [org.jboss.as.config] (MSC service thread 1-6) Configured system properties:
DSsettings.password = password
DSsettings.user-name = admin
DSsettings.connection-url = jdbc:oracle:fat:#activedb:1521:DEV
[Standalone] =
awt.nativeDoubleBuffering = true
NOTE: As these settings are logged in server log, ensure no clear text passwords are in the property files in production
Use passed in system properties
You could use these system properties with following syntax.
Example Usage in a data source file
<xa-datasource jndi-name="java:jboss/ds" pool-name="cPool" jta="true" enabled="true" use-ccm="true">
<xa-datasource-property name="URL">
${DSsettings.connection_url}
</xa-datasource-property>
<driver>oracle</driver>
...
<security>
<user-name>${DSsettings.user-name}</user-name>
<password>${DSsettings.password}</password>
</security>
...
</xa-datasource>
In JBoss 6 use: ./deploy/properties-service.xml
On JBoss AS7 properties-service.xml no longer exist, the below is the solution:
http://www.mastertheboss.com/jboss-server/jboss-configuration/how-to-inject-system-properties-into-jboss
I try to define environment entries in JBoss 5.1 and added following to the server/default/deploy/jbossweb.sar/context.xml file:
<Environment type="java.lang.String" name="name" value="value" />
Following error occurs on startup:
2010-01-26 14:50:08,383 ERROR
[org.jboss.web.tomcat.service.deployers.JBossContextConfig]
(main) XML error parsing: context.xml
org.jboss.xb.binding.JBossXBException:
Failed to parse source: Resource
cannot appear in this position.
Expected content of Context is
unordered_sequence: attributes?
InstanceListener* Realm? Parameters*
Manager? Loader? Valve* SessionCookie?
Resources? Listener*
Where may I define environment entries in JBoss (but outside of application's EAR)?
This article confirms that (likely) it is not possible to configure environment entries in JBoss. Author suggests to use PropertiesService as alternative.
Property configuration in properties-service.xml works great!
Is it possible to configure JBoss 5.x to use jboss-log4j.xml located outside from JBOSS_HOME?
If yes - what should be changed?
The conf/jboss-service.xml file contains the reference to jboss-log4j.xml:
<mbean code="org.jboss.logging.Log4jService"
name="jboss.system:type=Log4jService,service=Logging"
xmbean-dd="resource:xmdesc/Log4jService-xmbean.xml">
<attribute name="ConfigurationURL">resource:jboss-log4j.xml</attribute>
I'm not sure what resource:jboss-log4j.xml means, exactly, but ConfigurationURL sounds like something you could pass in a file://-style URL to, specifying an external log4j file.