Merge pull request #1107 from stianst/master

Removed admin audit events - needs a rethink
This commit is contained in:
Stian Thorgersen 2015-03-31 18:41:33 +02:00
commit 799c9da1c1
36 changed files with 120 additions and 557 deletions

View file

@ -25,7 +25,6 @@ import org.keycloak.broker.provider.FederatedIdentity;
import org.keycloak.broker.provider.IdentityBrokerException; import org.keycloak.broker.provider.IdentityBrokerException;
import org.keycloak.events.Errors; import org.keycloak.events.Errors;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventGroup;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
import org.keycloak.jose.jws.JWSInput; import org.keycloak.jose.jws.JWSInput;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
@ -88,14 +87,14 @@ public class OIDCIdentityProvider extends AbstractOAuth2IdentityProvider<OIDCIde
UserSessionModel userSession = session.sessions().getUserSession(realm, state); UserSessionModel userSession = session.sessions().getUserSession(realm, state);
if (userSession == null) { if (userSession == null) {
logger.error("no valid user session"); logger.error("no valid user session");
EventBuilder event = new EventBuilder(EventGroup.USER, realm, session, clientConnection); EventBuilder event = new EventBuilder(realm, session, clientConnection);
event.event(EventType.LOGOUT); event.event(EventType.LOGOUT);
event.error(Errors.USER_SESSION_NOT_FOUND); event.error(Errors.USER_SESSION_NOT_FOUND);
return Flows.forwardToSecurityFailurePage(session, realm, uriInfo, headers, Messages.IDENTITY_PROVIDER_UNEXPECTED_ERROR); return Flows.forwardToSecurityFailurePage(session, realm, uriInfo, headers, Messages.IDENTITY_PROVIDER_UNEXPECTED_ERROR);
} }
if (userSession.getState() != UserSessionModel.State.LOGGING_OUT) { if (userSession.getState() != UserSessionModel.State.LOGGING_OUT) {
logger.error("usersession in different state"); logger.error("usersession in different state");
EventBuilder event = new EventBuilder(EventGroup.USER, realm, session, clientConnection); EventBuilder event = new EventBuilder(realm, session, clientConnection);
event.event(EventType.LOGOUT); event.event(EventType.LOGOUT);
event.error(Errors.USER_SESSION_NOT_FOUND); event.error(Errors.USER_SESSION_NOT_FOUND);
return Flows.forwardToSecurityFailurePage(session, realm, uriInfo, headers, Messages.SESSION_NOT_ACTIVE); return Flows.forwardToSecurityFailurePage(session, realm, uriInfo, headers, Messages.SESSION_NOT_ACTIVE);

View file

@ -9,7 +9,6 @@ import org.keycloak.broker.provider.IdentityProvider;
import org.keycloak.events.Details; import org.keycloak.events.Details;
import org.keycloak.events.Errors; import org.keycloak.events.Errors;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventGroup;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
@ -163,7 +162,7 @@ public class SAMLEndpoint {
} }
public Response execute(String samlRequest, String samlResponse, String relayState) { public Response execute(String samlRequest, String samlResponse, String relayState) {
event = new EventBuilder(EventGroup.USER, realm, session, clientConnection); event = new EventBuilder(realm, session, clientConnection);
Response response = basicChecks(samlRequest, samlResponse); Response response = basicChecks(samlRequest, samlResponse);
if (response != null) return response; if (response != null) return response;
if (samlRequest != null) return handleSamlRequest(samlRequest, relayState); if (samlRequest != null) return handleSamlRequest(samlRequest, relayState);

View file

@ -95,10 +95,14 @@ public class MyEventListenerProvider implements EventListenerProvider {
<section> <section>
<title>Register a provider using Modules</title> <title>Register a provider using Modules</title>
<para> <para>
To register a provider using Modules first create a module. To do this you have to create a folder inside To register a provider using Modules first create a module. To do this you can either use the jboss-cli
KEYCLOAK_HOME/modules and add your jar and a <literal>module.xml</literal>. For example to add the event listener script or manually create a folder inside KEYCLOAK_HOME/modules and add your jar and a <literal>module.xml</literal>.
sysout example provider create the folder <literal>KEYCLOAK_HOME/modules/org/keycloak/examples/event-sysout/main</literal>. For example to add the event listener sysout example provider using the jboss-cli script execute:
Copy <literal>event-listener-sysout-example.jar</literal> to this folder and create <literal>module.xml</literal> <programlisting><![CDATA[{
KEYCLOAK_HOME/bin/jboss-cli.sh --command="module add --name=org.keycloak.examples.event-sysout --resources=event-listener-sysout-example.jar"
}]]></programlisting>
Or to manually create it start by creating the folder <literal>KEYCLOAK_HOME/modules/org/keycloak/examples/event-sysout/main</literal>.
Then copy <literal>event-listener-sysout-example.jar</literal> to this folder and create <literal>module.xml</literal>
with the following content: with the following content:
<programlisting><![CDATA[{ <programlisting><![CDATA[{
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
@ -113,8 +117,10 @@ public class MyEventListenerProvider implements EventListenerProvider {
</dependencies> </dependencies>
</module> </module>
}]]></programlisting> }]]></programlisting>
Next you need to register this module with Keycloak. This is done by editing keycloak-server.json and adding </para>
it to the providers: <para>
Once you've created the module you need to register this module with Keycloak. This is done by editing
keycloak-server.json and adding it to the providers:
<programlisting><![CDATA[{ <programlisting><![CDATA[{
"providers": [ "providers": [
... ...

View file

@ -24,9 +24,4 @@ public interface Details {
String NODE_HOST = "node_host"; String NODE_HOST = "node_host";
String REASON = "reason"; String REASON = "reason";
String REALM = "realm";
String REPRESENTATION = "representation";
String APPLICATION_CLUSTER_NODE = "application_cluster_node";
} }

View file

@ -12,8 +12,6 @@ public class Event {
private EventType type; private EventType type;
private EventGroup group;
private String realmId; private String realmId;
private String clientId; private String clientId;
@ -26,8 +24,6 @@ public class Event {
private String error; private String error;
private String representation;
private Map<String, String> details; private Map<String, String> details;
public long getTime() { public long getTime() {
@ -46,14 +42,6 @@ public class Event {
this.type = type; this.type = type;
} }
public EventGroup getGroup() {
return group;
}
public void setGroup(EventGroup group) {
this.group = group;
}
public String getRealmId() { public String getRealmId() {
return realmId; return realmId;
} }
@ -102,14 +90,6 @@ public class Event {
this.error = error; this.error = error;
} }
public String getRepresentation() {
return representation;
}
public void setRepresentation(String representation) {
this.representation = representation;
}
public Map<String, String> getDetails() { public Map<String, String> getDetails() {
return details; return details;
} }
@ -122,7 +102,6 @@ public class Event {
Event clone = new Event(); Event clone = new Event();
clone.time = time; clone.time = time;
clone.type = type; clone.type = type;
clone.group = group;
clone.realmId = realmId; clone.realmId = realmId;
clone.clientId = clientId; clone.clientId = clientId;
clone.userId = userId; clone.userId = userId;
@ -130,7 +109,6 @@ public class Event {
clone.ipAddress = ipAddress; clone.ipAddress = ipAddress;
clone.error = error; clone.error = error;
clone.details = details != null ? new HashMap<>(details) : null; clone.details = details != null ? new HashMap<>(details) : null;
clone.representation = representation;
return clone; return clone;
} }

View file

@ -7,9 +7,7 @@ import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel; import org.keycloak.models.UserModel;
import org.keycloak.models.UserSessionModel; import org.keycloak.models.UserSessionModel;
import org.keycloak.util.JsonSerialization;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -26,11 +24,10 @@ public class EventBuilder {
private RealmModel realm; private RealmModel realm;
private Event event; private Event event;
public EventBuilder(EventGroup group, RealmModel realm, KeycloakSession session, ClientConnection clientConnection) { public EventBuilder(RealmModel realm, KeycloakSession session, ClientConnection clientConnection) {
this.realm = realm; this.realm = realm;
event = new Event(); event = new Event();
event.setGroup(group);
if (realm.isEventsEnabled()) { if (realm.isEventsEnabled()) {
EventStoreProvider store = session.getProvider(EventStoreProvider.class); EventStoreProvider store = session.getProvider(EventStoreProvider.class);
@ -126,18 +123,6 @@ public class EventBuilder {
return this; return this;
} }
public EventBuilder representation(Object value) {
if (value == null || value.equals("")) {
return this;
}
try {
event.setRepresentation(JsonSerialization.writeValueAsPrettyString(value));
} catch (IOException e) {
throw new RuntimeException(e);
}
return this;
}
public EventBuilder removeDetail(String key) { public EventBuilder removeDetail(String key) {
if (event.getDetails() != null) { if (event.getDetails() != null) {
event.getDetails().remove(key); event.getDetails().remove(key);

View file

@ -1,11 +0,0 @@
package org.keycloak.events;
/**
* @author <a href="mailto:giriraj.sharma27@gmail.com">Giriraj Sharma</a>
*/
public enum EventGroup {
ADMIN,
USER
}

View file

@ -60,61 +60,7 @@ public enum EventType {
IDENTITY_PROVIDER_RETRIEVE_TOKEN(false), IDENTITY_PROVIDER_RETRIEVE_TOKEN(false),
IDENTITY_PROVIDER_RETRIEVE_TOKEN_ERROR(false), IDENTITY_PROVIDER_RETRIEVE_TOKEN_ERROR(false),
IDENTITY_PROVIDER_ACCCOUNT_LINKING(false), IDENTITY_PROVIDER_ACCCOUNT_LINKING(false),
IDENTITY_PROVIDER_ACCCOUNT_LINKING_ERROR(false), IDENTITY_PROVIDER_ACCCOUNT_LINKING_ERROR(false);
VIEW_REALM(false),
CREATE_REALM(false),
UPDATE_REALM(false),
DELETE_REALM(false),
VIEW_APPLICATIONS(false),
VIEW_APPLICATION(false),
CREATE_APPLICATION(false),
UPDATE_APPLICATION(false),
DELETE_APPLICATION(false),
VIEW_APPLICATION_USER_SESSIONS(false),
LOGOUT_APPLICATION_USERS(false),
LOGOUT_USER(false),
REGISTER_APPLICATION_CLUSTER_NODE(false),
UNREGISTER_APPLICATION_CLUSTER_NODE(false),
VIEW_CLIENT_CERTIFICATE(false),
UPDATE_CLIENT_CERTIFICATE(false),
VIEW_IDENTITY_PROVIDERS(false),
VIEW_IDENTITY_PROVIDER(false),
CREATE_IDENTITY_PROVIDER(false),
UPDATE_IDENTITY_PROVIDER(false),
DELETE_IDENTITY_PROVIDER(false),
VIEW_OAUTH_CLIENTS(false),
VIEW_OAUTH_CLIENT(false),
CREATE_OAUTH_CLIENT(false),
UPDATE_OAUTH_CLIENT(false),
DELETE_OAUTH_CLIENT(false),
VIEW_ROLES(false),
VIEW_ROLE(false),
CREATE_ROLE(false),
UPDATE_ROLE(false),
DELETE_ROLE(false),
VIEW_USERS(false),
VIEW_USER(false),
CREATE_USER(false),
UPDATE_USER(false),
DELETE_USER(false),
VIEW_USER_SESSIONS(false),
LOGOUT_USER_SESSIONS(false),
VIEW_FEDERATION_PROVIDERS(false),
VIEW_FEDERATION_PROVIDER(false),
CREATE_FEDERATION_PROVIDER(false),
UPDATE_FEDERATION_PROVIDER(false),
DELETE_FEDERATION_PROVIDER(false);
private boolean saveByDefault; private boolean saveByDefault;

View file

@ -23,9 +23,6 @@ public class EventEntity {
@Column(name="TYPE") @Column(name="TYPE")
private String type; private String type;
@Column(name="EVENT_GROUP")
private String group;
@Column(name="REALM_ID") @Column(name="REALM_ID")
private String realmId; private String realmId;
@ -47,10 +44,6 @@ public class EventEntity {
@Column(name="DETAILS_JSON", length = 2550) @Column(name="DETAILS_JSON", length = 2550)
private String detailsJson; private String detailsJson;
@Column(name="REPRESENTATION")
@Lob
private String representation;
public String getId() { public String getId() {
return id; return id;
} }
@ -75,14 +68,6 @@ public class EventEntity {
this.type = type; this.type = type;
} }
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public String getRealmId() { public String getRealmId() {
return realmId; return realmId;
} }
@ -139,11 +124,4 @@ public class EventEntity {
this.detailsJson = detailsJson; this.detailsJson = detailsJson;
} }
public String getRepresentation() {
return representation;
}
public void setRepresentation(String representation) {
this.representation = representation;
}
} }

View file

@ -4,13 +4,11 @@ import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference; import org.codehaus.jackson.type.TypeReference;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.keycloak.events.Event; import org.keycloak.events.Event;
import org.keycloak.events.EventGroup;
import org.keycloak.events.EventQuery; import org.keycloak.events.EventQuery;
import org.keycloak.events.EventStoreProvider; import org.keycloak.events.EventStoreProvider;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -65,14 +63,12 @@ public class JpaEventStoreProvider implements EventStoreProvider {
e.setId(UUID.randomUUID().toString()); e.setId(UUID.randomUUID().toString());
e.setTime(o.getTime()); e.setTime(o.getTime());
e.setType(o.getType().toString()); e.setType(o.getType().toString());
e.setGroup(o.getGroup().toString());
e.setRealmId(o.getRealmId()); e.setRealmId(o.getRealmId());
e.setClientId(o.getClientId()); e.setClientId(o.getClientId());
e.setUserId(o.getUserId()); e.setUserId(o.getUserId());
e.setSessionId(o.getSessionId()); e.setSessionId(o.getSessionId());
e.setIpAddress(o.getIpAddress()); e.setIpAddress(o.getIpAddress());
e.setError(o.getError()); e.setError(o.getError());
e.setRepresentation(o.getRepresentation());
try { try {
e.setDetailsJson(mapper.writeValueAsString(o.getDetails())); e.setDetailsJson(mapper.writeValueAsString(o.getDetails()));
} catch (IOException ex) { } catch (IOException ex) {
@ -85,14 +81,12 @@ public class JpaEventStoreProvider implements EventStoreProvider {
Event e = new Event(); Event e = new Event();
e.setTime(o.getTime()); e.setTime(o.getTime());
e.setType(EventType.valueOf(o.getType())); e.setType(EventType.valueOf(o.getType()));
e.setGroup(EventGroup.valueOf(o.getGroup()));
e.setRealmId(o.getRealmId()); e.setRealmId(o.getRealmId());
e.setClientId(o.getClientId()); e.setClientId(o.getClientId());
e.setUserId(o.getUserId()); e.setUserId(o.getUserId());
e.setSessionId(o.getSessionId()); e.setSessionId(o.getSessionId());
e.setIpAddress(o.getIpAddress()); e.setIpAddress(o.getIpAddress());
e.setError(o.getError()); e.setError(o.getError());
e.setRepresentation(o.getRepresentation());
try { try {
Map<String, String> details = mapper.readValue(o.getDetailsJson(), mapType); Map<String, String> details = mapper.readValue(o.getDetailsJson(), mapType);
e.setDetails(details); e.setDetails(details);

View file

@ -3,9 +3,7 @@ package org.keycloak.events.mongo;
import com.mongodb.BasicDBObject; import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection; import com.mongodb.DBCollection;
import com.mongodb.DBObject; import com.mongodb.DBObject;
import org.keycloak.events.Event; import org.keycloak.events.Event;
import org.keycloak.events.EventGroup;
import org.keycloak.events.EventQuery; import org.keycloak.events.EventQuery;
import org.keycloak.events.EventStoreProvider; import org.keycloak.events.EventStoreProvider;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
@ -60,14 +58,12 @@ public class MongoEventStoreProvider implements EventStoreProvider {
BasicDBObject e = new BasicDBObject(); BasicDBObject e = new BasicDBObject();
e.put("time", o.getTime()); e.put("time", o.getTime());
e.put("type", o.getType().toString()); e.put("type", o.getType().toString());
e.put("group", o.getGroup().toString());
e.put("realmId", o.getRealmId()); e.put("realmId", o.getRealmId());
e.put("clientId", o.getClientId()); e.put("clientId", o.getClientId());
e.put("userId", o.getUserId()); e.put("userId", o.getUserId());
e.put("sessionId", o.getSessionId()); e.put("sessionId", o.getSessionId());
e.put("ipAddress", o.getIpAddress()); e.put("ipAddress", o.getIpAddress());
e.put("error", o.getError()); e.put("error", o.getError());
e.put("representation", o.getRepresentation());
BasicDBObject details = new BasicDBObject(); BasicDBObject details = new BasicDBObject();
if (o.getDetails() != null) { if (o.getDetails() != null) {
@ -84,14 +80,12 @@ public class MongoEventStoreProvider implements EventStoreProvider {
Event e = new Event(); Event e = new Event();
e.setTime(o.getLong("time")); e.setTime(o.getLong("time"));
e.setType(EventType.valueOf(o.getString("type"))); e.setType(EventType.valueOf(o.getString("type")));
e.setGroup(EventGroup.valueOf(o.getString("group")));
e.setRealmId(o.getString("realmId")); e.setRealmId(o.getString("realmId"));
e.setClientId(o.getString("clientId")); e.setClientId(o.getString("clientId"));
e.setUserId(o.getString("userId")); e.setUserId(o.getString("userId"));
e.setSessionId(o.getString("sessionId")); e.setSessionId(o.getString("sessionId"));
e.setIpAddress(o.getString("ipAddress")); e.setIpAddress(o.getString("ipAddress"));
e.setError(o.getString("error")); e.setError(o.getString("error"));
e.setRepresentation(o.getString("representation"));
BasicDBObject d = (BasicDBObject) o.get("details"); BasicDBObject d = (BasicDBObject) o.get("details");
if (d != null) { if (d != null) {

View file

@ -7,13 +7,9 @@ import org.keycloak.Config;
import org.keycloak.connections.mongo.MongoConnectionProvider; import org.keycloak.connections.mongo.MongoConnectionProvider;
import org.keycloak.events.EventStoreProvider; import org.keycloak.events.EventStoreProvider;
import org.keycloak.events.EventStoreProviderFactory; import org.keycloak.events.EventStoreProviderFactory;
import org.keycloak.events.EventType;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory; import org.keycloak.models.KeycloakSessionFactory;
import java.util.HashSet;
import java.util.Set;
/** /**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a> * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/ */

View file

@ -1,12 +1,12 @@
package org.keycloak.events.log; package org.keycloak.events.log;
import java.util.Map;
import org.keycloak.events.Event; import org.keycloak.events.Event;
import org.keycloak.events.EventListenerProvider; import org.keycloak.events.EventListenerProvider;
import org.productivity.java.syslog4j.SyslogConstants; import org.productivity.java.syslog4j.SyslogConstants;
import org.productivity.java.syslog4j.SyslogIF; import org.productivity.java.syslog4j.SyslogIF;
import java.util.Map;
/** /**
* @author <a href="mailto:giriraj.sharma27@gmail.com">Giriraj Sharma</a> * @author <a href="mailto:giriraj.sharma27@gmail.com">Giriraj Sharma</a>
*/ */

View file

@ -25,7 +25,6 @@ import org.keycloak.OAuthErrorException;
import org.keycloak.RSATokenVerifier; import org.keycloak.RSATokenVerifier;
import org.keycloak.events.Details; import org.keycloak.events.Details;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventGroup;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
import org.keycloak.models.ClientModel; import org.keycloak.models.ClientModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
@ -111,7 +110,7 @@ public class UserInfoEndpoint {
} }
private Response issueUserInfo(String tokenString) { private Response issueUserInfo(String tokenString) {
EventBuilder event = new EventBuilder(EventGroup.USER, realm, session, clientConnection) EventBuilder event = new EventBuilder(realm, session, clientConnection)
.event(EventType.USER_INFO_REQUEST) .event(EventType.USER_INFO_REQUEST)
.detail(Details.AUTH_METHOD, Details.VALIDATE_ACCESS_TOKEN); .detail(Details.AUTH_METHOD, Details.VALIDATE_ACCESS_TOKEN);

View file

@ -9,7 +9,6 @@ import org.keycloak.VerificationException;
import org.keycloak.broker.provider.IdentityProvider; import org.keycloak.broker.provider.IdentityProvider;
import org.keycloak.events.Details; import org.keycloak.events.Details;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventGroup;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
import org.keycloak.jose.jws.JWSBuilder; import org.keycloak.jose.jws.JWSBuilder;
import org.keycloak.login.LoginFormsProvider; import org.keycloak.login.LoginFormsProvider;
@ -46,10 +45,10 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.net.URI; import java.net.URI;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.Iterator;
/** /**
* Stateless object that manages authentication * Stateless object that manages authentication
@ -182,7 +181,7 @@ public class AuthenticationManager {
expireRememberMeCookie(realm, uriInfo, connection); expireRememberMeCookie(realm, uriInfo, connection);
userSession.setState(UserSessionModel.State.LOGGED_OUT); userSession.setState(UserSessionModel.State.LOGGED_OUT);
String method = userSession.getNote(KEYCLOAK_LOGOUT_PROTOCOL); String method = userSession.getNote(KEYCLOAK_LOGOUT_PROTOCOL);
EventBuilder event = new EventBuilder(EventGroup.USER, realm, session, connection); EventBuilder event = new EventBuilder(realm, session, connection);
LoginProtocol protocol = session.getProvider(LoginProtocol.class, method); LoginProtocol protocol = session.getProvider(LoginProtocol.class, method);
protocol.setRealm(realm) protocol.setRealm(realm)
.setHttpHeaders(headers) .setHttpHeaders(headers)

View file

@ -29,7 +29,6 @@ import org.keycloak.broker.provider.IdentityProviderFactory;
import org.keycloak.events.Details; import org.keycloak.events.Details;
import org.keycloak.events.Errors; import org.keycloak.events.Errors;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventGroup;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
import org.keycloak.models.ClientModel; import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientSessionModel; import org.keycloak.models.ClientSessionModel;
@ -59,8 +58,14 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.*; import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -109,7 +114,7 @@ public class IdentityBrokerService implements IdentityProvider.AuthenticationCal
} }
public void init() { public void init() {
this.event = new EventBuilder(EventGroup.USER, realmModel, session, clientConnection).event(EventType.IDENTITY_PROVIDER_LOGIN); this.event = new EventBuilder(realmModel, session, clientConnection).event(EventType.IDENTITY_PROVIDER_LOGIN);
} }
@GET @GET

View file

@ -29,12 +29,20 @@ import org.keycloak.email.EmailProvider;
import org.keycloak.events.Details; import org.keycloak.events.Details;
import org.keycloak.events.Errors; import org.keycloak.events.Errors;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventGroup;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
import org.keycloak.jose.jws.JWSBuilder; import org.keycloak.jose.jws.JWSBuilder;
import org.keycloak.login.LoginFormsProvider; import org.keycloak.login.LoginFormsProvider;
import org.keycloak.models.*; import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientSessionModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelException;
import org.keycloak.models.PasswordPolicy;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RequiredCredentialModel;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.UserModel.RequiredAction; import org.keycloak.models.UserModel.RequiredAction;
import org.keycloak.models.UserSessionModel;
import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.models.utils.TimeBasedOTP; import org.keycloak.models.utils.TimeBasedOTP;
import org.keycloak.protocol.LoginProtocol; import org.keycloak.protocol.LoginProtocol;
@ -538,7 +546,7 @@ public class LoginActionsService {
AttributeFormDataProcessor.process(formData, realm, user); AttributeFormDataProcessor.process(formData, realm, user);
event.user(user).success(); event.user(user).success();
event = new EventBuilder(EventGroup.USER, realm, session, clientConnection); event = new EventBuilder(realm, session, clientConnection);
return processLogin(code, formData); return processLogin(code, formData);
} }

View file

@ -5,7 +5,6 @@ import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.ClientConnection; import org.keycloak.ClientConnection;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventGroup;
import org.keycloak.models.ApplicationModel; import org.keycloak.models.ApplicationModel;
import org.keycloak.models.Constants; import org.keycloak.models.Constants;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
@ -91,7 +90,7 @@ public class RealmsResource {
// backward compatibility // backward compatibility
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
RealmModel realm = locateRealm(name, realmManager); RealmModel realm = locateRealm(name, realmManager);
EventBuilder event = new EventBuilder(EventGroup.USER, realm, session, clientConnection); EventBuilder event = new EventBuilder(realm, session, clientConnection);
AuthenticationManager authManager = new AuthenticationManager(protector); AuthenticationManager authManager = new AuthenticationManager(protector);
LoginProtocolFactory factory = (LoginProtocolFactory)session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, OIDCLoginProtocol.LOGIN_PROTOCOL); LoginProtocolFactory factory = (LoginProtocolFactory)session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, OIDCLoginProtocol.LOGIN_PROTOCOL);
@ -107,7 +106,7 @@ public class RealmsResource {
final @PathParam("protocol") String protocol) { final @PathParam("protocol") String protocol) {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
RealmModel realm = locateRealm(name, realmManager); RealmModel realm = locateRealm(name, realmManager);
EventBuilder event = new EventBuilder(EventGroup.USER, realm, session, clientConnection); EventBuilder event = new EventBuilder(realm, session, clientConnection);
AuthenticationManager authManager = new AuthenticationManager(protector); AuthenticationManager authManager = new AuthenticationManager(protector);
LoginProtocolFactory factory = (LoginProtocolFactory)session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, protocol); LoginProtocolFactory factory = (LoginProtocolFactory)session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, protocol);
@ -129,7 +128,7 @@ public class RealmsResource {
public LoginActionsService getLoginActionsService(final @PathParam("realm") String name) { public LoginActionsService getLoginActionsService(final @PathParam("realm") String name) {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
RealmModel realm = locateRealm(name, realmManager); RealmModel realm = locateRealm(name, realmManager);
EventBuilder event = new EventBuilder(EventGroup.USER, realm, session, clientConnection); EventBuilder event = new EventBuilder(realm, session, clientConnection);
AuthenticationManager authManager = new AuthenticationManager(protector); AuthenticationManager authManager = new AuthenticationManager(protector);
LoginActionsService service = new LoginActionsService(realm, authManager, event); LoginActionsService service = new LoginActionsService(realm, authManager, event);
ResteasyProviderFactory.getInstance().injectProperties(service); ResteasyProviderFactory.getInstance().injectProperties(service);
@ -142,7 +141,7 @@ public class RealmsResource {
public ClientsManagementService getClientsManagementService(final @PathParam("realm") String name) { public ClientsManagementService getClientsManagementService(final @PathParam("realm") String name) {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
RealmModel realm = locateRealm(name, realmManager); RealmModel realm = locateRealm(name, realmManager);
EventBuilder event = new EventBuilder(EventGroup.USER, realm, session, clientConnection); EventBuilder event = new EventBuilder(realm, session, clientConnection);
ClientsManagementService service = new ClientsManagementService(realm, event); ClientsManagementService service = new ClientsManagementService(realm, event);
ResteasyProviderFactory.getInstance().injectProperties(service); ResteasyProviderFactory.getInstance().injectProperties(service);
return service; return service;
@ -168,7 +167,7 @@ public class RealmsResource {
throw new NotFoundException("account management not enabled"); throw new NotFoundException("account management not enabled");
} }
EventBuilder event = new EventBuilder(EventGroup.USER, realm, session, clientConnection); EventBuilder event = new EventBuilder(realm, session, clientConnection);
AccountService accountService = new AccountService(realm, application, event); AccountService accountService = new AccountService(realm, application, event);
ResteasyProviderFactory.getInstance().injectProperties(accountService); ResteasyProviderFactory.getInstance().injectProperties(accountService);
//resourceContext.initResource(accountService); //resourceContext.initResource(accountService);

View file

@ -8,8 +8,6 @@ import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.UnauthorizedException; import org.jboss.resteasy.spi.UnauthorizedException;
import org.keycloak.ClientConnection; import org.keycloak.ClientConnection;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventGroup;
import org.keycloak.jose.jws.JWSInput; import org.keycloak.jose.jws.JWSInput;
import org.keycloak.models.ClientModel; import org.keycloak.models.ClientModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
@ -29,7 +27,6 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.io.IOException; import java.io.IOException;
/** /**
@ -187,10 +184,7 @@ public class AdminRoot {
Cors.add(request).allowedOrigins(auth.getToken()).allowedMethods("GET", "PUT", "POST", "DELETE").auth().build(response); Cors.add(request).allowedOrigins(auth.getToken()).allowedMethods("GET", "PUT", "POST", "DELETE").auth().build(response);
EventBuilder event = new EventBuilder(EventGroup.ADMIN, auth.getRealm(), session, clientConnection); RealmsAdminResource adminResource = new RealmsAdminResource(auth, tokenManager);
event.user(auth.getUser()).client(auth.getClient());
RealmsAdminResource adminResource = new RealmsAdminResource(auth, tokenManager, event);
ResteasyProviderFactory.getInstance().injectProperties(adminResource); ResteasyProviderFactory.getInstance().injectProperties(adminResource);
return adminResource; return adminResource;
} }

View file

@ -5,9 +5,6 @@ import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.spi.BadRequestException; import org.jboss.resteasy.spi.BadRequestException;
import org.jboss.resteasy.spi.NotFoundException; import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.events.Details;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.ApplicationModel; import org.keycloak.models.ApplicationModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.ModelDuplicateException;
@ -43,7 +40,6 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -61,7 +57,6 @@ public class ApplicationResource {
protected static final Logger logger = Logger.getLogger(ApplicationResource.class); protected static final Logger logger = Logger.getLogger(ApplicationResource.class);
protected RealmModel realm; protected RealmModel realm;
private RealmAuth auth; private RealmAuth auth;
private EventBuilder event;
protected ApplicationModel application; protected ApplicationModel application;
protected KeycloakSession session; protected KeycloakSession session;
@ -72,15 +67,14 @@ public class ApplicationResource {
protected KeycloakApplication keycloak; protected KeycloakApplication keycloak;
protected KeycloakApplication getKeycloakApplication() { protected KeycloakApplication getKeycloakApplication() {
return (KeycloakApplication)keycloak; return keycloak;
} }
public ApplicationResource(RealmModel realm, RealmAuth auth, ApplicationModel applicationModel, KeycloakSession session, EventBuilder event) { public ApplicationResource(RealmModel realm, RealmAuth auth, ApplicationModel applicationModel, KeycloakSession session) {
this.realm = realm; this.realm = realm;
this.auth = auth; this.auth = auth;
this.application = applicationModel; this.application = applicationModel;
this.session = session; this.session = session;
this.event = event;
auth.init(RealmAuth.Resource.APPLICATION); auth.init(RealmAuth.Resource.APPLICATION);
} }
@ -89,7 +83,6 @@ public class ApplicationResource {
public ProtocolMappersResource getProtocolMappers() { public ProtocolMappersResource getProtocolMappers() {
ProtocolMappersResource mappers = new ProtocolMappersResource(application, auth); ProtocolMappersResource mappers = new ProtocolMappersResource(application, auth);
ResteasyProviderFactory.getInstance().injectProperties(mappers); ResteasyProviderFactory.getInstance().injectProperties(mappers);
//resourceContext.initResource(mappers);
return mappers; return mappers;
} }
@ -105,9 +98,6 @@ public class ApplicationResource {
try { try {
RepresentationToModel.updateApplication(rep, application); RepresentationToModel.updateApplication(rep, application);
event.event(EventType.UPDATE_APPLICATION).representation(rep).success();
return Response.noContent().build(); return Response.noContent().build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return Flows.errors().exists("Application " + rep.getName() + " already exists"); return Flows.errors().exists("Application " + rep.getName() + " already exists");
@ -126,11 +116,7 @@ public class ApplicationResource {
public ApplicationRepresentation getApplication() { public ApplicationRepresentation getApplication() {
auth.requireView(); auth.requireView();
ApplicationRepresentation rep = ModelToRepresentation.toRepresentation(application); return ModelToRepresentation.toRepresentation(application);
event.event(EventType.VIEW_APPLICATION).representation(rep).success();
return rep;
} }
/** /**
@ -140,7 +126,7 @@ public class ApplicationResource {
*/ */
@Path("certificates/{attr}") @Path("certificates/{attr}")
public ClientAttributeCertificateResource getCertficateResource(@PathParam("attr") String attributePrefix) { public ClientAttributeCertificateResource getCertficateResource(@PathParam("attr") String attributePrefix) {
return new ClientAttributeCertificateResource(realm, auth, application, session, attributePrefix, event); return new ClientAttributeCertificateResource(realm, auth, application, session, attributePrefix);
} }
@ -189,10 +175,6 @@ public class ApplicationResource {
@NoCache @NoCache
public void deleteApplication() { public void deleteApplication() {
auth.requireManage(); auth.requireManage();
ApplicationRepresentation rep = getApplication();
event.event(EventType.DELETE_APPLICATION).representation(rep).success();
new ApplicationManager(new RealmManager(session)).removeApplication(realm, application); new ApplicationManager(new RealmManager(session)).removeApplication(realm, application);
} }
@ -245,7 +227,7 @@ public class ApplicationResource {
@Path("roles") @Path("roles")
public RoleContainerResource getRoleContainerResource() { public RoleContainerResource getRoleContainerResource() {
return new RoleContainerResource(realm, auth, application, event); return new RoleContainerResource(realm, auth, application);
} }
/** /**
@ -348,9 +330,6 @@ public class ApplicationResource {
UserSessionRepresentation rep = ModelToRepresentation.toRepresentation(userSession); UserSessionRepresentation rep = ModelToRepresentation.toRepresentation(userSession);
sessions.add(rep); sessions.add(rep);
} }
event.event(EventType.VIEW_APPLICATION_USER_SESSIONS).representation(sessions).success();
return sessions; return sessions;
} }
@ -362,9 +341,6 @@ public class ApplicationResource {
@POST @POST
public GlobalRequestResult logoutAll() { public GlobalRequestResult logoutAll() {
auth.requireManage(); auth.requireManage();
event.event(EventType.LOGOUT_APPLICATION_USERS).success();
return new ResourceAdminManager().logoutApplication(uriInfo.getRequestUri(), realm, application); return new ResourceAdminManager().logoutApplication(uriInfo.getRequestUri(), realm, application);
} }
@ -380,9 +356,6 @@ public class ApplicationResource {
if (user == null) { if (user == null) {
throw new NotFoundException("User not found"); throw new NotFoundException("User not found");
} }
event.event(EventType.LOGOUT_USER).success();
new ResourceAdminManager().logoutUserFromApplication(uriInfo.getRequestUri(), realm, application, user, session); new ResourceAdminManager().logoutUserFromApplication(uriInfo.getRequestUri(), realm, application, user, session);
} }
@ -403,10 +376,6 @@ public class ApplicationResource {
} }
if (logger.isDebugEnabled()) logger.debug("Register node: " + node); if (logger.isDebugEnabled()) logger.debug("Register node: " + node);
application.registerNode(node, Time.currentTime()); application.registerNode(node, Time.currentTime());
event.event(EventType.REGISTER_APPLICATION_CLUSTER_NODE)
.detail(Details.APPLICATION_CLUSTER_NODE, node)
.success();
} }
/** /**
@ -427,10 +396,6 @@ public class ApplicationResource {
} }
application.unregisterNode(node); application.unregisterNode(node);
event.event(EventType.UNREGISTER_APPLICATION_CLUSTER_NODE)
.detail(Details.APPLICATION_CLUSTER_NODE, node)
.success();
} }
/** /**

View file

@ -1,6 +1,5 @@
package org.keycloak.services.resources.admin; package org.keycloak.services.resources.admin;
import org.keycloak.events.EventBuilder;
import org.keycloak.models.ApplicationModel; import org.keycloak.models.ApplicationModel;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
@ -9,8 +8,8 @@ import org.keycloak.models.RealmModel;
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class ApplicationsByIdResource extends ApplicationsResource { public class ApplicationsByIdResource extends ApplicationsResource {
public ApplicationsByIdResource(RealmModel realm, RealmAuth auth, EventBuilder event) { public ApplicationsByIdResource(RealmModel realm, RealmAuth auth) {
super(realm, auth, event); super(realm, auth);
} }
@Override @Override

View file

@ -4,8 +4,6 @@ import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.spi.NotFoundException; import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.ApplicationModel; import org.keycloak.models.ApplicationModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.ModelDuplicateException;
@ -25,7 +23,6 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -39,15 +36,13 @@ public class ApplicationsResource {
protected static final Logger logger = Logger.getLogger(RealmAdminResource.class); protected static final Logger logger = Logger.getLogger(RealmAdminResource.class);
protected RealmModel realm; protected RealmModel realm;
private RealmAuth auth; private RealmAuth auth;
private EventBuilder event;
@Context @Context
protected KeycloakSession session; protected KeycloakSession session;
public ApplicationsResource(RealmModel realm, RealmAuth auth, EventBuilder event) { public ApplicationsResource(RealmModel realm, RealmAuth auth) {
this.realm = realm; this.realm = realm;
this.auth = auth; this.auth = auth;
this.event = event;
auth.init(RealmAuth.Resource.APPLICATION); auth.init(RealmAuth.Resource.APPLICATION);
} }
@ -77,8 +72,6 @@ public class ApplicationsResource {
} }
} }
event.event(EventType.VIEW_APPLICATIONS).representation(rep).success();
return rep; return rep;
} }
@ -96,9 +89,6 @@ public class ApplicationsResource {
try { try {
ApplicationModel applicationModel = RepresentationToModel.createApplication(session, realm, rep, true); ApplicationModel applicationModel = RepresentationToModel.createApplication(session, realm, rep, true);
event.event(EventType.CREATE_APPLICATION).representation(rep).success();
return Response.created(uriInfo.getAbsolutePathBuilder().path(getApplicationPath(applicationModel)).build()).build(); return Response.created(uriInfo.getAbsolutePathBuilder().path(getApplicationPath(applicationModel)).build()).build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return Flows.errors().exists("Application " + rep.getName() + " already exists"); return Flows.errors().exists("Application " + rep.getName() + " already exists");
@ -121,7 +111,7 @@ public class ApplicationsResource {
if (applicationModel == null) { if (applicationModel == null) {
throw new NotFoundException("Could not find application: " + name); throw new NotFoundException("Could not find application: " + name);
} }
ApplicationResource applicationResource = new ApplicationResource(realm, auth, applicationModel, session, event); ApplicationResource applicationResource = new ApplicationResource(realm, auth, applicationModel, session);
ResteasyProviderFactory.getInstance().injectProperties(applicationResource); ResteasyProviderFactory.getInstance().injectProperties(applicationResource);
//resourceContext.initResource(applicationResource); //resourceContext.initResource(applicationResource);
return applicationResource; return applicationResource;

View file

@ -23,7 +23,6 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -48,14 +47,13 @@ public class ClientAttributeCertificateResource {
protected RealmModel realm; protected RealmModel realm;
private RealmAuth auth; private RealmAuth auth;
private EventBuilder event;
protected ClientModel client; protected ClientModel client;
protected KeycloakSession session; protected KeycloakSession session;
protected String attributePrefix; protected String attributePrefix;
protected String privateAttribute; protected String privateAttribute;
protected String certificateAttribute; protected String certificateAttribute;
public ClientAttributeCertificateResource(RealmModel realm, RealmAuth auth, ClientModel client, KeycloakSession session, String attributePrefix, EventBuilder event) { public ClientAttributeCertificateResource(RealmModel realm, RealmAuth auth, ClientModel client, KeycloakSession session, String attributePrefix) {
this.realm = realm; this.realm = realm;
this.auth = auth; this.auth = auth;
this.client = client; this.client = client;
@ -63,7 +61,6 @@ public class ClientAttributeCertificateResource {
this.attributePrefix = attributePrefix; this.attributePrefix = attributePrefix;
this.privateAttribute = attributePrefix + "." + PRIVATE_KEY; this.privateAttribute = attributePrefix + "." + PRIVATE_KEY;
this.certificateAttribute = attributePrefix + "." + X509CERTIFICATE; this.certificateAttribute = attributePrefix + "." + X509CERTIFICATE;
this.event = event;
} }
public static class ClientKeyPairInfo { public static class ClientKeyPairInfo {
@ -99,9 +96,6 @@ public class ClientAttributeCertificateResource {
ClientKeyPairInfo info = new ClientKeyPairInfo(); ClientKeyPairInfo info = new ClientKeyPairInfo();
info.setCertificate(client.getAttribute(certificateAttribute)); info.setCertificate(client.getAttribute(certificateAttribute));
info.setPrivateKey(client.getAttribute(privateAttribute)); info.setPrivateKey(client.getAttribute(privateAttribute));
event.event(EventType.VIEW_CLIENT_CERTIFICATE).representation(info).success();
return info; return info;
} }
@ -140,9 +134,6 @@ public class ClientAttributeCertificateResource {
ClientKeyPairInfo info = new ClientKeyPairInfo(); ClientKeyPairInfo info = new ClientKeyPairInfo();
info.setCertificate(client.getAttribute(certificateAttribute)); info.setCertificate(client.getAttribute(certificateAttribute));
info.setPrivateKey(client.getAttribute(privateAttribute)); info.setPrivateKey(client.getAttribute(privateAttribute));
event.event(EventType.UPDATE_CLIENT_CERTIFICATE).representation(info).success();
return info; return info;
} }
@ -200,8 +191,6 @@ public class ClientAttributeCertificateResource {
info.setCertificate(certPem); info.setCertificate(certPem);
} }
event.event(EventType.UPDATE_CLIENT_CERTIFICATE).representation(info).success();
return info; return info;
} }
@ -327,9 +316,6 @@ public class ClientAttributeCertificateResource {
stream.flush(); stream.flush();
stream.close(); stream.close();
byte[] rtn = stream.toByteArray(); byte[] rtn = stream.toByteArray();
event.event(EventType.VIEW_CLIENT_CERTIFICATE).representation(rtn).success();
return rtn; return rtn;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);

View file

@ -4,8 +4,6 @@ import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.annotations.cache.NoCache;
import org.keycloak.broker.provider.IdentityProvider; import org.keycloak.broker.provider.IdentityProvider;
import org.keycloak.broker.provider.IdentityProviderFactory; import org.keycloak.broker.provider.IdentityProviderFactory;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.ClientIdentityProviderMappingModel; import org.keycloak.models.ClientIdentityProviderMappingModel;
import org.keycloak.models.ClientModel; import org.keycloak.models.ClientModel;
import org.keycloak.models.FederatedIdentityModel; import org.keycloak.models.FederatedIdentityModel;
@ -31,7 +29,6 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -46,14 +43,12 @@ public class IdentityProviderResource {
private final RealmModel realm; private final RealmModel realm;
private final KeycloakSession session; private final KeycloakSession session;
private final IdentityProviderModel identityProviderModel; private final IdentityProviderModel identityProviderModel;
private EventBuilder event;
public IdentityProviderResource(RealmAuth auth, RealmModel realm, KeycloakSession session, IdentityProviderModel identityProviderModel, EventBuilder event) { public IdentityProviderResource(RealmAuth auth, RealmModel realm, KeycloakSession session, IdentityProviderModel identityProviderModel) {
this.realm = realm; this.realm = realm;
this.session = session; this.session = session;
this.identityProviderModel = identityProviderModel; this.identityProviderModel = identityProviderModel;
this.auth = auth; this.auth = auth;
this.event = event;
} }
@GET @GET
@ -62,10 +57,6 @@ public class IdentityProviderResource {
public IdentityProviderRepresentation getIdentityProvider() { public IdentityProviderRepresentation getIdentityProvider() {
IdentityProviderRepresentation rep = ModelToRepresentation.toRepresentation(this.identityProviderModel); IdentityProviderRepresentation rep = ModelToRepresentation.toRepresentation(this.identityProviderModel);
event.event(EventType.VIEW_IDENTITY_PROVIDER)
.representation(rep)
.success();
return rep; return rep;
} }
@ -74,17 +65,11 @@ public class IdentityProviderResource {
public Response delete() { public Response delete() {
this.auth.requireManage(); this.auth.requireManage();
IdentityProviderRepresentation rep = getIdentityProvider();
removeClientIdentityProviders(this.realm.getApplications(), this.identityProviderModel); removeClientIdentityProviders(this.realm.getApplications(), this.identityProviderModel);
removeClientIdentityProviders(this.realm.getOAuthClients(), this.identityProviderModel); removeClientIdentityProviders(this.realm.getOAuthClients(), this.identityProviderModel);
this.realm.removeIdentityProviderByAlias(this.identityProviderModel.getAlias()); this.realm.removeIdentityProviderByAlias(this.identityProviderModel.getAlias());
event.event(EventType.DELETE_IDENTITY_PROVIDER)
.representation(rep)
.success();
return Response.noContent().build(); return Response.noContent().build();
} }
@ -110,10 +95,6 @@ public class IdentityProviderResource {
updateUsersAfterProviderAliasChange(this.session.users().getUsers(this.realm), oldProviderId, newProviderId); updateUsersAfterProviderAliasChange(this.session.users().getUsers(this.realm), oldProviderId, newProviderId);
} }
event.event(EventType.UPDATE_IDENTITY_PROVIDER)
.representation(providerRep)
.success();
return Response.noContent().build(); return Response.noContent().build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return Flows.errors().exists("Identity Provider " + providerRep.getAlias() + " already exists"); return Flows.errors().exists("Identity Provider " + providerRep.getAlias() + " already exists");

View file

@ -8,8 +8,6 @@ import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.broker.provider.IdentityProvider; import org.keycloak.broker.provider.IdentityProvider;
import org.keycloak.broker.provider.IdentityProviderFactory; import org.keycloak.broker.provider.IdentityProviderFactory;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.IdentityProviderModel; import org.keycloak.models.IdentityProviderModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.ModelDuplicateException;
@ -32,7 +30,6 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -49,13 +46,11 @@ public class IdentityProvidersResource {
private final RealmModel realm; private final RealmModel realm;
private final KeycloakSession session; private final KeycloakSession session;
private RealmAuth auth; private RealmAuth auth;
private EventBuilder event;
public IdentityProvidersResource(RealmModel realm, KeycloakSession session, RealmAuth auth, EventBuilder event) { public IdentityProvidersResource(RealmModel realm, KeycloakSession session, RealmAuth auth) {
this.realm = realm; this.realm = realm;
this.session = session; this.session = session;
this.auth = auth; this.auth = auth;
this.event = event;
this.auth.init(RealmAuth.Resource.IDENTITY_PROVIDER); this.auth.init(RealmAuth.Resource.IDENTITY_PROVIDER);
} }
@ -68,10 +63,6 @@ public class IdentityProvidersResource {
IdentityProviderFactory providerFactory = getProviderFactorytById(providerId); IdentityProviderFactory providerFactory = getProviderFactorytById(providerId);
if (providerFactory != null) { if (providerFactory != null) {
event.event(EventType.VIEW_IDENTITY_PROVIDERS)
.representation(providerFactory)
.success();
return Response.ok(providerFactory).build(); return Response.ok(providerFactory).build();
} }
@ -90,11 +81,6 @@ public class IdentityProvidersResource {
InputStream inputStream = file.getBody(InputStream.class, null); InputStream inputStream = file.getBody(InputStream.class, null);
IdentityProviderFactory providerFactory = getProviderFactorytById(providerId); IdentityProviderFactory providerFactory = getProviderFactorytById(providerId);
Map<String, String> config = providerFactory.parseConfig(inputStream); Map<String, String> config = providerFactory.parseConfig(inputStream);
event.event(EventType.CREATE_IDENTITY_PROVIDER)
.representation(config)
.success();
return config; return config;
} }
@ -116,11 +102,6 @@ public class IdentityProvidersResource {
} }
IdentityProviderFactory providerFactory = getProviderFactorytById(providerId); IdentityProviderFactory providerFactory = getProviderFactorytById(providerId);
Map<String, String> config = providerFactory.parseConfig(inputStream); Map<String, String> config = providerFactory.parseConfig(inputStream);
event.event(EventType.CREATE_IDENTITY_PROVIDER)
.representation(config)
.success();
return config; return config;
} }
@ -137,8 +118,6 @@ public class IdentityProvidersResource {
representations.add(ModelToRepresentation.toRepresentation(identityProviderModel)); representations.add(ModelToRepresentation.toRepresentation(identityProviderModel));
} }
event.event(EventType.VIEW_IDENTITY_PROVIDERS).representation(representations).success();
return representations; return representations;
} }
@ -151,10 +130,6 @@ public class IdentityProvidersResource {
try { try {
this.realm.addIdentityProvider(RepresentationToModel.toModel(representation)); this.realm.addIdentityProvider(RepresentationToModel.toModel(representation));
event.event(EventType.CREATE_IDENTITY_PROVIDER)
.representation(representation)
.success();
return Response.created(uriInfo.getAbsolutePathBuilder().path(representation.getProviderId()).build()).build(); return Response.created(uriInfo.getAbsolutePathBuilder().path(representation.getProviderId()).build()).build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return Flows.errors().exists("Identity Provider " + representation.getAlias() + " already exists"); return Flows.errors().exists("Identity Provider " + representation.getAlias() + " already exists");
@ -177,13 +152,9 @@ public class IdentityProvidersResource {
throw new NotFoundException("Could not find identity provider: " + alias); throw new NotFoundException("Could not find identity provider: " + alias);
} }
IdentityProviderResource identityProviderResource = new IdentityProviderResource(this.auth, realm, session, identityProviderModel, event); IdentityProviderResource identityProviderResource = new IdentityProviderResource(this.auth, realm, session, identityProviderModel);
ResteasyProviderFactory.getInstance().injectProperties(identityProviderResource); ResteasyProviderFactory.getInstance().injectProperties(identityProviderResource);
event.event(EventType.VIEW_IDENTITY_PROVIDER)
.representation(identityProviderResource)
.success();
return identityProviderResource; return identityProviderResource;
} }

View file

@ -4,8 +4,6 @@ import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.spi.NotFoundException; import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.OAuthClientModel; import org.keycloak.models.OAuthClientModel;
@ -33,7 +31,6 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.io.IOException; import java.io.IOException;
/** /**
@ -46,7 +43,6 @@ public class OAuthClientResource {
protected static final Logger logger = Logger.getLogger(RealmAdminResource.class); protected static final Logger logger = Logger.getLogger(RealmAdminResource.class);
protected RealmModel realm; protected RealmModel realm;
private RealmAuth auth; private RealmAuth auth;
private EventBuilder event;
protected OAuthClientModel oauthClient; protected OAuthClientModel oauthClient;
protected KeycloakSession session; protected KeycloakSession session;
@Context @Context
@ -59,12 +55,11 @@ public class OAuthClientResource {
return (KeycloakApplication)application; return (KeycloakApplication)application;
} }
public OAuthClientResource(RealmModel realm, RealmAuth auth, OAuthClientModel oauthClient, KeycloakSession session, EventBuilder event) { public OAuthClientResource(RealmModel realm, RealmAuth auth, OAuthClientModel oauthClient, KeycloakSession session) {
this.realm = realm; this.realm = realm;
this.auth = auth; this.auth = auth;
this.oauthClient = oauthClient; this.oauthClient = oauthClient;
this.session = session; this.session = session;
this.event = event;
auth.init(RealmAuth.Resource.CLIENT); auth.init(RealmAuth.Resource.CLIENT);
} }
@ -89,7 +84,7 @@ public class OAuthClientResource {
*/ */
@Path("certificates/{attr}") @Path("certificates/{attr}")
public ClientAttributeCertificateResource getCertficateResource(@PathParam("attr") String attributePrefix) { public ClientAttributeCertificateResource getCertficateResource(@PathParam("attr") String attributePrefix) {
return new ClientAttributeCertificateResource(realm, auth, oauthClient, session, attributePrefix, event); return new ClientAttributeCertificateResource(realm, auth, oauthClient, session, attributePrefix);
} }
@ -107,8 +102,6 @@ public class OAuthClientResource {
try { try {
RepresentationToModel.updateOAuthClient(session, rep, oauthClient); RepresentationToModel.updateOAuthClient(session, rep, oauthClient);
event.event(EventType.UPDATE_OAUTH_CLIENT).representation(rep).success();
return Response.noContent().build(); return Response.noContent().build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return Flows.errors().exists("Client " + rep.getName() + " already exists"); return Flows.errors().exists("Client " + rep.getName() + " already exists");
@ -126,11 +119,7 @@ public class OAuthClientResource {
public OAuthClientRepresentation getOAuthClient() { public OAuthClientRepresentation getOAuthClient() {
auth.requireView(); auth.requireView();
OAuthClientRepresentation rep = ModelToRepresentation.toRepresentation(oauthClient); return ModelToRepresentation.toRepresentation(oauthClient);
event.event(EventType.VIEW_OAUTH_CLIENT).representation(rep).success();
return rep;
} }
/** /**
@ -162,10 +151,6 @@ public class OAuthClientResource {
public void deleteOAuthClient() { public void deleteOAuthClient() {
auth.requireManage(); auth.requireManage();
OAuthClientRepresentation rep = getOAuthClient();
event.event(EventType.DELETE_OAUTH_CLIENT).representation(rep).success();
new OAuthClientManager(new RealmManager(session)).removeClient(realm, oauthClient); new OAuthClientManager(new RealmManager(session)).removeClient(realm, oauthClient);
} }

View file

@ -1,6 +1,5 @@
package org.keycloak.services.resources.admin; package org.keycloak.services.resources.admin;
import org.keycloak.events.EventBuilder;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.OAuthClientModel; import org.keycloak.models.OAuthClientModel;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
@ -10,8 +9,8 @@ import org.keycloak.models.RealmModel;
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class OAuthClientsByIdResource extends OAuthClientsResource { public class OAuthClientsByIdResource extends OAuthClientsResource {
public OAuthClientsByIdResource(RealmModel realm, RealmAuth auth, KeycloakSession session, EventBuilder event) { public OAuthClientsByIdResource(RealmModel realm, RealmAuth auth, KeycloakSession session) {
super(realm, auth, session, event); super(realm, auth, session);
} }
@Override @Override

View file

@ -4,8 +4,6 @@ import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.spi.NotFoundException; import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.OAuthClientModel; import org.keycloak.models.OAuthClientModel;
@ -25,7 +23,6 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -36,21 +33,13 @@ import java.util.List;
public class OAuthClientsResource { public class OAuthClientsResource {
protected static final Logger logger = Logger.getLogger(RealmAdminResource.class); protected static final Logger logger = Logger.getLogger(RealmAdminResource.class);
protected RealmModel realm; protected RealmModel realm;
private EventBuilder event;
protected KeycloakSession session; protected KeycloakSession session;
/*
@Context
protected ResourceContext resourceContext;
*/
private RealmAuth auth; private RealmAuth auth;
public OAuthClientsResource(RealmModel realm, RealmAuth auth, KeycloakSession session, EventBuilder event) { public OAuthClientsResource(RealmModel realm, RealmAuth auth, KeycloakSession session) {
this.auth = auth; this.auth = auth;
this.realm = realm; this.realm = realm;
this.session = session; this.session = session;
this.event = event;
auth.init(RealmAuth.Resource.CLIENT); auth.init(RealmAuth.Resource.CLIENT);
} }
@ -78,8 +67,6 @@ public class OAuthClientsResource {
} }
} }
event.event(EventType.VIEW_OAUTH_CLIENTS).representation(rep).success();
return rep; return rep;
} }
@ -97,8 +84,6 @@ public class OAuthClientsResource {
try { try {
OAuthClientModel oauth = RepresentationToModel.createOAuthClient(session, rep, realm); OAuthClientModel oauth = RepresentationToModel.createOAuthClient(session, rep, realm);
event.event(EventType.CREATE_OAUTH_CLIENT).representation(rep).success();
return Response.created(uriInfo.getAbsolutePathBuilder().path(getClientPath(oauth)).build()).build(); return Response.created(uriInfo.getAbsolutePathBuilder().path(getClientPath(oauth)).build()).build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return Flows.errors().exists("Client " + rep.getName() + " already exists"); return Flows.errors().exists("Client " + rep.getName() + " already exists");
@ -123,7 +108,7 @@ public class OAuthClientsResource {
if (oauth == null) { if (oauth == null) {
throw new NotFoundException("OAuth Client not found"); throw new NotFoundException("OAuth Client not found");
} }
OAuthClientResource oAuthClientResource = new OAuthClientResource(realm, auth, oauth, session, event); OAuthClientResource oAuthClientResource = new OAuthClientResource(realm, auth, oauth, session);
ResteasyProviderFactory.getInstance().injectProperties(oAuthClientResource); ResteasyProviderFactory.getInstance().injectProperties(oAuthClientResource);
//resourceContext.initResource(oAuthClientResource); //resourceContext.initResource(oAuthClientResource);
return oAuthClientResource; return oAuthClientResource;

View file

@ -1,32 +1,11 @@
package org.keycloak.services.resources.admin; package org.keycloak.services.resources.admin;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.spi.NotFoundException; import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.ClientConnection; import org.keycloak.ClientConnection;
import org.keycloak.events.Event; import org.keycloak.events.Event;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventQuery; import org.keycloak.events.EventQuery;
import org.keycloak.events.EventStoreProvider; import org.keycloak.events.EventStoreProvider;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
@ -53,6 +32,25 @@ import org.keycloak.services.managers.UsersSyncManager;
import org.keycloak.services.resources.flows.Flows; import org.keycloak.services.resources.flows.Flows;
import org.keycloak.timer.TimerProvider; import org.keycloak.timer.TimerProvider;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/** /**
* Base resource class for the admin REST api of one realm * Base resource class for the admin REST api of one realm
* *
@ -64,7 +62,6 @@ public class RealmAdminResource {
protected RealmAuth auth; protected RealmAuth auth;
protected RealmModel realm; protected RealmModel realm;
private TokenManager tokenManager; private TokenManager tokenManager;
private EventBuilder event;
@Context @Context
protected KeycloakSession session; protected KeycloakSession session;
@ -78,11 +75,10 @@ public class RealmAdminResource {
@Context @Context
protected HttpHeaders headers; protected HttpHeaders headers;
public RealmAdminResource(RealmAuth auth, RealmModel realm, TokenManager tokenManager, EventBuilder event) { public RealmAdminResource(RealmAuth auth, RealmModel realm, TokenManager tokenManager) {
this.auth = auth; this.auth = auth;
this.realm = realm; this.realm = realm;
this.tokenManager = tokenManager; this.tokenManager = tokenManager;
this.event = event;
auth.init(RealmAuth.Resource.REALM); auth.init(RealmAuth.Resource.REALM);
} }
@ -105,7 +101,7 @@ public class RealmAdminResource {
*/ */
@Path("applications") @Path("applications")
public ApplicationsResource getApplications() { public ApplicationsResource getApplications() {
ApplicationsResource applicationsResource = new ApplicationsResource(realm, auth, event); ApplicationsResource applicationsResource = new ApplicationsResource(realm, auth);
ResteasyProviderFactory.getInstance().injectProperties(applicationsResource); ResteasyProviderFactory.getInstance().injectProperties(applicationsResource);
//resourceContext.initResource(applicationsResource); //resourceContext.initResource(applicationsResource);
return applicationsResource; return applicationsResource;
@ -118,7 +114,7 @@ public class RealmAdminResource {
*/ */
@Path("applications-by-id") @Path("applications-by-id")
public ApplicationsByIdResource getApplicationsById() { public ApplicationsByIdResource getApplicationsById() {
ApplicationsByIdResource applicationsResource = new ApplicationsByIdResource(realm, auth, event); ApplicationsByIdResource applicationsResource = new ApplicationsByIdResource(realm, auth);
ResteasyProviderFactory.getInstance().injectProperties(applicationsResource); ResteasyProviderFactory.getInstance().injectProperties(applicationsResource);
//resourceContext.initResource(applicationsResource); //resourceContext.initResource(applicationsResource);
return applicationsResource; return applicationsResource;
@ -131,7 +127,7 @@ public class RealmAdminResource {
*/ */
@Path("oauth-clients") @Path("oauth-clients")
public OAuthClientsResource getOAuthClients() { public OAuthClientsResource getOAuthClients() {
OAuthClientsResource oauth = new OAuthClientsResource(realm, auth, session, event); OAuthClientsResource oauth = new OAuthClientsResource(realm, auth, session);
ResteasyProviderFactory.getInstance().injectProperties(oauth); ResteasyProviderFactory.getInstance().injectProperties(oauth);
//resourceContext.initResource(oauth); //resourceContext.initResource(oauth);
return oauth; return oauth;
@ -144,7 +140,7 @@ public class RealmAdminResource {
*/ */
@Path("oauth-clients-by-id") @Path("oauth-clients-by-id")
public OAuthClientsByIdResource getOAuthClientsById() { public OAuthClientsByIdResource getOAuthClientsById() {
OAuthClientsByIdResource oauth = new OAuthClientsByIdResource(realm, auth, session, event); OAuthClientsByIdResource oauth = new OAuthClientsByIdResource(realm, auth, session);
ResteasyProviderFactory.getInstance().injectProperties(oauth); ResteasyProviderFactory.getInstance().injectProperties(oauth);
//resourceContext.initResource(oauth); //resourceContext.initResource(oauth);
return oauth; return oauth;
@ -157,7 +153,7 @@ public class RealmAdminResource {
*/ */
@Path("roles") @Path("roles")
public RoleContainerResource getRoleContainerResource() { public RoleContainerResource getRoleContainerResource() {
return new RoleContainerResource(realm, auth, realm, event); return new RoleContainerResource(realm, auth, realm);
} }
/** /**
@ -180,18 +176,12 @@ public class RealmAdminResource {
CacheUserProvider cache = (CacheUserProvider)session.userStorage(); CacheUserProvider cache = (CacheUserProvider)session.userStorage();
rep.setUserCacheEnabled(cache.isEnabled()); rep.setUserCacheEnabled(cache.isEnabled());
} }
event.event(EventType.VIEW_REALM).representation(rep).success();
return rep; return rep;
} else { } else {
auth.requireAny(); auth.requireAny();
RealmRepresentation rep = new RealmRepresentation(); RealmRepresentation rep = new RealmRepresentation();
rep.setRealm(realm.getName()); rep.setRealm(realm.getName());
event.event(EventType.VIEW_REALM).representation(rep).success();
return rep; return rep;
} }
} }
@ -227,8 +217,6 @@ public class RealmAdminResource {
usersSyncManager.refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), fedProvider, realm.getId()); usersSyncManager.refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), fedProvider, realm.getId());
} }
event.event(EventType.UPDATE_REALM).representation(rep).success();
return Response.noContent().build(); return Response.noContent().build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return Flows.errors().exists("Realm " + rep.getRealm() + " already exists"); return Flows.errors().exists("Realm " + rep.getRealm() + " already exists");
@ -243,13 +231,9 @@ public class RealmAdminResource {
public void deleteRealm() { public void deleteRealm() {
auth.requireManage(); auth.requireManage();
RealmRepresentation rep = getRealm();
if (!new RealmManager(session).removeRealm(realm)) { if (!new RealmManager(session).removeRealm(realm)) {
throw new NotFoundException("Realm doesn't exist"); throw new NotFoundException("Realm doesn't exist");
} }
event.event(EventType.DELETE_REALM).representation(rep).success();
} }
/** /**
@ -259,7 +243,7 @@ public class RealmAdminResource {
*/ */
@Path("users") @Path("users")
public UsersResource users() { public UsersResource users() {
UsersResource users = new UsersResource(realm, auth, tokenManager, event); UsersResource users = new UsersResource(realm, auth, tokenManager);
ResteasyProviderFactory.getInstance().injectProperties(users); ResteasyProviderFactory.getInstance().injectProperties(users);
//resourceContext.initResource(users); //resourceContext.initResource(users);
return users; return users;
@ -267,7 +251,7 @@ public class RealmAdminResource {
@Path("user-federation") @Path("user-federation")
public UserFederationResource userFederation() { public UserFederationResource userFederation() {
UserFederationResource fed = new UserFederationResource(realm, auth, event); UserFederationResource fed = new UserFederationResource(realm, auth);
ResteasyProviderFactory.getInstance().injectProperties(fed); ResteasyProviderFactory.getInstance().injectProperties(fed);
//resourceContext.initResource(fed); //resourceContext.initResource(fed);
return fed; return fed;
@ -280,7 +264,7 @@ public class RealmAdminResource {
*/ */
@Path("roles-by-id") @Path("roles-by-id")
public RoleByIdResource rolesById() { public RoleByIdResource rolesById() {
RoleByIdResource resource = new RoleByIdResource(realm, auth, event); RoleByIdResource resource = new RoleByIdResource(realm, auth);
ResteasyProviderFactory.getInstance().injectProperties(resource); ResteasyProviderFactory.getInstance().injectProperties(resource);
//resourceContext.initResource(resource); //resourceContext.initResource(resource);
return resource; return resource;
@ -487,6 +471,6 @@ public class RealmAdminResource {
@Path("identity-provider") @Path("identity-provider")
public IdentityProvidersResource getIdentityProviderResource() { public IdentityProvidersResource getIdentityProviderResource() {
return new IdentityProvidersResource(realm, session, this.auth, event); return new IdentityProvidersResource(realm, session, this.auth);
} }
} }

View file

@ -4,11 +4,9 @@ import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.plugins.providers.multipart.InputPart; import org.jboss.resteasy.plugins.providers.multipart.InputPart;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.NotFoundException; import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.events.Details;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.AdminRoles; import org.keycloak.models.AdminRoles;
import org.keycloak.models.ApplicationModel; import org.keycloak.models.ApplicationModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
@ -36,7 +34,6 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
@ -53,12 +50,16 @@ public class RealmsAdminResource {
protected static final Logger logger = Logger.getLogger(RealmsAdminResource.class); protected static final Logger logger = Logger.getLogger(RealmsAdminResource.class);
protected AdminAuth auth; protected AdminAuth auth;
protected TokenManager tokenManager; protected TokenManager tokenManager;
private EventBuilder event;
public RealmsAdminResource(AdminAuth auth, TokenManager tokenManager, EventBuilder event) { @Context
protected KeycloakSession session;
@Context
protected KeycloakApplication keycloak;
public RealmsAdminResource(AdminAuth auth, TokenManager tokenManager) {
this.auth = auth; this.auth = auth;
this.tokenManager = tokenManager; this.tokenManager = tokenManager;
this.event = event;
} }
public static final CacheControl noCache = new CacheControl(); public static final CacheControl noCache = new CacheControl();
@ -67,17 +68,6 @@ public class RealmsAdminResource {
noCache.setNoCache(true); noCache.setNoCache(true);
} }
/*
@Context
protected ResourceContext resourceContext;
*/
@Context
protected KeycloakSession session;
@Context
protected KeycloakApplication keycloak;
/** /**
* Returns a list of realms. This list is filtered based on what realms the caller is allowed to view. * Returns a list of realms. This list is filtered based on what realms the caller is allowed to view.
* *
@ -102,7 +92,6 @@ public class RealmsAdminResource {
return reps; return reps;
} }
protected void addRealmRep(List<RealmRepresentation> reps, RealmModel realm, ApplicationModel realmManagementApplication) { protected void addRealmRep(List<RealmRepresentation> reps, RealmModel realm, ApplicationModel realmManagementApplication) {
if (auth.hasAppRole(realmManagementApplication, AdminRoles.MANAGE_REALM)) { if (auth.hasAppRole(realmManagementApplication, AdminRoles.MANAGE_REALM)) {
reps.add(ModelToRepresentation.toRepresentation(realm, false)); reps.add(ModelToRepresentation.toRepresentation(realm, false));
@ -141,10 +130,6 @@ public class RealmsAdminResource {
URI location = AdminRoot.realmsUrl(uriInfo).path(realm.getName()).build(); URI location = AdminRoot.realmsUrl(uriInfo).path(realm.getName()).build();
logger.debugv("imported realm success, sending back: {0}", location.toString()); logger.debugv("imported realm success, sending back: {0}", location.toString());
event.event(EventType.CREATE_REALM)
.representation(rep)
.success();
return Response.created(location).build(); return Response.created(location).build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return Flows.errors().exists("Realm " + rep.getRealm() + " already exists"); return Flows.errors().exists("Realm " + rep.getRealm() + " already exists");
@ -191,8 +176,6 @@ public class RealmsAdminResource {
URI location = AdminRoot.realmsUrl(uriInfo).path(realm.getName()).build(); URI location = AdminRoot.realmsUrl(uriInfo).path(realm.getName()).build();
return Response.created(location).build(); return Response.created(location).build();
} }
event.event(EventType.CREATE_REALM).representation(rep).success();
} }
return Response.noContent().build(); return Response.noContent().build();
@ -237,8 +220,7 @@ public class RealmsAdminResource {
realmAuth = new RealmAuth(auth, realm.getApplicationByName(realmManager.getRealmAdminApplicationName(auth.getRealm()))); realmAuth = new RealmAuth(auth, realm.getApplicationByName(realmManager.getRealmAdminApplicationName(auth.getRealm())));
} }
event.detail(Details.REALM, realm.getName()); RealmAdminResource adminResource = new RealmAdminResource(realmAuth, realm, tokenManager);
RealmAdminResource adminResource = new RealmAdminResource(realmAuth, realm, tokenManager, event);
ResteasyProviderFactory.getInstance().injectProperties(adminResource); ResteasyProviderFactory.getInstance().injectProperties(adminResource);
//resourceContext.initResource(adminResource); //resourceContext.initResource(adminResource);
return adminResource; return adminResource;

View file

@ -3,8 +3,6 @@ package org.keycloak.services.resources.admin;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.spi.NotFoundException; import org.jboss.resteasy.spi.NotFoundException;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.ApplicationModel; import org.keycloak.models.ApplicationModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.OAuthClientModel; import org.keycloak.models.OAuthClientModel;
@ -22,7 +20,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -36,17 +33,15 @@ public class RoleByIdResource extends RoleResource {
protected static final Logger logger = Logger.getLogger(RoleByIdResource.class); protected static final Logger logger = Logger.getLogger(RoleByIdResource.class);
private final RealmModel realm; private final RealmModel realm;
private final RealmAuth auth; private final RealmAuth auth;
private EventBuilder event;
@Context @Context
protected KeycloakSession session; protected KeycloakSession session;
public RoleByIdResource(RealmModel realm, RealmAuth auth, EventBuilder event) { public RoleByIdResource(RealmModel realm, RealmAuth auth) {
super(realm); super(realm);
this.realm = realm; this.realm = realm;
this.auth = auth; this.auth = auth;
this.event = event;
} }
/** /**
@ -63,13 +58,7 @@ public class RoleByIdResource extends RoleResource {
RoleModel roleModel = getRoleModel(id); RoleModel roleModel = getRoleModel(id);
auth.requireView(); auth.requireView();
RoleRepresentation rep = getRole(roleModel); return getRole(roleModel);
event.event(EventType.VIEW_ROLE)
.representation(rep)
.success();
return rep;
} }
protected RoleModel getRoleModel(String id) { protected RoleModel getRoleModel(String id) {
@ -102,14 +91,9 @@ public class RoleByIdResource extends RoleResource {
@DELETE @DELETE
@NoCache @NoCache
public void deleteRole(final @PathParam("role-id") String id) { public void deleteRole(final @PathParam("role-id") String id) {
RoleRepresentation rep = getRole(id);
RoleModel role = getRoleModel(id); RoleModel role = getRoleModel(id);
auth.requireManage(); auth.requireManage();
deleteRole(role); deleteRole(role);
event.event(EventType.DELETE_ROLE)
.representation(rep)
.success();
} }
/** /**
@ -125,10 +109,6 @@ public class RoleByIdResource extends RoleResource {
RoleModel role = getRoleModel(id); RoleModel role = getRoleModel(id);
auth.requireManage(); auth.requireManage();
updateRole(rep, role); updateRole(rep, role);
event.event(EventType.UPDATE_ROLE)
.representation(rep)
.success();
} }
/** /**
@ -144,12 +124,6 @@ public class RoleByIdResource extends RoleResource {
RoleModel role = getRoleModel(id); RoleModel role = getRoleModel(id);
auth.requireManage(); auth.requireManage();
addComposites(roles, role); addComposites(roles, role);
RoleRepresentation rep = getRole(id);
event.event(EventType.UPDATE_ROLE)
.representation(rep)
.success();
} }
/** /**

View file

@ -2,8 +2,6 @@ package org.keycloak.services.resources.admin;
import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.spi.NotFoundException; import org.jboss.resteasy.spi.NotFoundException;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.ApplicationModel; import org.keycloak.models.ApplicationModel;
import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
@ -24,7 +22,6 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -37,14 +34,12 @@ public class RoleContainerResource extends RoleResource {
private final RealmModel realm; private final RealmModel realm;
private final RealmAuth auth; private final RealmAuth auth;
protected RoleContainerModel roleContainer; protected RoleContainerModel roleContainer;
private EventBuilder event;
public RoleContainerResource(RealmModel realm, RealmAuth auth, RoleContainerModel roleContainer, EventBuilder event) { public RoleContainerResource(RealmModel realm, RealmAuth auth, RoleContainerModel roleContainer) {
super(realm); super(realm);
this.realm = realm; this.realm = realm;
this.auth = auth; this.auth = auth;
this.roleContainer = roleContainer; this.roleContainer = roleContainer;
this.event = event;
} }
/** /**
@ -63,9 +58,6 @@ public class RoleContainerResource extends RoleResource {
for (RoleModel roleModel : roleModels) { for (RoleModel roleModel : roleModels) {
roles.add(ModelToRepresentation.toRepresentation(roleModel)); roles.add(ModelToRepresentation.toRepresentation(roleModel));
} }
event.event(EventType.VIEW_ROLES).representation(roles).success();
return roles; return roles;
} }
@ -84,11 +76,6 @@ public class RoleContainerResource extends RoleResource {
try { try {
RoleModel role = roleContainer.addRole(rep.getName()); RoleModel role = roleContainer.addRole(rep.getName());
role.setDescription(rep.getDescription()); role.setDescription(rep.getDescription());
event.event(EventType.CREATE_ROLE)
.representation(rep)
.success();
return Response.created(uriInfo.getAbsolutePathBuilder().path(role.getName()).build()).build(); return Response.created(uriInfo.getAbsolutePathBuilder().path(role.getName()).build()).build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return Flows.errors().exists("Role with name " + rep.getName() + " already exists"); return Flows.errors().exists("Role with name " + rep.getName() + " already exists");
@ -113,13 +100,7 @@ public class RoleContainerResource extends RoleResource {
throw new NotFoundException("Could not find role: " + roleName); throw new NotFoundException("Could not find role: " + roleName);
} }
RoleRepresentation rep = getRole(roleModel); return getRole(roleModel);
event.event(EventType.VIEW_ROLE)
.representation(rep)
.success();
return rep;
} }
/** /**
@ -139,10 +120,6 @@ public class RoleContainerResource extends RoleResource {
throw new NotFoundException("Could not find role: " + roleName); throw new NotFoundException("Could not find role: " + roleName);
} }
deleteRole(role); deleteRole(role);
event.event(EventType.DELETE_ROLE)
.representation(rep)
.success();
} }
/** /**
@ -164,11 +141,6 @@ public class RoleContainerResource extends RoleResource {
} }
try { try {
updateRole(rep, role); updateRole(rep, role);
event.event(EventType.UPDATE_ROLE)
.representation(rep)
.success();
return Response.noContent().build(); return Response.noContent().build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return Flows.errors().exists("Role with name " + rep.getName() + " already exists"); return Flows.errors().exists("Role with name " + rep.getName() + " already exists");

View file

@ -3,6 +3,7 @@ package org.keycloak.services.resources.admin;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.spi.NotFoundException; import org.jboss.resteasy.spi.NotFoundException;
import org.keycloak.constants.KerberosConstants;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.RequiredCredentialModel; import org.keycloak.models.RequiredCredentialModel;
@ -10,9 +11,6 @@ import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserFederationProvider; import org.keycloak.models.UserFederationProvider;
import org.keycloak.models.UserFederationProviderFactory; import org.keycloak.models.UserFederationProviderFactory;
import org.keycloak.models.UserFederationProviderModel; import org.keycloak.models.UserFederationProviderModel;
import org.keycloak.constants.KerberosConstants;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.utils.ModelToRepresentation; import org.keycloak.models.utils.ModelToRepresentation;
import org.keycloak.provider.ProviderFactory; import org.keycloak.provider.ProviderFactory;
import org.keycloak.representations.idm.UserFederationProviderFactoryRepresentation; import org.keycloak.representations.idm.UserFederationProviderFactoryRepresentation;
@ -32,7 +30,6 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -49,18 +46,15 @@ public class UserFederationResource {
protected RealmAuth auth; protected RealmAuth auth;
private EventBuilder event;
@Context @Context
protected UriInfo uriInfo; protected UriInfo uriInfo;
@Context @Context
protected KeycloakSession session; protected KeycloakSession session;
public UserFederationResource(RealmModel realm, RealmAuth auth, EventBuilder event) { public UserFederationResource(RealmModel realm, RealmAuth auth) {
this.auth = auth; this.auth = auth;
this.realm = realm; this.realm = realm;
this.event = event;
auth.init(RealmAuth.Resource.USER); auth.init(RealmAuth.Resource.USER);
} }
@ -83,9 +77,6 @@ public class UserFederationResource {
rep.setOptions(((UserFederationProviderFactory)factory).getConfigurationOptions()); rep.setOptions(((UserFederationProviderFactory)factory).getConfigurationOptions());
providers.add(rep); providers.add(rep);
} }
event.event(EventType.VIEW_FEDERATION_PROVIDERS).representation(providers).success();
return providers; return providers;
} }
@ -107,9 +98,6 @@ public class UserFederationResource {
UserFederationProviderFactoryRepresentation rep = new UserFederationProviderFactoryRepresentation(); UserFederationProviderFactoryRepresentation rep = new UserFederationProviderFactoryRepresentation();
rep.setId(factory.getId()); rep.setId(factory.getId());
rep.setOptions(((UserFederationProviderFactory)factory).getConfigurationOptions()); rep.setOptions(((UserFederationProviderFactory)factory).getConfigurationOptions());
event.event(EventType.VIEW_FEDERATION_PROVIDER).representation(rep).success();
return rep; return rep;
} }
throw new NotFoundException("Could not find provider"); throw new NotFoundException("Could not find provider");
@ -134,11 +122,6 @@ public class UserFederationResource {
rep.getFullSyncPeriod(), rep.getChangedSyncPeriod(), rep.getLastSync()); rep.getFullSyncPeriod(), rep.getChangedSyncPeriod(), rep.getLastSync());
new UsersSyncManager().refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), model, realm.getId()); new UsersSyncManager().refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), model, realm.getId());
checkKerberosCredential(model); checkKerberosCredential(model);
event.event(EventType.CREATE_FEDERATION_PROVIDER)
.representation(rep)
.success();
return Response.created(uriInfo.getAbsolutePathBuilder().path(model.getId()).build()).build(); return Response.created(uriInfo.getAbsolutePathBuilder().path(model.getId()).build()).build();
} }
@ -162,10 +145,6 @@ public class UserFederationResource {
realm.updateUserFederationProvider(model); realm.updateUserFederationProvider(model);
new UsersSyncManager().refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), model, realm.getId()); new UsersSyncManager().refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), model, realm.getId());
checkKerberosCredential(model); checkKerberosCredential(model);
event.event(EventType.UPDATE_FEDERATION_PROVIDER)
.representation(rep)
.success();
} }
/** /**
@ -181,13 +160,7 @@ public class UserFederationResource {
auth.requireView(); auth.requireView();
for (UserFederationProviderModel model : realm.getUserFederationProviders()) { for (UserFederationProviderModel model : realm.getUserFederationProviders()) {
if (model.getId().equals(id)) { if (model.getId().equals(id)) {
UserFederationProviderRepresentation rep = ModelToRepresentation.toRepresentation(model); return ModelToRepresentation.toRepresentation(model);
event.event(EventType.VIEW_FEDERATION_PROVIDER)
.representation(rep)
.success();
return rep;
} }
} }
@ -208,10 +181,6 @@ public class UserFederationResource {
UserFederationProviderModel model = new UserFederationProviderModel(id, null, null, -1, null, -1, -1, 0); UserFederationProviderModel model = new UserFederationProviderModel(id, null, null, -1, null, -1, -1, 0);
realm.removeUserFederationProvider(model); realm.removeUserFederationProvider(model);
new UsersSyncManager().removePeriodicSyncForProvider(session.getProvider(TimerProvider.class), model); new UsersSyncManager().removePeriodicSyncForProvider(session.getProvider(TimerProvider.class), model);
event.event(EventType.DELETE_FEDERATION_PROVIDER)
.representation(rep)
.success();
} }

View file

@ -7,9 +7,6 @@ import org.jboss.resteasy.spi.NotFoundException;
import org.keycloak.ClientConnection; import org.keycloak.ClientConnection;
import org.keycloak.email.EmailException; import org.keycloak.email.EmailException;
import org.keycloak.email.EmailProvider; import org.keycloak.email.EmailProvider;
import org.keycloak.events.Details;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.ApplicationModel; import org.keycloak.models.ApplicationModel;
import org.keycloak.models.ClientModel; import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientSessionModel; import org.keycloak.models.ClientSessionModel;
@ -58,7 +55,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -82,8 +78,6 @@ public class UsersResource {
private TokenManager tokenManager; private TokenManager tokenManager;
private EventBuilder event;
@Context @Context
protected ClientConnection clientConnection; protected ClientConnection clientConnection;
@ -96,11 +90,10 @@ public class UsersResource {
@Context @Context
protected HttpHeaders headers; protected HttpHeaders headers;
public UsersResource(RealmModel realm, RealmAuth auth, TokenManager tokenManager, EventBuilder event) { public UsersResource(RealmModel realm, RealmAuth auth, TokenManager tokenManager) {
this.auth = auth; this.auth = auth;
this.realm = realm; this.realm = realm;
this.tokenManager = tokenManager; this.tokenManager = tokenManager;
this.event = event;
auth.init(RealmAuth.Resource.USER); auth.init(RealmAuth.Resource.USER);
} }
@ -125,10 +118,6 @@ public class UsersResource {
} }
updateUserFromRep(user, rep); updateUserFromRep(user, rep);
event.event(EventType.UPDATE_USER)
.representation(rep)
.success();
if (session.getTransaction().isActive()) { if (session.getTransaction().isActive()) {
session.getTransaction().commit(); session.getTransaction().commit();
} }
@ -165,10 +154,6 @@ public class UsersResource {
UserModel user = session.users().addUser(realm, rep.getUsername()); UserModel user = session.users().addUser(realm, rep.getUsername());
updateUserFromRep(user, rep); updateUserFromRep(user, rep);
event.event(EventType.CREATE_USER)
.representation(rep)
.success();
if (session.getTransaction().isActive()) { if (session.getTransaction().isActive()) {
session.getTransaction().commit(); session.getTransaction().commit();
} }
@ -234,13 +219,7 @@ public class UsersResource {
throw new NotFoundException("User not found"); throw new NotFoundException("User not found");
} }
UserRepresentation rep = ModelToRepresentation.toRepresentation(user); return ModelToRepresentation.toRepresentation(user);
event.event(EventType.VIEW_USER)
.representation(rep)
.success();
return rep;
} }
/** /**
@ -265,11 +244,6 @@ public class UsersResource {
UserSessionRepresentation rep = ModelToRepresentation.toRepresentation(session); UserSessionRepresentation rep = ModelToRepresentation.toRepresentation(session);
reps.add(rep); reps.add(rep);
} }
event.event(EventType.VIEW_USER_SESSIONS)
.representation(reps)
.success();
return reps; return reps;
} }
@ -301,11 +275,6 @@ public class UsersResource {
} }
} }
} }
event.event(EventType.VIEW_USER)
.representation(result)
.success();
return result; return result;
} }
@ -361,9 +330,6 @@ public class UsersResource {
for (UserSessionModel userSession : userSessions) { for (UserSessionModel userSession : userSessions) {
AuthenticationManager.backchannelLogout(session, realm, userSession, uriInfo, clientConnection, headers); AuthenticationManager.backchannelLogout(session, realm, userSession, uriInfo, clientConnection, headers);
} }
event.event(EventType.LOGOUT_USER_SESSIONS)
.success();
} }
/** /**
@ -385,11 +351,6 @@ public class UsersResource {
boolean removed = new UserManager(session).removeUser(realm, user); boolean removed = new UserManager(session).removeUser(realm, user);
if (removed) { if (removed) {
event.event(EventType.DELETE_USER)
.representation(rep)
.success();
return Response.noContent().build(); return Response.noContent().build();
} else { } else {
return Flows.errors().error("User couldn't be deleted", Response.Status.BAD_REQUEST); return Flows.errors().error("User couldn't be deleted", Response.Status.BAD_REQUEST);

View file

@ -29,7 +29,6 @@ import org.keycloak.broker.provider.AuthenticationRequest;
import org.keycloak.broker.provider.FederatedIdentity; import org.keycloak.broker.provider.FederatedIdentity;
import org.keycloak.broker.provider.IdentityBrokerException; import org.keycloak.broker.provider.IdentityBrokerException;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventGroup;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
import org.keycloak.models.ClientModel; import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientSessionModel; import org.keycloak.models.ClientSessionModel;
@ -156,7 +155,7 @@ public class TwitterIdentityProvider extends AbstractIdentityProvider<OAuth2Iden
} catch (Exception e) { } catch (Exception e) {
logger.error("Could get user profile from twitter.", e); logger.error("Could get user profile from twitter.", e);
} }
EventBuilder event = new EventBuilder(EventGroup.USER, realm, session, clientConnection); EventBuilder event = new EventBuilder(realm, session, clientConnection);
event.event(EventType.LOGIN); event.event(EventType.LOGIN);
event.error("twitter_login_failed"); event.error("twitter_login_failed");
return Flows.forwardToSecurityFailurePage(session, realm, uriInfo, headers, Messages.UNEXPECTED_ERROR_HANDLING_RESPONSE); return Flows.forwardToSecurityFailurePage(session, realm, uriInfo, headers, Messages.UNEXPECTED_ERROR_HANDLING_RESPONSE);

View file

@ -6,7 +6,6 @@ import org.junit.Before;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.keycloak.events.Event; import org.keycloak.events.Event;
import org.keycloak.events.EventGroup;
import org.keycloak.events.EventStoreProvider; import org.keycloak.events.EventStoreProvider;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
@ -186,7 +185,6 @@ public class EventStoreProviderTest {
Event e = new Event(); Event e = new Event();
e.setTime(time); e.setTime(time);
e.setType(event); e.setType(event);
e.setGroup(EventGroup.USER);
e.setRealmId(realmId); e.setRealmId(realmId);
e.setClientId(clientId); e.setClientId(clientId);
e.setUserId(userId); e.setUserId(userId);