Provided sys-logging provider to enable keycloak events remote logging.
This commit is contained in:
parent
1d8ebd441d
commit
30a36498c9
6 changed files with 168 additions and 1 deletions
|
@ -20,6 +20,7 @@
|
||||||
<module>email</module>
|
<module>email</module>
|
||||||
<module>jpa</module>
|
<module>jpa</module>
|
||||||
<module>jboss-logging</module>
|
<module>jboss-logging</module>
|
||||||
|
<module>syslog</module>
|
||||||
<module>mongo</module>
|
<module>mongo</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
||||||
|
|
47
events/syslog/pom.xml
Normal file
47
events/syslog/pom.xml
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<project>
|
||||||
|
<parent>
|
||||||
|
<artifactId>keycloak-events-parent</artifactId>
|
||||||
|
<groupId>org.keycloak</groupId>
|
||||||
|
<version>1.2.0.Beta1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>keycloak-events-syslog</artifactId>
|
||||||
|
<name>Keycloak Events Syslog Provider</name>
|
||||||
|
<description />
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.syslog4j</groupId>
|
||||||
|
<artifactId>syslog4j</artifactId>
|
||||||
|
<version>${syslog4j.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.keycloak</groupId>
|
||||||
|
<artifactId>keycloak-core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.keycloak</groupId>
|
||||||
|
<artifactId>keycloak-model-api</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.keycloak</groupId>
|
||||||
|
<artifactId>keycloak-events-api</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,65 @@
|
||||||
|
package org.keycloak.events.log;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.keycloak.events.Event;
|
||||||
|
import org.keycloak.events.EventListenerProvider;
|
||||||
|
import org.productivity.java.syslog4j.SyslogConstants;
|
||||||
|
import org.productivity.java.syslog4j.SyslogIF;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="mailto:giriraj.sharma27@gmail.com">Giriraj Sharma</a>
|
||||||
|
*/
|
||||||
|
public class SysLoggingEventListenerProvider implements EventListenerProvider {
|
||||||
|
|
||||||
|
private final SyslogIF syslogger;
|
||||||
|
|
||||||
|
public SysLoggingEventListenerProvider(SyslogIF syslogger) {
|
||||||
|
this.syslogger = syslogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(Event event) {
|
||||||
|
int level = event.getError() != null ? SyslogConstants.LEVEL_ERROR : SyslogConstants.LEVEL_INFO;
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append("type=");
|
||||||
|
sb.append(event.getType());
|
||||||
|
sb.append(", realmId=");
|
||||||
|
sb.append(event.getRealmId());
|
||||||
|
sb.append(", clientId=");
|
||||||
|
sb.append(event.getClientId());
|
||||||
|
sb.append(", userId=");
|
||||||
|
sb.append(event.getUserId());
|
||||||
|
sb.append(", ipAddress=");
|
||||||
|
sb.append(event.getIpAddress());
|
||||||
|
|
||||||
|
if (event.getError() != null) {
|
||||||
|
sb.append(", error=");
|
||||||
|
sb.append(event.getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getDetails() != null) {
|
||||||
|
for (Map.Entry<String, String> e : event.getDetails().entrySet()) {
|
||||||
|
sb.append(", ");
|
||||||
|
sb.append(e.getKey());
|
||||||
|
if (e.getValue() == null || e.getValue().indexOf(' ') == -1) {
|
||||||
|
sb.append("=");
|
||||||
|
sb.append(e.getValue());
|
||||||
|
} else {
|
||||||
|
sb.append("='");
|
||||||
|
sb.append(e.getValue());
|
||||||
|
sb.append("'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
syslogger.log(level, sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package org.keycloak.events.log;
|
||||||
|
|
||||||
|
import org.keycloak.Config;
|
||||||
|
import org.keycloak.events.EventListenerProvider;
|
||||||
|
import org.keycloak.events.EventListenerProviderFactory;
|
||||||
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.productivity.java.syslog4j.Syslog;
|
||||||
|
import org.productivity.java.syslog4j.SyslogIF;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="mailto:giriraj.sharma27@gmail.com">Giriraj Sharma</a>
|
||||||
|
*/
|
||||||
|
public class SysLoggingEventListenerProviderFactory implements EventListenerProviderFactory {
|
||||||
|
|
||||||
|
public static final String ID = "sys-logging";
|
||||||
|
|
||||||
|
private SyslogIF syslogger;
|
||||||
|
private String protocol;
|
||||||
|
private String host;
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EventListenerProvider create(KeycloakSession session) {
|
||||||
|
return new SysLoggingEventListenerProvider(syslogger);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(Config.Scope config) {
|
||||||
|
protocol = config.get("protocol");
|
||||||
|
host = config.get("host");
|
||||||
|
port = config.getInt("port");
|
||||||
|
|
||||||
|
syslogger = Syslog.getInstance(protocol);
|
||||||
|
syslogger.getConfig().setHost(host);
|
||||||
|
syslogger.getConfig().setPort(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
org.keycloak.events.log.SysLoggingEventListenerProviderFactory
|
8
pom.xml
8
pom.xml
|
@ -1,5 +1,5 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<name>Keycloak</name>
|
<name>Keycloak</name>
|
||||||
|
@ -25,6 +25,7 @@
|
||||||
<picketbox.ldap.version>1.0.2.Final</picketbox.ldap.version>
|
<picketbox.ldap.version>1.0.2.Final</picketbox.ldap.version>
|
||||||
<mongo.driver.version>2.11.3</mongo.driver.version>
|
<mongo.driver.version>2.11.3</mongo.driver.version>
|
||||||
<jboss.logging.version>3.1.4.GA</jboss.logging.version>
|
<jboss.logging.version>3.1.4.GA</jboss.logging.version>
|
||||||
|
<syslog4j.version>0.9.30</syslog4j.version>
|
||||||
<jboss-logging-tools.version>1.2.0.Beta1</jboss-logging-tools.version>
|
<jboss-logging-tools.version>1.2.0.Beta1</jboss-logging-tools.version>
|
||||||
<hibernate.javax.persistence.version>1.0.1.Final</hibernate.javax.persistence.version>
|
<hibernate.javax.persistence.version>1.0.1.Final</hibernate.javax.persistence.version>
|
||||||
<hibernate.entitymanager.version>4.0.1.Final</hibernate.entitymanager.version>
|
<hibernate.entitymanager.version>4.0.1.Final</hibernate.entitymanager.version>
|
||||||
|
@ -316,6 +317,11 @@
|
||||||
<artifactId>jboss-logging</artifactId>
|
<artifactId>jboss-logging</artifactId>
|
||||||
<version>${jboss.logging.version}</version>
|
<version>${jboss.logging.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.syslog4j</groupId>
|
||||||
|
<artifactId>syslog4j</artifactId>
|
||||||
|
<version>${syslog4j.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
|
|
Loading…
Reference in a new issue