如何获得Keycloak 4.5.0.Final才能登录JSON格式?
我正在使用Helm chart在Kubernetes中运行Keycloak,它提供了用于运行JBoss CLI脚本(keycloak.cli.custom
)或shell脚本(keycloak.preStartScript
)的钩子。
但是我想避免不得不自定义Docker映像。
答案 0 :(得分:0)
遵循这一出色的article(也链接到Github),可以按照以下步骤获得JSON日志:
deployments
文件夹中(请阅读本文以获取完整的详细信息)最终代码可能如下所示:
public class MyEventListenerProvider implements EventListenerProvider {
public MyEventListenerProvider() {
// use c'tor to init variables / connections / etc. - plugin load hook
this.jsonMapper = new ObjectMapper();
}
ObjectMapper jsonMapper;
private stringify(Object obj) {
try {
return this.jsonMapper.writeValueAsString(obj);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
@Override
public void onEvent(Event event) {
System.out.println(this.stringify(event));
}
@Override
public void onEvent(AdminEvent adminEvent, boolean b) {
System.out.println(this.stringify(adminEvent));
}
@Override
public void close() {
// use close to close connections / reset variables - plugin unload hook
}
该示例是即时编写的(部分编写,如果出现编译错误,抱歉),并按照here
的说明使用Jackson的库答案 1 :(得分:0)
我正在使用keycloak 8.0.1,所以这可能不适用于您的4.5版本,但我要做的就是提供一个jboss cli脚本以使用json格式器而不是PATTERN格式器
# Undertow HTTP Server Configuration
echo Started configuring Undertow ....
# Create a new log formatter to output json with full stacktrace details
/subsystem=logging/json-formatter=SUMO_FORMATTER:add(pretty-print=false, exception-output-type=detailed-and-formatted, print-details=false)
# Disable the original console output that was in plain text format
/subsystem=logging/console-handler=CONSOLE/:write-attribute(name=enabled,value=false)
# Create a new console logger that uses the new json formatter
/subsystem=logging/console-handler=SUMO_CONSOLE:add(enabled=true, named-formatter=SUMO_FORMATTER)
# Make the root logger use the new console logger
/subsystem=logging/root-logger=ROOT/:write-attribute(name=handlers,value=["SUMO_CONSOLE"])
echo ... Completed configuring Undertow
这里有一些doco