【问题标题】:(Keycloak) Freemarker Template system properties and environment variables(Keycloak) Freemarker 模板系统属性和环境变量
【发布时间】:2020-04-03 12:15:37
【问题描述】:

我们想要处理模板并尝试获取我们之前在standalone.xml 文件中设置的系统属性,如下所示。

</extensions>
<system-properties>
    <property name="testProp" value="TestVal"/>
</system-properties>

在 Keycloak 的文档中,它的描述如下。

  • ${some.system.property} - 用于系统属性
  • ${env.ENV_VAR} - 用于环境变量。

但对我们没有任何帮助。我们总是收到以下错误消息“发生内部服务器错误”。 Freemarker模板中获取系统属性和环境变量的正确方法是什么?

【问题讨论】:

  • 我不知道 Keycloak,但如果您提供异常消息和堆栈跟踪(在日志文件中找到它),并且如果错误在模板内,它肯定有助于获得答案,然后是模板的相关部分。

标签: jboss wildfly freemarker keycloak system-properties


【解决方案1】:

Keycloak Theme Property Documentation 缺少如何在模板中添加它们。 不过是just a bit lower in the same document

所以theme.properties 可能是

customPropInThemeProperties=${env.SOME_OTHER_RESOURCE_URL}

然后在.ftl中使用

${properties.customPropInThemeProperties}

【讨论】:

    【解决方案2】:

    为了在keycloak的freemarker模板中使用系统属性,进行如下配置。

    standalone.xml 中声明您的系统属性

    <system-properties>        
            <property name="UATLogin" value="http://localhost:9090" />
    </system-properties>
    

    在 theme.properties 中添加变量以访问系统属性。

       UATURL=${UATLogin}
    

    例如,我用register.ftl做了测试

    <span><a href="${properties.UATURL}">${kcSanitize(msg("backToLogin"))?no_esc}</a></span>
    

    【讨论】:

      猜你喜欢
      • 2011-10-26
      • 2011-02-21
      • 2015-09-16
      • 2012-12-11
      • 2015-03-16
      • 1970-01-01
      • 2019-01-19
      • 2015-09-12
      相关资源
      最近更新 更多