-
Notifications
You must be signed in to change notification settings - Fork 5
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
event store #124
Draft
xgp
wants to merge
17
commits into
opdt:main
Choose a base branch
from
xgp:xgp/event-store
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
event store #124
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f8db1b0
initial structure of event store
xgp 94a05db
Merge branch 'main' into xgp/event-store
xgp a32a736
compiliing. need to figure out *Query.
xgp 11d9187
started query providers without order or range.
xgp cdd061c
moved convenience methods out of query providers
xgp c0c12bb
headers
xgp 23ac383
put the skip/limit in the stream. todo real paging that does NOT load…
xgp 6f69b96
Merge branch 'main' into xgp/event-store
xgp fd367b0
working for storage of events. admin ui still fails to load events pa…
xgp 42da653
working-ish tests.
xgp 48cec8c
using ALLOW_FILTERING to make progress on testing.
xgp cfe775a
event tests working independently
xgp ad2e8ff
added proper clear method that removes future dates. tests now pass.
xgp e748854
formatting
xgp fede22e
added to readme
xgp ab75812
formatting
xgp 81003b5
requested pr updates
xgp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
98 changes: 98 additions & 0 deletions
98
...ain/java/de/arbeitsagentur/opdt/keycloak/cassandra/event/CassandraEventStoreProvider.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,98 @@ | ||
/* | ||
* Copyright 2024 Phase Two, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.arbeitsagentur.opdt.keycloak.cassandra.event; | ||
|
||
import static de.arbeitsagentur.opdt.keycloak.cassandra.event.persistence.Converters.*; | ||
|
||
import de.arbeitsagentur.opdt.keycloak.cassandra.event.persistence.EventRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.jbosslog.JBossLog; | ||
import org.keycloak.events.Event; | ||
import org.keycloak.events.EventQuery; | ||
import org.keycloak.events.EventStoreProvider; | ||
import org.keycloak.events.admin.AdminEvent; | ||
import org.keycloak.events.admin.AdminEventQuery; | ||
import org.keycloak.models.RealmModel; | ||
|
||
@JBossLog | ||
@RequiredArgsConstructor | ||
public class CassandraEventStoreProvider implements EventStoreProvider { | ||
|
||
private final EventRepository repository; | ||
|
||
@Override | ||
public void onEvent(Event event) { | ||
repository.insertEvent(eventToEntity(event)); | ||
} | ||
|
||
@Override | ||
public void onEvent(AdminEvent event, boolean includeRepresentation) { | ||
repository.insertAdminEvent(adminEventToEntity(event, includeRepresentation)); | ||
} | ||
|
||
@Override | ||
public EventQuery createQuery() { | ||
return repository.eventQuery(); | ||
} | ||
|
||
@Override | ||
public AdminEventQuery createAdminQuery() { | ||
return repository.adminEventQuery(); | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
throw new UnsupportedOperationException( | ||
"clear() is deprecated and not supported in this implementation"); | ||
} | ||
|
||
@Override | ||
public void clear(RealmModel realm) { | ||
repository.deleteRealmEvents(realm.getId()); | ||
} | ||
|
||
@Override | ||
public void clear(RealmModel realm, long olderThan) { | ||
repository.deleteRealmEvents(realm.getId(), olderThan); | ||
} | ||
|
||
@Override | ||
public void clearExpiredEvents() { | ||
throw new UnsupportedOperationException( | ||
"clearExpiredEvents() is deprecated and not supported in this implementation"); | ||
} | ||
|
||
@Override | ||
public void clearAdmin() { | ||
throw new UnsupportedOperationException( | ||
"clearAdmin() is deprecated and not supported in this implementation"); | ||
} | ||
|
||
@Override | ||
public void clearAdmin(RealmModel realm) { | ||
repository.deleteAdminRealmEvents(realm.getId()); | ||
} | ||
|
||
@Override | ||
public void clearAdmin(RealmModel realm, long olderThan) { | ||
repository.deleteAdminRealmEvents(realm.getId(), olderThan); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// Nothing to do | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...a/de/arbeitsagentur/opdt/keycloak/cassandra/event/CassandraEventStoreProviderFactory.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,65 @@ | ||
/* | ||
* Copyright 2024 Phase Two, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.arbeitsagentur.opdt.keycloak.cassandra.event; | ||
|
||
import static de.arbeitsagentur.opdt.keycloak.common.CommunityProfiles.isCassandraCacheProfileEnabled; | ||
import static de.arbeitsagentur.opdt.keycloak.common.CommunityProfiles.isCassandraProfileEnabled; | ||
import static de.arbeitsagentur.opdt.keycloak.common.ProviderHelpers.createProviderCached; | ||
import static org.keycloak.userprofile.DeclarativeUserProfileProvider.PROVIDER_PRIORITY; | ||
|
||
import com.google.auto.service.AutoService; | ||
import de.arbeitsagentur.opdt.keycloak.cassandra.connection.CassandraConnectionProvider; | ||
import org.keycloak.Config; | ||
import org.keycloak.events.EventStoreProviderFactory; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.provider.EnvironmentDependentProviderFactory; | ||
|
||
@AutoService(EventStoreProviderFactory.class) | ||
public class CassandraEventStoreProviderFactory | ||
implements EventStoreProviderFactory, EnvironmentDependentProviderFactory { | ||
|
||
@Override | ||
public CassandraEventStoreProvider create(KeycloakSession session) { | ||
CassandraConnectionProvider cassandraConnectionProvider = | ||
createProviderCached(session, CassandraConnectionProvider.class); | ||
return new CassandraEventStoreProvider(cassandraConnectionProvider.getRepository()); | ||
} | ||
|
||
@Override | ||
public void init(Config.Scope config) {} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory factory) {} | ||
|
||
@Override | ||
public void close() {} | ||
|
||
@Override | ||
public String getId() { | ||
return "cassandra"; | ||
} | ||
|
||
@Override | ||
public int order() { | ||
return PROVIDER_PRIORITY + 1; | ||
} | ||
|
||
@Override | ||
public boolean isSupported() { | ||
return isCassandraProfileEnabled() || isCassandraCacheProfileEnabled(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done with external file based configuration and not hardcoded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @opdt I was having problems getting the migration to run in the tests without a timeout. Can you point me to some documentation/examples of how this is achieved using external file based configuration? I'm not super familiar with cassandra, so the options are new to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been struggling to figure out how to load an external file based configuration @opdt. Is there an example you're aware of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally figured out how to load config from a file. I have a branch here, so let me know if you want me to do a separate PR. https://github.com/opdt/keycloak-cassandra-extension/compare/main...xgp:keycloak-cassandra-extension:xgp/config-file?expand=1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You dont need any custom code to load the config from a file. The cassandra driver does it automatically: https://docs.datastax.com/en/developer/java-driver/4.17/manual/core/configuration/ (application.conf in Classpath)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. But if you want to allow it to be put somewhere else and not bundled with the jar, then you have to tell Cassandra where to load it from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, I might want to have k8s mount the conf file in the pod and then need to tell the extension where to load it from. This decouples the configuration from the library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats possible via
-Dconfig.file=/path/to/application.conf
via the underyling Lightbend configuration library (which also supports loading from other resources/URLs).You can pass additional Java arguments via
JAVA_OPTS_APPEND
environment variable in Keycloak.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem I encounter when I specify that is that the init method still runs. So even though the underlying library supports the
-Dconfig.file
override, it appears that it never gets there because of the exceptions thrown when the variables are missing.Also, if I set both, the variables in the config scope are what gets used.