Merge branch 'girirajsharma-master'

This commit is contained in:
Stian Thorgersen 2015-02-04 09:03:02 +01:00
commit 27d4a33226
6 changed files with 167 additions and 0 deletions

View file

@ -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
View 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>

View file

@ -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() {
}
}

View file

@ -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 = "syslog";
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;
}
}

View file

@ -0,0 +1 @@
org.keycloak.events.log.SysLoggingEventListenerProviderFactory

View file

@ -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>