Fix resource path for partial import events.
This commit is contained in:
parent
dd038ddbd5
commit
2d878805c1
4 changed files with 35 additions and 12 deletions
|
@ -107,14 +107,14 @@ public class PartialImportManager {
|
|||
|
||||
private void addedEvent(PartialImportResult result) {
|
||||
adminEvent.operation(OperationType.CREATE)
|
||||
.resourcePath(uriInfo)
|
||||
.resourcePath(result.getResourceType().getPath(), result.getId())
|
||||
.representation(result.getRepresentation())
|
||||
.success();
|
||||
};
|
||||
|
||||
private void overwrittenEvent(PartialImportResult result) {
|
||||
adminEvent.operation(OperationType.UPDATE)
|
||||
.resourcePath(uriInfo)
|
||||
.resourcePath(result.getResourceType().getPath(), result.getId())
|
||||
.representation(result.getRepresentation())
|
||||
.success();
|
||||
}
|
||||
|
|
|
@ -26,14 +26,14 @@ import org.codehaus.jackson.annotate.JsonIgnore;
|
|||
public class PartialImportResult {
|
||||
|
||||
private final Action action;
|
||||
private final String resourceType;
|
||||
private final ResourceType resourceType;
|
||||
private final String resourceName;
|
||||
private final String id;
|
||||
private final Object representation;
|
||||
|
||||
private PartialImportResult(Action action, ResourceType resourceType, String resourceName, String id, Object representation) {
|
||||
this.action = action;
|
||||
this.resourceType = resourceType.toString();
|
||||
this.resourceType = resourceType;
|
||||
this.resourceName = resourceName;
|
||||
this.id = id;
|
||||
this.representation = representation;
|
||||
|
@ -55,7 +55,7 @@ public class PartialImportResult {
|
|||
return action;
|
||||
}
|
||||
|
||||
public String getResourceType() {
|
||||
public ResourceType getResourceType() {
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,17 @@ package org.keycloak.partialimport;
|
|||
public enum ResourceType {
|
||||
USER, CLIENT, IDP, REALM_ROLE, CLIENT_ROLE;
|
||||
|
||||
public String getPath() {
|
||||
switch(this) {
|
||||
case USER: return "users";
|
||||
case CLIENT: return "clients";
|
||||
case IDP: return "identity-provider-settings";
|
||||
case REALM_ROLE: return "realms";
|
||||
case CLIENT_ROLE: return "clients";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch(this) {
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.keycloak.common.util.Time;
|
|||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
public class AdminEventBuilder {
|
||||
|
||||
|
||||
private static final Logger log = Logger.getLogger(AdminEventBuilder.class);
|
||||
|
||||
private EventStoreProvider store;
|
||||
|
@ -59,17 +59,17 @@ public class AdminEventBuilder {
|
|||
authUser(auth.getUser());
|
||||
authIpAddress(clientConnection.getRemoteAddr());
|
||||
}
|
||||
|
||||
|
||||
public AdminEventBuilder realm(RealmModel realm) {
|
||||
adminEvent.setRealmId(realm.getId());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public AdminEventBuilder realm(String realmId) {
|
||||
adminEvent.setRealmId(realmId);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public AdminEventBuilder operation(OperationType e) {
|
||||
adminEvent.setOperationType(e);
|
||||
return this;
|
||||
|
@ -123,6 +123,18 @@ public class AdminEventBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public AdminEventBuilder resourcePath(String... pathElements) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String element : pathElements) {
|
||||
sb.append("/");
|
||||
sb.append(element);
|
||||
}
|
||||
if (pathElements.length > 0) sb.deleteCharAt(0); // remove leading '/'
|
||||
|
||||
adminEvent.setResourcePath(sb.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public AdminEventBuilder resourcePath(UriInfo uriInfo) {
|
||||
String path = getResourcePath(uriInfo);
|
||||
adminEvent.setResourcePath(path);
|
||||
|
@ -155,7 +167,7 @@ public class AdminEventBuilder {
|
|||
adminEvent.setError(error);
|
||||
send();
|
||||
}
|
||||
|
||||
|
||||
public AdminEventBuilder representation(Object value) {
|
||||
if (value == null || value.equals("")) {
|
||||
return this;
|
||||
|
@ -167,7 +179,7 @@ public class AdminEventBuilder {
|
|||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public AdminEvent getEvent() {
|
||||
return adminEvent;
|
||||
}
|
||||
|
@ -190,7 +202,7 @@ public class AdminEventBuilder {
|
|||
log.error("Failed to save event", t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (listeners != null) {
|
||||
for (EventListenerProvider l : listeners) {
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue