-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#46 - Resolve compatibility issues between JSON and AVRO
- Loading branch information
Showing
13 changed files
with
503 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/com/github/snuk87/keycloak/kafka/mapper/KeycloakMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.github.snuk87.keycloak.kafka.mapper; | ||
|
||
import com.github.snuk87.keycloak.kafka.dto.AuthDetails; | ||
import com.github.snuk87.keycloak.kafka.dto.KeycloakAdminEvent; | ||
import com.github.snuk87.keycloak.kafka.dto.KeycloakEvent; | ||
import com.github.snuk87.keycloak.kafka.dto.OperationType; | ||
import org.keycloak.events.Event; | ||
import org.keycloak.events.admin.AdminEvent; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class KeycloakMapper { | ||
|
||
public static KeycloakAdminEvent mapEventToKeycloakEvent(final AdminEvent event){ | ||
return KeycloakAdminEvent.newBuilder() | ||
.setId(event.getId()) | ||
.setTime(event.getTime()) | ||
.setRealmId(event.getRealmId()) | ||
.setRealmName(event.getRealmName()) | ||
.setError(event.getError()) | ||
.setResourceType(event.getResourceTypeAsString()) | ||
.setResourcePath(event.getResourcePath()) | ||
.setRepresentation(event.getRepresentation()) | ||
.setOperationType(OperationType.valueOf(Optional.ofNullable(event.getOperationType()).map(ot -> ot.toString()).orElse(OperationType.ACTION.toString()))) | ||
.setAuthDetails( | ||
Optional.ofNullable(event.getAuthDetails()).map(authDetails -> AuthDetails.newBuilder() | ||
.setClientId(authDetails.getClientId()) | ||
.setIpAddress(authDetails.getIpAddress()) | ||
.setRealmId(authDetails.getRealmId()) | ||
.setRealmName(authDetails.getRealmName()) | ||
.setUserId(authDetails.getUserId()) | ||
.build()) | ||
.orElse(null) | ||
).build(); | ||
} | ||
|
||
public static KeycloakEvent mapEventToKeycloakEvent(final Event event){ | ||
return KeycloakEvent.newBuilder() | ||
.setId(event.getId()) | ||
.setTime(event.getTime()) | ||
.setRealmId(event.getRealmId()) | ||
.setRealmName(event.getRealmName()) | ||
.setError(event.getError()) | ||
.setClientId(event.getClientId()) | ||
.setUserId(event.getUserId()) | ||
.setSessionId(event.getSessionId()) | ||
.setIpAddress(event.getIpAddress()) | ||
.setDetails(event.getDetails()) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...a/com/github/snuk87/keycloak/kafka/serializer/mixin/JacksonIgnoreAvroPropertiesMixIn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.snuk87.keycloak.kafka.serializer.mixin; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import org.apache.avro.Schema; | ||
import org.apache.avro.specific.SpecificData; | ||
|
||
public abstract class JacksonIgnoreAvroPropertiesMixIn { | ||
|
||
@JsonIgnore | ||
public abstract Schema getSchema(); | ||
|
||
@JsonIgnore | ||
public abstract SpecificData getSpecificData(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/resources/META-INF/services/org.keycloak.events.EventListenerProviderFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
com.github.snuk87.keycloak.kafka.KafkaEventListenerProviderFactory | ||
com.github.snuk87.keycloak.kafka.spi.KafkaEventListenerProviderFactory |
137 changes: 137 additions & 0 deletions
137
src/main/resources/avro/keycloak-admin-events-value.avsc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
{ | ||
"type": "record", | ||
"name": "KeycloakAdminEvent", | ||
"namespace": "com.github.snuk87.keycloak.kafka.dto", | ||
"fields": [ | ||
{ | ||
"name": "authDetails", | ||
"type": [ | ||
"null", | ||
{ | ||
"type": "record", | ||
"name": "AuthDetails", | ||
"fields": [ | ||
{ | ||
"name": "clientId", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "ipAddress", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "realmId", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "realmName", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "userId", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
} | ||
] | ||
} | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "error", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "id", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "operationType", | ||
"type": [ | ||
"null", | ||
{ | ||
"type": "enum", | ||
"name": "OperationType", | ||
"symbols": [ | ||
"CREATE", | ||
"UPDATE", | ||
"DELETE", | ||
"ACTION" | ||
] | ||
} | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "realmId", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "realmName", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "representation", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "resourcePath", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "resourceType", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"default": null | ||
}, | ||
{ | ||
"name": "time", | ||
"type": "long" | ||
} | ||
] | ||
} |
Oops, something went wrong.