Skip to content

Commit

Permalink
switched eventTypes to FetchType.EAGER in WebhookEntity (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
xgp authored Nov 13, 2023
1 parent 777425b commit 0efa3c5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ protected void send(
log.warnf("Sending failure (Server response:%d)", status);
throw new SenderException(true);
}
} catch (SenderException se) {
// rethrow existing SenderException
throw se;
} catch (Exception e) {
log.warnf(e, "Sending exception to %s", targetUri);
throw new SenderException(false, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ScriptEventListenerProvider implements EventListenerProvider, Confi

protected final KeycloakSession session;
protected final boolean scriptsDisabled;

public ScriptEventListenerProvider(KeycloakSession session) {
this.session = session;
this.scriptsDisabled = Boolean.parseBoolean(System.getenv(SCRIPTS_DISABLED_ENV));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public class WebhookEntity {
@Column(name = "ALGORITHM")
protected String algorithm;

@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
@Column(name = "VALUE")
@CollectionTable(
name = "WEBHOOK_EVENT_TYPES",
joinColumns = {@JoinColumn(name = "WEBHOOK_ID")})
protected Set<String> eventTypes = new HashSet();
protected Set<String> eventTypes = new HashSet<>();

@Column(name = "CREATED_BY_USER_ID")
protected String createdBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import lombok.extern.jbosslog.JBossLog;
Expand Down Expand Up @@ -59,6 +60,10 @@ public void testAddGetWebhook() throws Exception {
.auth(keycloak.tokenManager().getAccessTokenString())
.asResponse();
assertThat(response.getStatus(), is(200));
/*
String r = response.asString();
log.infof("got webhook response %s", r);
*/
WebhookRepresentation rep = response.asJson(new TypeReference<WebhookRepresentation>() {});
assertNotNull(rep);
assertTrue(rep.isEnabled());
Expand All @@ -76,6 +81,49 @@ public void testAddGetWebhook() throws Exception {
assertThat(response.getStatus(), is(204));
}

/** https://github.com/p2-inc/keycloak-events/issues/42 */
@Test
public void testAddGetWebhookEventTypes() throws Exception {
Keycloak keycloak = server.client();

String url = "https://pipedream.m.pipedream.net";
Set<String> types =
ImmutableSet.of(
"access.REMOVE_TOTP",
"access.UPDATE_TOTP",
"access.LOGIN",
"access.LOGOUT",
"access.REGISTER",
"access.UPDATE_PASSWORD",
"access.VERIFY_EMAIL",
"access.SEND_VERIFY_EMAIL",
"access.RESET_PASSWORD");
String id = createWebhook(keycloak, httpClient, baseUrl(), url, "A3jt6D8lz", types);

SimpleHttp.Response response =
SimpleHttp.doGet(baseUrl() + "/" + urlencode(id), httpClient)
.auth(keycloak.tokenManager().getAccessTokenString())
.asResponse();
assertThat(response.getStatus(), is(200));

WebhookRepresentation rep = response.asJson(new TypeReference<WebhookRepresentation>() {});
assertNotNull(rep);
assertTrue(rep.isEnabled());
assertNotNull(rep.getId());
assertNotNull(rep.getCreatedAt());
assertNotNull(rep.getCreatedBy());
assertThat(rep.getRealm(), is("master"));
assertThat(rep.getUrl(), is(url));
assertThat(rep.getEventTypes().size(), is(9));
assertNull(rep.getSecret());

response =
SimpleHttp.doDelete(baseUrl() + "/" + urlencode(id), httpClient)
.auth(keycloak.tokenManager().getAccessTokenString())
.asResponse();
assertThat(response.getStatus(), is(204));
}

@Test
public void testUpdateGetWebhook() throws Exception {
Keycloak keycloak = server.client();
Expand Down

0 comments on commit 0efa3c5

Please sign in to comment.