Merge pull request #1107 from stianst/master
Removed admin audit events - needs a rethink
This commit is contained in:
commit
799c9da1c1
36 changed files with 120 additions and 557 deletions
|
@ -25,7 +25,6 @@ import org.keycloak.broker.provider.FederatedIdentity;
|
|||
import org.keycloak.broker.provider.IdentityBrokerException;
|
||||
import org.keycloak.events.Errors;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.jose.jws.JWSInput;
|
||||
import org.keycloak.models.RealmModel;
|
||||
|
@ -88,14 +87,14 @@ public class OIDCIdentityProvider extends AbstractOAuth2IdentityProvider<OIDCIde
|
|||
UserSessionModel userSession = session.sessions().getUserSession(realm, state);
|
||||
if (userSession == null) {
|
||||
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.error(Errors.USER_SESSION_NOT_FOUND);
|
||||
return Flows.forwardToSecurityFailurePage(session, realm, uriInfo, headers, Messages.IDENTITY_PROVIDER_UNEXPECTED_ERROR);
|
||||
}
|
||||
if (userSession.getState() != UserSessionModel.State.LOGGING_OUT) {
|
||||
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.error(Errors.USER_SESSION_NOT_FOUND);
|
||||
return Flows.forwardToSecurityFailurePage(session, realm, uriInfo, headers, Messages.SESSION_NOT_ACTIVE);
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.keycloak.broker.provider.IdentityProvider;
|
|||
import org.keycloak.events.Details;
|
||||
import org.keycloak.events.Errors;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
|
@ -163,7 +162,7 @@ public class SAMLEndpoint {
|
|||
}
|
||||
|
||||
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);
|
||||
if (response != null) return response;
|
||||
if (samlRequest != null) return handleSamlRequest(samlRequest, relayState);
|
||||
|
|
|
@ -95,10 +95,14 @@ public class MyEventListenerProvider implements EventListenerProvider {
|
|||
<section>
|
||||
<title>Register a provider using Modules</title>
|
||||
<para>
|
||||
To register a provider using Modules first create a module. To do this you have to create a folder inside
|
||||
KEYCLOAK_HOME/modules and add your jar and a <literal>module.xml</literal>. For example to add the event listener
|
||||
sysout example provider create the folder <literal>KEYCLOAK_HOME/modules/org/keycloak/examples/event-sysout/main</literal>.
|
||||
Copy <literal>event-listener-sysout-example.jar</literal> to this folder and create <literal>module.xml</literal>
|
||||
To register a provider using Modules first create a module. To do this you can either use the jboss-cli
|
||||
script or manually create a folder inside KEYCLOAK_HOME/modules and add your jar and a <literal>module.xml</literal>.
|
||||
For example to add the event listener sysout example provider using the jboss-cli script execute:
|
||||
<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:
|
||||
<programlisting><![CDATA[{
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
@ -113,8 +117,10 @@ public class MyEventListenerProvider implements EventListenerProvider {
|
|||
</dependencies>
|
||||
</module>
|
||||
}]]></programlisting>
|
||||
Next you need to register this module with Keycloak. This is done by editing keycloak-server.json and adding
|
||||
it to the providers:
|
||||
</para>
|
||||
<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[{
|
||||
"providers": [
|
||||
...
|
||||
|
|
|
@ -24,9 +24,4 @@ public interface Details {
|
|||
String NODE_HOST = "node_host";
|
||||
String REASON = "reason";
|
||||
|
||||
String REALM = "realm";
|
||||
String REPRESENTATION = "representation";
|
||||
|
||||
String APPLICATION_CLUSTER_NODE = "application_cluster_node";
|
||||
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@ public class Event {
|
|||
|
||||
private EventType type;
|
||||
|
||||
private EventGroup group;
|
||||
|
||||
private String realmId;
|
||||
|
||||
private String clientId;
|
||||
|
@ -26,8 +24,6 @@ public class Event {
|
|||
|
||||
private String error;
|
||||
|
||||
private String representation;
|
||||
|
||||
private Map<String, String> details;
|
||||
|
||||
public long getTime() {
|
||||
|
@ -46,14 +42,6 @@ public class Event {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public EventGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(EventGroup group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public String getRealmId() {
|
||||
return realmId;
|
||||
}
|
||||
|
@ -102,14 +90,6 @@ public class Event {
|
|||
this.error = error;
|
||||
}
|
||||
|
||||
public String getRepresentation() {
|
||||
return representation;
|
||||
}
|
||||
|
||||
public void setRepresentation(String representation) {
|
||||
this.representation = representation;
|
||||
}
|
||||
|
||||
public Map<String, String> getDetails() {
|
||||
return details;
|
||||
}
|
||||
|
@ -122,7 +102,6 @@ public class Event {
|
|||
Event clone = new Event();
|
||||
clone.time = time;
|
||||
clone.type = type;
|
||||
clone.group = group;
|
||||
clone.realmId = realmId;
|
||||
clone.clientId = clientId;
|
||||
clone.userId = userId;
|
||||
|
@ -130,7 +109,6 @@ public class Event {
|
|||
clone.ipAddress = ipAddress;
|
||||
clone.error = error;
|
||||
clone.details = details != null ? new HashMap<>(details) : null;
|
||||
clone.representation = representation;
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,7 @@ import org.keycloak.models.KeycloakSession;
|
|||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.UserSessionModel;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -26,11 +24,10 @@ public class EventBuilder {
|
|||
private RealmModel realm;
|
||||
private Event event;
|
||||
|
||||
public EventBuilder(EventGroup group, RealmModel realm, KeycloakSession session, ClientConnection clientConnection) {
|
||||
public EventBuilder(RealmModel realm, KeycloakSession session, ClientConnection clientConnection) {
|
||||
this.realm = realm;
|
||||
|
||||
event = new Event();
|
||||
event.setGroup(group);
|
||||
|
||||
if (realm.isEventsEnabled()) {
|
||||
EventStoreProvider store = session.getProvider(EventStoreProvider.class);
|
||||
|
@ -126,18 +123,6 @@ public class EventBuilder {
|
|||
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) {
|
||||
if (event.getDetails() != null) {
|
||||
event.getDetails().remove(key);
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package org.keycloak.events;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:giriraj.sharma27@gmail.com">Giriraj Sharma</a>
|
||||
*/
|
||||
public enum EventGroup {
|
||||
|
||||
ADMIN,
|
||||
USER
|
||||
|
||||
}
|
|
@ -60,61 +60,7 @@ public enum EventType {
|
|||
IDENTITY_PROVIDER_RETRIEVE_TOKEN(false),
|
||||
IDENTITY_PROVIDER_RETRIEVE_TOKEN_ERROR(false),
|
||||
IDENTITY_PROVIDER_ACCCOUNT_LINKING(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);
|
||||
IDENTITY_PROVIDER_ACCCOUNT_LINKING_ERROR(false);
|
||||
|
||||
private boolean saveByDefault;
|
||||
|
||||
|
|
|
@ -23,9 +23,6 @@ public class EventEntity {
|
|||
@Column(name="TYPE")
|
||||
private String type;
|
||||
|
||||
@Column(name="EVENT_GROUP")
|
||||
private String group;
|
||||
|
||||
@Column(name="REALM_ID")
|
||||
private String realmId;
|
||||
|
||||
|
@ -47,10 +44,6 @@ public class EventEntity {
|
|||
@Column(name="DETAILS_JSON", length = 2550)
|
||||
private String detailsJson;
|
||||
|
||||
@Column(name="REPRESENTATION")
|
||||
@Lob
|
||||
private String representation;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -75,14 +68,6 @@ public class EventEntity {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public String getRealmId() {
|
||||
return realmId;
|
||||
}
|
||||
|
@ -139,11 +124,4 @@ public class EventEntity {
|
|||
this.detailsJson = detailsJson;
|
||||
}
|
||||
|
||||
public String getRepresentation() {
|
||||
return representation;
|
||||
}
|
||||
|
||||
public void setRepresentation(String representation) {
|
||||
this.representation = representation;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,11 @@ import org.codehaus.jackson.map.ObjectMapper;
|
|||
import org.codehaus.jackson.type.TypeReference;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.events.Event;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.events.EventQuery;
|
||||
import org.keycloak.events.EventStoreProvider;
|
||||
import org.keycloak.events.EventType;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -65,14 +63,12 @@ public class JpaEventStoreProvider implements EventStoreProvider {
|
|||
e.setId(UUID.randomUUID().toString());
|
||||
e.setTime(o.getTime());
|
||||
e.setType(o.getType().toString());
|
||||
e.setGroup(o.getGroup().toString());
|
||||
e.setRealmId(o.getRealmId());
|
||||
e.setClientId(o.getClientId());
|
||||
e.setUserId(o.getUserId());
|
||||
e.setSessionId(o.getSessionId());
|
||||
e.setIpAddress(o.getIpAddress());
|
||||
e.setError(o.getError());
|
||||
e.setRepresentation(o.getRepresentation());
|
||||
try {
|
||||
e.setDetailsJson(mapper.writeValueAsString(o.getDetails()));
|
||||
} catch (IOException ex) {
|
||||
|
@ -85,14 +81,12 @@ public class JpaEventStoreProvider implements EventStoreProvider {
|
|||
Event e = new Event();
|
||||
e.setTime(o.getTime());
|
||||
e.setType(EventType.valueOf(o.getType()));
|
||||
e.setGroup(EventGroup.valueOf(o.getGroup()));
|
||||
e.setRealmId(o.getRealmId());
|
||||
e.setClientId(o.getClientId());
|
||||
e.setUserId(o.getUserId());
|
||||
e.setSessionId(o.getSessionId());
|
||||
e.setIpAddress(o.getIpAddress());
|
||||
e.setError(o.getError());
|
||||
e.setRepresentation(o.getRepresentation());
|
||||
try {
|
||||
Map<String, String> details = mapper.readValue(o.getDetailsJson(), mapType);
|
||||
e.setDetails(details);
|
||||
|
|
|
@ -3,9 +3,7 @@ package org.keycloak.events.mongo;
|
|||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBObject;
|
||||
|
||||
import org.keycloak.events.Event;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.events.EventQuery;
|
||||
import org.keycloak.events.EventStoreProvider;
|
||||
import org.keycloak.events.EventType;
|
||||
|
@ -60,14 +58,12 @@ public class MongoEventStoreProvider implements EventStoreProvider {
|
|||
BasicDBObject e = new BasicDBObject();
|
||||
e.put("time", o.getTime());
|
||||
e.put("type", o.getType().toString());
|
||||
e.put("group", o.getGroup().toString());
|
||||
e.put("realmId", o.getRealmId());
|
||||
e.put("clientId", o.getClientId());
|
||||
e.put("userId", o.getUserId());
|
||||
e.put("sessionId", o.getSessionId());
|
||||
e.put("ipAddress", o.getIpAddress());
|
||||
e.put("error", o.getError());
|
||||
e.put("representation", o.getRepresentation());
|
||||
|
||||
BasicDBObject details = new BasicDBObject();
|
||||
if (o.getDetails() != null) {
|
||||
|
@ -84,14 +80,12 @@ public class MongoEventStoreProvider implements EventStoreProvider {
|
|||
Event e = new Event();
|
||||
e.setTime(o.getLong("time"));
|
||||
e.setType(EventType.valueOf(o.getString("type")));
|
||||
e.setGroup(EventGroup.valueOf(o.getString("group")));
|
||||
e.setRealmId(o.getString("realmId"));
|
||||
e.setClientId(o.getString("clientId"));
|
||||
e.setUserId(o.getString("userId"));
|
||||
e.setSessionId(o.getString("sessionId"));
|
||||
e.setIpAddress(o.getString("ipAddress"));
|
||||
e.setError(o.getString("error"));
|
||||
e.setRepresentation(o.getString("representation"));
|
||||
|
||||
BasicDBObject d = (BasicDBObject) o.get("details");
|
||||
if (d != null) {
|
||||
|
|
|
@ -7,13 +7,9 @@ import org.keycloak.Config;
|
|||
import org.keycloak.connections.mongo.MongoConnectionProvider;
|
||||
import org.keycloak.events.EventStoreProvider;
|
||||
import org.keycloak.events.EventStoreProviderFactory;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package org.keycloak.events.log;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.keycloak.events.Event;
|
||||
import org.keycloak.events.EventListenerProvider;
|
||||
import org.productivity.java.syslog4j.SyslogConstants;
|
||||
import org.productivity.java.syslog4j.SyslogIF;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:giriraj.sharma27@gmail.com">Giriraj Sharma</a>
|
||||
*/
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.keycloak.OAuthErrorException;
|
|||
import org.keycloak.RSATokenVerifier;
|
||||
import org.keycloak.events.Details;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
|
@ -111,7 +110,7 @@ public class UserInfoEndpoint {
|
|||
}
|
||||
|
||||
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)
|
||||
.detail(Details.AUTH_METHOD, Details.VALIDATE_ACCESS_TOKEN);
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.keycloak.VerificationException;
|
|||
import org.keycloak.broker.provider.IdentityProvider;
|
||||
import org.keycloak.events.Details;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.jose.jws.JWSBuilder;
|
||||
import org.keycloak.login.LoginFormsProvider;
|
||||
|
@ -46,10 +45,10 @@ import javax.ws.rs.core.Response;
|
|||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Stateless object that manages authentication
|
||||
|
@ -182,7 +181,7 @@ public class AuthenticationManager {
|
|||
expireRememberMeCookie(realm, uriInfo, connection);
|
||||
userSession.setState(UserSessionModel.State.LOGGED_OUT);
|
||||
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);
|
||||
protocol.setRealm(realm)
|
||||
.setHttpHeaders(headers)
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.keycloak.broker.provider.IdentityProviderFactory;
|
|||
import org.keycloak.events.Details;
|
||||
import org.keycloak.events.Errors;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
|
@ -59,8 +58,14 @@ import javax.ws.rs.POST;
|
|||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
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.UriBuilder;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -109,7 +114,7 @@ public class IdentityBrokerService implements IdentityProvider.AuthenticationCal
|
|||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -29,12 +29,20 @@ import org.keycloak.email.EmailProvider;
|
|||
import org.keycloak.events.Details;
|
||||
import org.keycloak.events.Errors;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.jose.jws.JWSBuilder;
|
||||
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.UserSessionModel;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
import org.keycloak.models.utils.TimeBasedOTP;
|
||||
import org.keycloak.protocol.LoginProtocol;
|
||||
|
@ -538,7 +546,7 @@ public class LoginActionsService {
|
|||
AttributeFormDataProcessor.process(formData, realm, user);
|
||||
|
||||
event.user(user).success();
|
||||
event = new EventBuilder(EventGroup.USER, realm, session, clientConnection);
|
||||
event = new EventBuilder(realm, session, clientConnection);
|
||||
|
||||
return processLogin(code, formData);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import org.jboss.resteasy.spi.NotFoundException;
|
|||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.keycloak.ClientConnection;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
|
@ -91,7 +90,7 @@ public class RealmsResource {
|
|||
// backward compatibility
|
||||
RealmManager realmManager = new RealmManager(session);
|
||||
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);
|
||||
|
||||
LoginProtocolFactory factory = (LoginProtocolFactory)session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, OIDCLoginProtocol.LOGIN_PROTOCOL);
|
||||
|
@ -107,7 +106,7 @@ public class RealmsResource {
|
|||
final @PathParam("protocol") String protocol) {
|
||||
RealmManager realmManager = new RealmManager(session);
|
||||
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);
|
||||
|
||||
LoginProtocolFactory factory = (LoginProtocolFactory)session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, protocol);
|
||||
|
@ -129,7 +128,7 @@ public class RealmsResource {
|
|||
public LoginActionsService getLoginActionsService(final @PathParam("realm") String name) {
|
||||
RealmManager realmManager = new RealmManager(session);
|
||||
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);
|
||||
LoginActionsService service = new LoginActionsService(realm, authManager, event);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(service);
|
||||
|
@ -142,7 +141,7 @@ public class RealmsResource {
|
|||
public ClientsManagementService getClientsManagementService(final @PathParam("realm") String name) {
|
||||
RealmManager realmManager = new RealmManager(session);
|
||||
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);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(service);
|
||||
return service;
|
||||
|
@ -168,7 +167,7 @@ public class RealmsResource {
|
|||
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);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(accountService);
|
||||
//resourceContext.initResource(accountService);
|
||||
|
|
|
@ -8,8 +8,6 @@ import org.jboss.resteasy.spi.NotFoundException;
|
|||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.jboss.resteasy.spi.UnauthorizedException;
|
||||
import org.keycloak.ClientConnection;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.jose.jws.JWSInput;
|
||||
import org.keycloak.models.ClientModel;
|
||||
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.UriBuilder;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
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);
|
||||
|
||||
EventBuilder event = new EventBuilder(EventGroup.ADMIN, auth.getRealm(), session, clientConnection);
|
||||
event.user(auth.getUser()).client(auth.getClient());
|
||||
|
||||
RealmsAdminResource adminResource = new RealmsAdminResource(auth, tokenManager, event);
|
||||
RealmsAdminResource adminResource = new RealmsAdminResource(auth, tokenManager);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(adminResource);
|
||||
return adminResource;
|
||||
}
|
||||
|
|
|
@ -5,9 +5,6 @@ import org.jboss.resteasy.annotations.cache.NoCache;
|
|||
import org.jboss.resteasy.spi.BadRequestException;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
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.KeycloakSession;
|
||||
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.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -61,7 +57,6 @@ public class ApplicationResource {
|
|||
protected static final Logger logger = Logger.getLogger(ApplicationResource.class);
|
||||
protected RealmModel realm;
|
||||
private RealmAuth auth;
|
||||
private EventBuilder event;
|
||||
protected ApplicationModel application;
|
||||
protected KeycloakSession session;
|
||||
|
||||
|
@ -72,15 +67,14 @@ public class ApplicationResource {
|
|||
protected KeycloakApplication keycloak;
|
||||
|
||||
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.auth = auth;
|
||||
this.application = applicationModel;
|
||||
this.session = session;
|
||||
this.event = event;
|
||||
|
||||
auth.init(RealmAuth.Resource.APPLICATION);
|
||||
}
|
||||
|
@ -89,7 +83,6 @@ public class ApplicationResource {
|
|||
public ProtocolMappersResource getProtocolMappers() {
|
||||
ProtocolMappersResource mappers = new ProtocolMappersResource(application, auth);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(mappers);
|
||||
//resourceContext.initResource(mappers);
|
||||
return mappers;
|
||||
}
|
||||
|
||||
|
@ -105,9 +98,6 @@ public class ApplicationResource {
|
|||
|
||||
try {
|
||||
RepresentationToModel.updateApplication(rep, application);
|
||||
|
||||
event.event(EventType.UPDATE_APPLICATION).representation(rep).success();
|
||||
|
||||
return Response.noContent().build();
|
||||
} catch (ModelDuplicateException e) {
|
||||
return Flows.errors().exists("Application " + rep.getName() + " already exists");
|
||||
|
@ -126,11 +116,7 @@ public class ApplicationResource {
|
|||
public ApplicationRepresentation getApplication() {
|
||||
auth.requireView();
|
||||
|
||||
ApplicationRepresentation rep = ModelToRepresentation.toRepresentation(application);
|
||||
|
||||
event.event(EventType.VIEW_APPLICATION).representation(rep).success();
|
||||
|
||||
return rep;
|
||||
return ModelToRepresentation.toRepresentation(application);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,7 +126,7 @@ public class ApplicationResource {
|
|||
*/
|
||||
@Path("certificates/{attr}")
|
||||
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
|
||||
public void deleteApplication() {
|
||||
auth.requireManage();
|
||||
|
||||
ApplicationRepresentation rep = getApplication();
|
||||
event.event(EventType.DELETE_APPLICATION).representation(rep).success();
|
||||
|
||||
new ApplicationManager(new RealmManager(session)).removeApplication(realm, application);
|
||||
}
|
||||
|
||||
|
@ -245,7 +227,7 @@ public class ApplicationResource {
|
|||
|
||||
@Path("roles")
|
||||
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);
|
||||
sessions.add(rep);
|
||||
}
|
||||
|
||||
event.event(EventType.VIEW_APPLICATION_USER_SESSIONS).representation(sessions).success();
|
||||
|
||||
return sessions;
|
||||
}
|
||||
|
||||
|
@ -362,9 +341,6 @@ public class ApplicationResource {
|
|||
@POST
|
||||
public GlobalRequestResult logoutAll() {
|
||||
auth.requireManage();
|
||||
|
||||
event.event(EventType.LOGOUT_APPLICATION_USERS).success();
|
||||
|
||||
return new ResourceAdminManager().logoutApplication(uriInfo.getRequestUri(), realm, application);
|
||||
}
|
||||
|
||||
|
@ -380,9 +356,6 @@ public class ApplicationResource {
|
|||
if (user == null) {
|
||||
throw new NotFoundException("User not found");
|
||||
}
|
||||
|
||||
event.event(EventType.LOGOUT_USER).success();
|
||||
|
||||
new ResourceAdminManager().logoutUserFromApplication(uriInfo.getRequestUri(), realm, application, user, session);
|
||||
}
|
||||
|
||||
|
@ -403,10 +376,6 @@ public class ApplicationResource {
|
|||
}
|
||||
if (logger.isDebugEnabled()) logger.debug("Register node: " + node);
|
||||
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);
|
||||
|
||||
event.event(EventType.UNREGISTER_APPLICATION_CLUSTER_NODE)
|
||||
.detail(Details.APPLICATION_CLUSTER_NODE, node)
|
||||
.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
|
||||
|
@ -9,8 +8,8 @@ import org.keycloak.models.RealmModel;
|
|||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class ApplicationsByIdResource extends ApplicationsResource {
|
||||
public ApplicationsByIdResource(RealmModel realm, RealmAuth auth, EventBuilder event) {
|
||||
super(realm, auth, event);
|
||||
public ApplicationsByIdResource(RealmModel realm, RealmAuth auth) {
|
||||
super(realm, auth);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,8 +4,6 @@ import org.jboss.logging.Logger;
|
|||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
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.KeycloakSession;
|
||||
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.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -39,15 +36,13 @@ public class ApplicationsResource {
|
|||
protected static final Logger logger = Logger.getLogger(RealmAdminResource.class);
|
||||
protected RealmModel realm;
|
||||
private RealmAuth auth;
|
||||
private EventBuilder event;
|
||||
|
||||
@Context
|
||||
protected KeycloakSession session;
|
||||
|
||||
public ApplicationsResource(RealmModel realm, RealmAuth auth, EventBuilder event) {
|
||||
public ApplicationsResource(RealmModel realm, RealmAuth auth) {
|
||||
this.realm = realm;
|
||||
this.auth = auth;
|
||||
this.event = event;
|
||||
|
||||
auth.init(RealmAuth.Resource.APPLICATION);
|
||||
}
|
||||
|
@ -77,8 +72,6 @@ public class ApplicationsResource {
|
|||
}
|
||||
}
|
||||
|
||||
event.event(EventType.VIEW_APPLICATIONS).representation(rep).success();
|
||||
|
||||
return rep;
|
||||
}
|
||||
|
||||
|
@ -96,9 +89,6 @@ public class ApplicationsResource {
|
|||
|
||||
try {
|
||||
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();
|
||||
} catch (ModelDuplicateException e) {
|
||||
return Flows.errors().exists("Application " + rep.getName() + " already exists");
|
||||
|
@ -121,7 +111,7 @@ public class ApplicationsResource {
|
|||
if (applicationModel == null) {
|
||||
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);
|
||||
//resourceContext.initResource(applicationResource);
|
||||
return applicationResource;
|
||||
|
|
|
@ -23,7 +23,6 @@ import javax.ws.rs.Produces;
|
|||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -48,14 +47,13 @@ public class ClientAttributeCertificateResource {
|
|||
|
||||
protected RealmModel realm;
|
||||
private RealmAuth auth;
|
||||
private EventBuilder event;
|
||||
protected ClientModel client;
|
||||
protected KeycloakSession session;
|
||||
protected String attributePrefix;
|
||||
protected String privateAttribute;
|
||||
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.auth = auth;
|
||||
this.client = client;
|
||||
|
@ -63,7 +61,6 @@ public class ClientAttributeCertificateResource {
|
|||
this.attributePrefix = attributePrefix;
|
||||
this.privateAttribute = attributePrefix + "." + PRIVATE_KEY;
|
||||
this.certificateAttribute = attributePrefix + "." + X509CERTIFICATE;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public static class ClientKeyPairInfo {
|
||||
|
@ -99,9 +96,6 @@ public class ClientAttributeCertificateResource {
|
|||
ClientKeyPairInfo info = new ClientKeyPairInfo();
|
||||
info.setCertificate(client.getAttribute(certificateAttribute));
|
||||
info.setPrivateKey(client.getAttribute(privateAttribute));
|
||||
|
||||
event.event(EventType.VIEW_CLIENT_CERTIFICATE).representation(info).success();
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -140,9 +134,6 @@ public class ClientAttributeCertificateResource {
|
|||
ClientKeyPairInfo info = new ClientKeyPairInfo();
|
||||
info.setCertificate(client.getAttribute(certificateAttribute));
|
||||
info.setPrivateKey(client.getAttribute(privateAttribute));
|
||||
|
||||
event.event(EventType.UPDATE_CLIENT_CERTIFICATE).representation(info).success();
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -200,8 +191,6 @@ public class ClientAttributeCertificateResource {
|
|||
info.setCertificate(certPem);
|
||||
}
|
||||
|
||||
event.event(EventType.UPDATE_CLIENT_CERTIFICATE).representation(info).success();
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -327,9 +316,6 @@ public class ClientAttributeCertificateResource {
|
|||
stream.flush();
|
||||
stream.close();
|
||||
byte[] rtn = stream.toByteArray();
|
||||
|
||||
event.event(EventType.VIEW_CLIENT_CERTIFICATE).representation(rtn).success();
|
||||
|
||||
return rtn;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -4,8 +4,6 @@ import org.jboss.logging.Logger;
|
|||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.keycloak.broker.provider.IdentityProvider;
|
||||
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.ClientModel;
|
||||
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.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -46,14 +43,12 @@ public class IdentityProviderResource {
|
|||
private final RealmModel realm;
|
||||
private final KeycloakSession session;
|
||||
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.session = session;
|
||||
this.identityProviderModel = identityProviderModel;
|
||||
this.auth = auth;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
@GET
|
||||
|
@ -62,10 +57,6 @@ public class IdentityProviderResource {
|
|||
public IdentityProviderRepresentation getIdentityProvider() {
|
||||
IdentityProviderRepresentation rep = ModelToRepresentation.toRepresentation(this.identityProviderModel);
|
||||
|
||||
event.event(EventType.VIEW_IDENTITY_PROVIDER)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return rep;
|
||||
}
|
||||
|
||||
|
@ -74,17 +65,11 @@ public class IdentityProviderResource {
|
|||
public Response delete() {
|
||||
this.auth.requireManage();
|
||||
|
||||
IdentityProviderRepresentation rep = getIdentityProvider();
|
||||
|
||||
removeClientIdentityProviders(this.realm.getApplications(), this.identityProviderModel);
|
||||
removeClientIdentityProviders(this.realm.getOAuthClients(), this.identityProviderModel);
|
||||
|
||||
this.realm.removeIdentityProviderByAlias(this.identityProviderModel.getAlias());
|
||||
|
||||
event.event(EventType.DELETE_IDENTITY_PROVIDER)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return Response.noContent().build();
|
||||
}
|
||||
|
||||
|
@ -110,10 +95,6 @@ public class IdentityProviderResource {
|
|||
updateUsersAfterProviderAliasChange(this.session.users().getUsers(this.realm), oldProviderId, newProviderId);
|
||||
}
|
||||
|
||||
event.event(EventType.UPDATE_IDENTITY_PROVIDER)
|
||||
.representation(providerRep)
|
||||
.success();
|
||||
|
||||
return Response.noContent().build();
|
||||
} catch (ModelDuplicateException e) {
|
||||
return Flows.errors().exists("Identity Provider " + providerRep.getAlias() + " already exists");
|
||||
|
|
|
@ -8,8 +8,6 @@ import org.jboss.resteasy.spi.NotFoundException;
|
|||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.keycloak.broker.provider.IdentityProvider;
|
||||
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.KeycloakSession;
|
||||
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.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
@ -49,13 +46,11 @@ public class IdentityProvidersResource {
|
|||
private final RealmModel realm;
|
||||
private final KeycloakSession session;
|
||||
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.session = session;
|
||||
this.auth = auth;
|
||||
this.event = event;
|
||||
this.auth.init(RealmAuth.Resource.IDENTITY_PROVIDER);
|
||||
}
|
||||
|
||||
|
@ -68,10 +63,6 @@ public class IdentityProvidersResource {
|
|||
IdentityProviderFactory providerFactory = getProviderFactorytById(providerId);
|
||||
|
||||
if (providerFactory != null) {
|
||||
event.event(EventType.VIEW_IDENTITY_PROVIDERS)
|
||||
.representation(providerFactory)
|
||||
.success();
|
||||
|
||||
return Response.ok(providerFactory).build();
|
||||
}
|
||||
|
||||
|
@ -90,11 +81,6 @@ public class IdentityProvidersResource {
|
|||
InputStream inputStream = file.getBody(InputStream.class, null);
|
||||
IdentityProviderFactory providerFactory = getProviderFactorytById(providerId);
|
||||
Map<String, String> config = providerFactory.parseConfig(inputStream);
|
||||
|
||||
event.event(EventType.CREATE_IDENTITY_PROVIDER)
|
||||
.representation(config)
|
||||
.success();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@ -116,11 +102,6 @@ public class IdentityProvidersResource {
|
|||
}
|
||||
IdentityProviderFactory providerFactory = getProviderFactorytById(providerId);
|
||||
Map<String, String> config = providerFactory.parseConfig(inputStream);
|
||||
|
||||
event.event(EventType.CREATE_IDENTITY_PROVIDER)
|
||||
.representation(config)
|
||||
.success();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@ -137,8 +118,6 @@ public class IdentityProvidersResource {
|
|||
representations.add(ModelToRepresentation.toRepresentation(identityProviderModel));
|
||||
}
|
||||
|
||||
event.event(EventType.VIEW_IDENTITY_PROVIDERS).representation(representations).success();
|
||||
|
||||
return representations;
|
||||
}
|
||||
|
||||
|
@ -151,10 +130,6 @@ public class IdentityProvidersResource {
|
|||
try {
|
||||
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();
|
||||
} catch (ModelDuplicateException e) {
|
||||
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);
|
||||
}
|
||||
|
||||
IdentityProviderResource identityProviderResource = new IdentityProviderResource(this.auth, realm, session, identityProviderModel, event);
|
||||
IdentityProviderResource identityProviderResource = new IdentityProviderResource(this.auth, realm, session, identityProviderModel);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(identityProviderResource);
|
||||
|
||||
event.event(EventType.VIEW_IDENTITY_PROVIDER)
|
||||
.representation(identityProviderResource)
|
||||
.success();
|
||||
|
||||
return identityProviderResource;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@ import org.jboss.logging.Logger;
|
|||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
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.ModelDuplicateException;
|
||||
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.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
|
@ -46,7 +43,6 @@ public class OAuthClientResource {
|
|||
protected static final Logger logger = Logger.getLogger(RealmAdminResource.class);
|
||||
protected RealmModel realm;
|
||||
private RealmAuth auth;
|
||||
private EventBuilder event;
|
||||
protected OAuthClientModel oauthClient;
|
||||
protected KeycloakSession session;
|
||||
@Context
|
||||
|
@ -59,12 +55,11 @@ public class OAuthClientResource {
|
|||
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.auth = auth;
|
||||
this.oauthClient = oauthClient;
|
||||
this.session = session;
|
||||
this.event = event;
|
||||
|
||||
auth.init(RealmAuth.Resource.CLIENT);
|
||||
}
|
||||
|
@ -89,7 +84,7 @@ public class OAuthClientResource {
|
|||
*/
|
||||
@Path("certificates/{attr}")
|
||||
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 {
|
||||
RepresentationToModel.updateOAuthClient(session, rep, oauthClient);
|
||||
event.event(EventType.UPDATE_OAUTH_CLIENT).representation(rep).success();
|
||||
|
||||
return Response.noContent().build();
|
||||
} catch (ModelDuplicateException e) {
|
||||
return Flows.errors().exists("Client " + rep.getName() + " already exists");
|
||||
|
@ -126,11 +119,7 @@ public class OAuthClientResource {
|
|||
public OAuthClientRepresentation getOAuthClient() {
|
||||
auth.requireView();
|
||||
|
||||
OAuthClientRepresentation rep = ModelToRepresentation.toRepresentation(oauthClient);
|
||||
|
||||
event.event(EventType.VIEW_OAUTH_CLIENT).representation(rep).success();
|
||||
|
||||
return rep;
|
||||
return ModelToRepresentation.toRepresentation(oauthClient);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,10 +151,6 @@ public class OAuthClientResource {
|
|||
public void deleteOAuthClient() {
|
||||
auth.requireManage();
|
||||
|
||||
OAuthClientRepresentation rep = getOAuthClient();
|
||||
|
||||
event.event(EventType.DELETE_OAUTH_CLIENT).representation(rep).success();
|
||||
|
||||
new OAuthClientManager(new RealmManager(session)).removeClient(realm, oauthClient);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
|
@ -10,8 +9,8 @@ import org.keycloak.models.RealmModel;
|
|||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class OAuthClientsByIdResource extends OAuthClientsResource {
|
||||
public OAuthClientsByIdResource(RealmModel realm, RealmAuth auth, KeycloakSession session, EventBuilder event) {
|
||||
super(realm, auth, session, event);
|
||||
public OAuthClientsByIdResource(RealmModel realm, RealmAuth auth, KeycloakSession session) {
|
||||
super(realm, auth, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,8 +4,6 @@ import org.jboss.logging.Logger;
|
|||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
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.ModelDuplicateException;
|
||||
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.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -36,21 +33,13 @@ import java.util.List;
|
|||
public class OAuthClientsResource {
|
||||
protected static final Logger logger = Logger.getLogger(RealmAdminResource.class);
|
||||
protected RealmModel realm;
|
||||
private EventBuilder event;
|
||||
protected KeycloakSession session;
|
||||
|
||||
/*
|
||||
@Context
|
||||
protected ResourceContext resourceContext;
|
||||
|
||||
*/
|
||||
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.realm = realm;
|
||||
this.session = session;
|
||||
this.event = event;
|
||||
|
||||
auth.init(RealmAuth.Resource.CLIENT);
|
||||
}
|
||||
|
@ -78,8 +67,6 @@ public class OAuthClientsResource {
|
|||
}
|
||||
}
|
||||
|
||||
event.event(EventType.VIEW_OAUTH_CLIENTS).representation(rep).success();
|
||||
|
||||
return rep;
|
||||
}
|
||||
|
||||
|
@ -97,8 +84,6 @@ public class OAuthClientsResource {
|
|||
|
||||
try {
|
||||
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();
|
||||
} catch (ModelDuplicateException e) {
|
||||
return Flows.errors().exists("Client " + rep.getName() + " already exists");
|
||||
|
@ -123,7 +108,7 @@ public class OAuthClientsResource {
|
|||
if (oauth == null) {
|
||||
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);
|
||||
//resourceContext.initResource(oAuthClientResource);
|
||||
return oAuthClientResource;
|
||||
|
|
|
@ -1,32 +1,11 @@
|
|||
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.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.keycloak.ClientConnection;
|
||||
import org.keycloak.events.Event;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventQuery;
|
||||
import org.keycloak.events.EventStoreProvider;
|
||||
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.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
|
||||
*
|
||||
|
@ -64,7 +62,6 @@ public class RealmAdminResource {
|
|||
protected RealmAuth auth;
|
||||
protected RealmModel realm;
|
||||
private TokenManager tokenManager;
|
||||
private EventBuilder event;
|
||||
|
||||
@Context
|
||||
protected KeycloakSession session;
|
||||
|
@ -78,11 +75,10 @@ public class RealmAdminResource {
|
|||
@Context
|
||||
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.realm = realm;
|
||||
this.tokenManager = tokenManager;
|
||||
this.event = event;
|
||||
|
||||
auth.init(RealmAuth.Resource.REALM);
|
||||
}
|
||||
|
@ -105,7 +101,7 @@ public class RealmAdminResource {
|
|||
*/
|
||||
@Path("applications")
|
||||
public ApplicationsResource getApplications() {
|
||||
ApplicationsResource applicationsResource = new ApplicationsResource(realm, auth, event);
|
||||
ApplicationsResource applicationsResource = new ApplicationsResource(realm, auth);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(applicationsResource);
|
||||
//resourceContext.initResource(applicationsResource);
|
||||
return applicationsResource;
|
||||
|
@ -118,7 +114,7 @@ public class RealmAdminResource {
|
|||
*/
|
||||
@Path("applications-by-id")
|
||||
public ApplicationsByIdResource getApplicationsById() {
|
||||
ApplicationsByIdResource applicationsResource = new ApplicationsByIdResource(realm, auth, event);
|
||||
ApplicationsByIdResource applicationsResource = new ApplicationsByIdResource(realm, auth);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(applicationsResource);
|
||||
//resourceContext.initResource(applicationsResource);
|
||||
return applicationsResource;
|
||||
|
@ -131,7 +127,7 @@ public class RealmAdminResource {
|
|||
*/
|
||||
@Path("oauth-clients")
|
||||
public OAuthClientsResource getOAuthClients() {
|
||||
OAuthClientsResource oauth = new OAuthClientsResource(realm, auth, session, event);
|
||||
OAuthClientsResource oauth = new OAuthClientsResource(realm, auth, session);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(oauth);
|
||||
//resourceContext.initResource(oauth);
|
||||
return oauth;
|
||||
|
@ -144,7 +140,7 @@ public class RealmAdminResource {
|
|||
*/
|
||||
@Path("oauth-clients-by-id")
|
||||
public OAuthClientsByIdResource getOAuthClientsById() {
|
||||
OAuthClientsByIdResource oauth = new OAuthClientsByIdResource(realm, auth, session, event);
|
||||
OAuthClientsByIdResource oauth = new OAuthClientsByIdResource(realm, auth, session);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(oauth);
|
||||
//resourceContext.initResource(oauth);
|
||||
return oauth;
|
||||
|
@ -157,7 +153,7 @@ public class RealmAdminResource {
|
|||
*/
|
||||
@Path("roles")
|
||||
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();
|
||||
rep.setUserCacheEnabled(cache.isEnabled());
|
||||
}
|
||||
|
||||
event.event(EventType.VIEW_REALM).representation(rep).success();
|
||||
|
||||
return rep;
|
||||
} else {
|
||||
auth.requireAny();
|
||||
|
||||
RealmRepresentation rep = new RealmRepresentation();
|
||||
rep.setRealm(realm.getName());
|
||||
|
||||
event.event(EventType.VIEW_REALM).representation(rep).success();
|
||||
|
||||
return rep;
|
||||
}
|
||||
}
|
||||
|
@ -227,8 +217,6 @@ public class RealmAdminResource {
|
|||
usersSyncManager.refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), fedProvider, realm.getId());
|
||||
}
|
||||
|
||||
event.event(EventType.UPDATE_REALM).representation(rep).success();
|
||||
|
||||
return Response.noContent().build();
|
||||
} catch (ModelDuplicateException e) {
|
||||
return Flows.errors().exists("Realm " + rep.getRealm() + " already exists");
|
||||
|
@ -243,13 +231,9 @@ public class RealmAdminResource {
|
|||
public void deleteRealm() {
|
||||
auth.requireManage();
|
||||
|
||||
RealmRepresentation rep = getRealm();
|
||||
|
||||
if (!new RealmManager(session).removeRealm(realm)) {
|
||||
throw new NotFoundException("Realm doesn't exist");
|
||||
}
|
||||
|
||||
event.event(EventType.DELETE_REALM).representation(rep).success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -259,7 +243,7 @@ public class RealmAdminResource {
|
|||
*/
|
||||
@Path("users")
|
||||
public UsersResource users() {
|
||||
UsersResource users = new UsersResource(realm, auth, tokenManager, event);
|
||||
UsersResource users = new UsersResource(realm, auth, tokenManager);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(users);
|
||||
//resourceContext.initResource(users);
|
||||
return users;
|
||||
|
@ -267,7 +251,7 @@ public class RealmAdminResource {
|
|||
|
||||
@Path("user-federation")
|
||||
public UserFederationResource userFederation() {
|
||||
UserFederationResource fed = new UserFederationResource(realm, auth, event);
|
||||
UserFederationResource fed = new UserFederationResource(realm, auth);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(fed);
|
||||
//resourceContext.initResource(fed);
|
||||
return fed;
|
||||
|
@ -280,7 +264,7 @@ public class RealmAdminResource {
|
|||
*/
|
||||
@Path("roles-by-id")
|
||||
public RoleByIdResource rolesById() {
|
||||
RoleByIdResource resource = new RoleByIdResource(realm, auth, event);
|
||||
RoleByIdResource resource = new RoleByIdResource(realm, auth);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(resource);
|
||||
//resourceContext.initResource(resource);
|
||||
return resource;
|
||||
|
@ -487,6 +471,6 @@ public class RealmAdminResource {
|
|||
|
||||
@Path("identity-provider")
|
||||
public IdentityProvidersResource getIdentityProviderResource() {
|
||||
return new IdentityProvidersResource(realm, session, this.auth, event);
|
||||
return new IdentityProvidersResource(realm, session, this.auth);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,9 @@ import org.jboss.logging.Logger;
|
|||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.plugins.providers.multipart.InputPart;
|
||||
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.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.ApplicationModel;
|
||||
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.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
|
@ -53,12 +50,16 @@ public class RealmsAdminResource {
|
|||
protected static final Logger logger = Logger.getLogger(RealmsAdminResource.class);
|
||||
protected AdminAuth auth;
|
||||
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.tokenManager = tokenManager;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public static final CacheControl noCache = new CacheControl();
|
||||
|
@ -67,17 +68,6 @@ public class RealmsAdminResource {
|
|||
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.
|
||||
*
|
||||
|
@ -102,7 +92,6 @@ public class RealmsAdminResource {
|
|||
return reps;
|
||||
}
|
||||
|
||||
|
||||
protected void addRealmRep(List<RealmRepresentation> reps, RealmModel realm, ApplicationModel realmManagementApplication) {
|
||||
if (auth.hasAppRole(realmManagementApplication, AdminRoles.MANAGE_REALM)) {
|
||||
reps.add(ModelToRepresentation.toRepresentation(realm, false));
|
||||
|
@ -141,10 +130,6 @@ public class RealmsAdminResource {
|
|||
URI location = AdminRoot.realmsUrl(uriInfo).path(realm.getName()).build();
|
||||
logger.debugv("imported realm success, sending back: {0}", location.toString());
|
||||
|
||||
event.event(EventType.CREATE_REALM)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return Response.created(location).build();
|
||||
} catch (ModelDuplicateException e) {
|
||||
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();
|
||||
return Response.created(location).build();
|
||||
}
|
||||
|
||||
event.event(EventType.CREATE_REALM).representation(rep).success();
|
||||
}
|
||||
|
||||
return Response.noContent().build();
|
||||
|
@ -237,8 +220,7 @@ public class RealmsAdminResource {
|
|||
realmAuth = new RealmAuth(auth, realm.getApplicationByName(realmManager.getRealmAdminApplicationName(auth.getRealm())));
|
||||
}
|
||||
|
||||
event.detail(Details.REALM, realm.getName());
|
||||
RealmAdminResource adminResource = new RealmAdminResource(realmAuth, realm, tokenManager, event);
|
||||
RealmAdminResource adminResource = new RealmAdminResource(realmAuth, realm, tokenManager);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(adminResource);
|
||||
//resourceContext.initResource(adminResource);
|
||||
return adminResource;
|
||||
|
|
|
@ -3,8 +3,6 @@ package org.keycloak.services.resources.admin;
|
|||
import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
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.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
|
@ -22,7 +20,6 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -36,17 +33,15 @@ public class RoleByIdResource extends RoleResource {
|
|||
protected static final Logger logger = Logger.getLogger(RoleByIdResource.class);
|
||||
private final RealmModel realm;
|
||||
private final RealmAuth auth;
|
||||
private EventBuilder event;
|
||||
|
||||
@Context
|
||||
protected KeycloakSession session;
|
||||
|
||||
public RoleByIdResource(RealmModel realm, RealmAuth auth, EventBuilder event) {
|
||||
public RoleByIdResource(RealmModel realm, RealmAuth auth) {
|
||||
super(realm);
|
||||
|
||||
this.realm = realm;
|
||||
this.auth = auth;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,13 +58,7 @@ public class RoleByIdResource extends RoleResource {
|
|||
RoleModel roleModel = getRoleModel(id);
|
||||
auth.requireView();
|
||||
|
||||
RoleRepresentation rep = getRole(roleModel);
|
||||
|
||||
event.event(EventType.VIEW_ROLE)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return rep;
|
||||
return getRole(roleModel);
|
||||
}
|
||||
|
||||
protected RoleModel getRoleModel(String id) {
|
||||
|
@ -102,14 +91,9 @@ public class RoleByIdResource extends RoleResource {
|
|||
@DELETE
|
||||
@NoCache
|
||||
public void deleteRole(final @PathParam("role-id") String id) {
|
||||
RoleRepresentation rep = getRole(id);
|
||||
RoleModel role = getRoleModel(id);
|
||||
auth.requireManage();
|
||||
deleteRole(role);
|
||||
|
||||
event.event(EventType.DELETE_ROLE)
|
||||
.representation(rep)
|
||||
.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,10 +109,6 @@ public class RoleByIdResource extends RoleResource {
|
|||
RoleModel role = getRoleModel(id);
|
||||
auth.requireManage();
|
||||
updateRole(rep, role);
|
||||
|
||||
event.event(EventType.UPDATE_ROLE)
|
||||
.representation(rep)
|
||||
.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,12 +124,6 @@ public class RoleByIdResource extends RoleResource {
|
|||
RoleModel role = getRoleModel(id);
|
||||
auth.requireManage();
|
||||
addComposites(roles, role);
|
||||
|
||||
RoleRepresentation rep = getRole(id);
|
||||
|
||||
event.event(EventType.UPDATE_ROLE)
|
||||
.representation(rep)
|
||||
.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,8 +2,6 @@ package org.keycloak.services.resources.admin;
|
|||
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
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.ModelDuplicateException;
|
||||
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.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -37,14 +34,12 @@ public class RoleContainerResource extends RoleResource {
|
|||
private final RealmModel realm;
|
||||
private final RealmAuth auth;
|
||||
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);
|
||||
this.realm = realm;
|
||||
this.auth = auth;
|
||||
this.roleContainer = roleContainer;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,9 +58,6 @@ public class RoleContainerResource extends RoleResource {
|
|||
for (RoleModel roleModel : roleModels) {
|
||||
roles.add(ModelToRepresentation.toRepresentation(roleModel));
|
||||
}
|
||||
|
||||
event.event(EventType.VIEW_ROLES).representation(roles).success();
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
@ -84,11 +76,6 @@ public class RoleContainerResource extends RoleResource {
|
|||
try {
|
||||
RoleModel role = roleContainer.addRole(rep.getName());
|
||||
role.setDescription(rep.getDescription());
|
||||
|
||||
event.event(EventType.CREATE_ROLE)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return Response.created(uriInfo.getAbsolutePathBuilder().path(role.getName()).build()).build();
|
||||
} catch (ModelDuplicateException e) {
|
||||
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);
|
||||
}
|
||||
|
||||
RoleRepresentation rep = getRole(roleModel);
|
||||
|
||||
event.event(EventType.VIEW_ROLE)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return rep;
|
||||
return getRole(roleModel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,10 +120,6 @@ public class RoleContainerResource extends RoleResource {
|
|||
throw new NotFoundException("Could not find role: " + roleName);
|
||||
}
|
||||
deleteRole(role);
|
||||
|
||||
event.event(EventType.DELETE_ROLE)
|
||||
.representation(rep)
|
||||
.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -164,11 +141,6 @@ public class RoleContainerResource extends RoleResource {
|
|||
}
|
||||
try {
|
||||
updateRole(rep, role);
|
||||
|
||||
event.event(EventType.UPDATE_ROLE)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return Response.noContent().build();
|
||||
} catch (ModelDuplicateException e) {
|
||||
return Flows.errors().exists("Role with name " + rep.getName() + " already exists");
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.keycloak.services.resources.admin;
|
|||
import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.keycloak.constants.KerberosConstants;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
|
@ -10,9 +11,6 @@ import org.keycloak.models.UserCredentialModel;
|
|||
import org.keycloak.models.UserFederationProvider;
|
||||
import org.keycloak.models.UserFederationProviderFactory;
|
||||
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.provider.ProviderFactory;
|
||||
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.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -49,18 +46,15 @@ public class UserFederationResource {
|
|||
|
||||
protected RealmAuth auth;
|
||||
|
||||
private EventBuilder event;
|
||||
|
||||
@Context
|
||||
protected UriInfo uriInfo;
|
||||
|
||||
@Context
|
||||
protected KeycloakSession session;
|
||||
|
||||
public UserFederationResource(RealmModel realm, RealmAuth auth, EventBuilder event) {
|
||||
public UserFederationResource(RealmModel realm, RealmAuth auth) {
|
||||
this.auth = auth;
|
||||
this.realm = realm;
|
||||
this.event = event;
|
||||
|
||||
auth.init(RealmAuth.Resource.USER);
|
||||
}
|
||||
|
@ -83,9 +77,6 @@ public class UserFederationResource {
|
|||
rep.setOptions(((UserFederationProviderFactory)factory).getConfigurationOptions());
|
||||
providers.add(rep);
|
||||
}
|
||||
|
||||
event.event(EventType.VIEW_FEDERATION_PROVIDERS).representation(providers).success();
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
|
@ -107,9 +98,6 @@ public class UserFederationResource {
|
|||
UserFederationProviderFactoryRepresentation rep = new UserFederationProviderFactoryRepresentation();
|
||||
rep.setId(factory.getId());
|
||||
rep.setOptions(((UserFederationProviderFactory)factory).getConfigurationOptions());
|
||||
|
||||
event.event(EventType.VIEW_FEDERATION_PROVIDER).representation(rep).success();
|
||||
|
||||
return rep;
|
||||
}
|
||||
throw new NotFoundException("Could not find provider");
|
||||
|
@ -134,11 +122,6 @@ public class UserFederationResource {
|
|||
rep.getFullSyncPeriod(), rep.getChangedSyncPeriod(), rep.getLastSync());
|
||||
new UsersSyncManager().refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), model, realm.getId());
|
||||
checkKerberosCredential(model);
|
||||
|
||||
event.event(EventType.CREATE_FEDERATION_PROVIDER)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return Response.created(uriInfo.getAbsolutePathBuilder().path(model.getId()).build()).build();
|
||||
}
|
||||
|
||||
|
@ -162,10 +145,6 @@ public class UserFederationResource {
|
|||
realm.updateUserFederationProvider(model);
|
||||
new UsersSyncManager().refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), model, realm.getId());
|
||||
checkKerberosCredential(model);
|
||||
|
||||
event.event(EventType.UPDATE_FEDERATION_PROVIDER)
|
||||
.representation(rep)
|
||||
.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,13 +160,7 @@ public class UserFederationResource {
|
|||
auth.requireView();
|
||||
for (UserFederationProviderModel model : realm.getUserFederationProviders()) {
|
||||
if (model.getId().equals(id)) {
|
||||
UserFederationProviderRepresentation rep = ModelToRepresentation.toRepresentation(model);
|
||||
|
||||
event.event(EventType.VIEW_FEDERATION_PROVIDER)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return rep;
|
||||
return ModelToRepresentation.toRepresentation(model);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,10 +181,6 @@ public class UserFederationResource {
|
|||
UserFederationProviderModel model = new UserFederationProviderModel(id, null, null, -1, null, -1, -1, 0);
|
||||
realm.removeUserFederationProvider(model);
|
||||
new UsersSyncManager().removePeriodicSyncForProvider(session.getProvider(TimerProvider.class), model);
|
||||
|
||||
event.event(EventType.DELETE_FEDERATION_PROVIDER)
|
||||
.representation(rep)
|
||||
.success();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,9 +7,6 @@ import org.jboss.resteasy.spi.NotFoundException;
|
|||
import org.keycloak.ClientConnection;
|
||||
import org.keycloak.email.EmailException;
|
||||
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.ClientModel;
|
||||
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.UriBuilder;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -82,8 +78,6 @@ public class UsersResource {
|
|||
|
||||
private TokenManager tokenManager;
|
||||
|
||||
private EventBuilder event;
|
||||
|
||||
@Context
|
||||
protected ClientConnection clientConnection;
|
||||
|
||||
|
@ -96,11 +90,10 @@ public class UsersResource {
|
|||
@Context
|
||||
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.realm = realm;
|
||||
this.tokenManager = tokenManager;
|
||||
this.event = event;
|
||||
|
||||
auth.init(RealmAuth.Resource.USER);
|
||||
}
|
||||
|
@ -125,10 +118,6 @@ public class UsersResource {
|
|||
}
|
||||
updateUserFromRep(user, rep);
|
||||
|
||||
event.event(EventType.UPDATE_USER)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
if (session.getTransaction().isActive()) {
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
@ -165,10 +154,6 @@ public class UsersResource {
|
|||
UserModel user = session.users().addUser(realm, rep.getUsername());
|
||||
updateUserFromRep(user, rep);
|
||||
|
||||
event.event(EventType.CREATE_USER)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
if (session.getTransaction().isActive()) {
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
@ -234,13 +219,7 @@ public class UsersResource {
|
|||
throw new NotFoundException("User not found");
|
||||
}
|
||||
|
||||
UserRepresentation rep = ModelToRepresentation.toRepresentation(user);
|
||||
|
||||
event.event(EventType.VIEW_USER)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return rep;
|
||||
return ModelToRepresentation.toRepresentation(user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -265,11 +244,6 @@ public class UsersResource {
|
|||
UserSessionRepresentation rep = ModelToRepresentation.toRepresentation(session);
|
||||
reps.add(rep);
|
||||
}
|
||||
|
||||
event.event(EventType.VIEW_USER_SESSIONS)
|
||||
.representation(reps)
|
||||
.success();
|
||||
|
||||
return reps;
|
||||
}
|
||||
|
||||
|
@ -301,11 +275,6 @@ public class UsersResource {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.event(EventType.VIEW_USER)
|
||||
.representation(result)
|
||||
.success();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -361,9 +330,6 @@ public class UsersResource {
|
|||
for (UserSessionModel userSession : userSessions) {
|
||||
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);
|
||||
if (removed) {
|
||||
|
||||
event.event(EventType.DELETE_USER)
|
||||
.representation(rep)
|
||||
.success();
|
||||
|
||||
return Response.noContent().build();
|
||||
} else {
|
||||
return Flows.errors().error("User couldn't be deleted", Response.Status.BAD_REQUEST);
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.keycloak.broker.provider.AuthenticationRequest;
|
|||
import org.keycloak.broker.provider.FederatedIdentity;
|
||||
import org.keycloak.broker.provider.IdentityBrokerException;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
|
@ -156,7 +155,7 @@ public class TwitterIdentityProvider extends AbstractIdentityProvider<OAuth2Iden
|
|||
} catch (Exception 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.error("twitter_login_failed");
|
||||
return Flows.forwardToSecurityFailurePage(session, realm, uriInfo, headers, Messages.UNEXPECTED_ERROR_HANDLING_RESPONSE);
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.junit.Before;
|
|||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.events.Event;
|
||||
import org.keycloak.events.EventGroup;
|
||||
import org.keycloak.events.EventStoreProvider;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
|
@ -186,7 +185,6 @@ public class EventStoreProviderTest {
|
|||
Event e = new Event();
|
||||
e.setTime(time);
|
||||
e.setType(event);
|
||||
e.setGroup(EventGroup.USER);
|
||||
e.setRealmId(realmId);
|
||||
e.setClientId(clientId);
|
||||
e.setUserId(userId);
|
||||
|
|
Loading…
Reference in a new issue