Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-7 - if client or realm - which is a custom name contains a dot (.) #8

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-7 - if client or realm - which is a custom name contains a dot (.)
then it breaks the logical division of the routing key

This fix removes the dots from clientId or realm name before sanitising
the routing key as a whole.
  • Loading branch information
aznamier committed Jun 22, 2021
commit 73ea11fd55813f44d5b83d56f13263b599b1ec1d
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static String calculateRoutingKey(AdminEvent adminEvent) {
//KK.EVENT.ADMIN.<REALM>.<RESULT>.<RESOURCE_TYPE>.<OPERATION>
String routingKey = ROUTING_KEY_PREFIX
+ ".ADMIN"
+ "." + adminEvent.getRealmId()
+ "." + removeDots(adminEvent.getRealmId())
+ "." + (adminEvent.getError() != null ? "ERROR" : "SUCCESS")
+ "." + adminEvent.getResourceTypeAsString()
+ "." + adminEvent.getOperationType().toString()
Expand All @@ -39,9 +39,9 @@ public static String calculateRoutingKey(Event event) {
//KK.EVENT.CLIENT.<REALM>.<RESULT>.<CLIENT>.<EVENT_TYPE>
String routingKey = ROUTING_KEY_PREFIX
+ ".CLIENT"
+ "." + event.getRealmId()
+ "." + removeDots(event.getRealmId())
+ "." + (event.getError() != null ? "ERROR" : "SUCCESS")
+ "." + event.getClientId()
+ "." + removeDots(event.getClientId())
+ "." + event.getType();

return normalizeKey(routingKey);
Expand All @@ -53,6 +53,13 @@ public static final String normalizeKey(String stringToNormalize) {
replaceAll(" ", "_");
}

public static final String removeDots(String stringToNormalize) {
if(stringToNormalize != null) {
stringToNormalize = stringToNormalize.replaceAll("\\.", "");
}
return stringToNormalize;
}

public static String writeAsJson(Object object, boolean isPretty) {
String messageAsJson = "unparsable";
try {
Expand Down