Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Keycloak) Freemarker Template system properties and environment variables

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?

like image 484
Arved Avatar asked Oct 23 '25 22:10

Arved


2 Answers

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}
like image 52
Rin malavi Avatar answered Oct 26 '25 19:10

Rin malavi


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><a href="${properties.UATURL}">${kcSanitize(msg("backToLogin"))?no_esc}</a></span>
like image 37
user15924497 Avatar answered Oct 26 '25 20:10

user15924497



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!