8000 Enable Admin API v2 client events by default by shawkins · Pull Request #55791 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ public ClientResourceTypeProvider(KeycloakSession session) {
this.permissions = AdminPermissions.evaluator(session, realm, authInfo);
this.adminEventBuilder = new AdminEventV2Builder(realm, permissions.adminAuth(), session, session.getContext().getConnection()).resource(ResourceType.CLIENT);
this.validator = new HibernateValidatorProvider(new ValidationContext(session, realm));
this.rolesService = new RolesService(session, realm, permissions, adminEventBuilder);
// A separate builder is needed as the role resources change the resource type of the builder they are given.
this.rolesService = new RolesService(session, realm, permissions,
new AdminEventV2Builder(realm, permissions.adminAuth(), session, session.getContext().getConnection()));
}

public Map<String, BaseClientModelSchema<? extends BaseClientRepresentation>> getSchemaMap() {
Expand Down Expand Up @@ -287,19 +289,17 @@ protected boolean onDelete(ClientModel client) {
}

/**
* Fires a v2 admin event for client operations (only enabled for testing now to avoid duplicated admin events)
* Fires a v2 admin event for client operations
*
* @param operationType the type of operation (CREATE, UPDATE, DELETE)
* @param representation the v2 representation of the client
*/
protected void fireAdminEvent(OperationType operationType, BaseClientRepresentation representation) {
if (Boolean.parseBoolean(System.getProperty("kc.admin-v2.client-service.events.enabled", "false"))) {
adminEventBuilder
.operation(operationType)
.resourcePath(session.getContext().getUri())
.representation(representation)
.success();
}
adminEventBuilder
.operation(operationType)
.resourcePath(session.getContext().getUri())
.representation(representation)
.success();
}

@Override
Expand Down Expand Up @@ -483,10 +483,15 @@ protected void handleRoles(RoleContainerResource clientRoles, Set<String> rolesF
.map(RoleRepresentation::getName)
.collect(Collectors.toSet());

System.out.println("handleRoles called! desired=" + desiredRoleNames + " current=" + currentRoleNames);

// Add missing roles (in desiredRoleNames but not in currentRoleNames)
desiredRoleNames.stream()
.filter(roleName -> !currentRoleNames.contains(roleName))
.forEach(roleName -> clientRoles.doCreateRole(new RoleRepresentation(roleName, "", false)));
.forEach(roleName -> {
System.out.println("creating role " + roleName);
clientRoles.doCreateRole(new RoleRepresentation(roleName, "", false));
});

// Remove extra roles (in currentRoleNames but not in desiredRoleNames)
currentRoleNames.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@
import org.keycloak.testframework.annotations.InjectRealm;
import org.keycloak.testframework.annotations.KeycloakIntegrationTest;
import org.keycloak.testframework.realm.ManagedRealm;
import org.keycloak.testframework.remote.runonserver.InjectRunOnServer;
import org.keycloak.testframework.remote.runonserver.RunOnServerClient;
import org.keycloak.testframework.server.KeycloakServerConfig;
import org.keycloak.testframework.server.KeycloakServerConfigBuilder;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -60,9 +57,6 @@
public class AdminEventV2Test extends AbstractClientApiV2Test {
private static final String TEST_CLIENT_ID = "v2-rep-test-client";

@InjectRunOnServer
RunOnServerClient runOnServer;

@InjectRealm
ManagedRealm testRealm;

Expand All @@ -73,11 +67,6 @@ public String getRealmName() {

@BeforeEach
public void setupAndClearEvents() {
runOnServer.run(session -> {
// enable Admin v2 events on the server
System.setProperty("kc.admin-v2.client-service.events.enabled", "true");
});

// Enable admin events on test realm
RealmEventsConfigRepresentation eventsConfig = testRealm.admin().getRealmEventsConfig();
eventsConfig.setAdminEventsEnabled(true);
Expand All @@ -88,14 +77,6 @@ public void setupAndClearEvents() {
testRealm.admin().clearAdminEvents();
}

@AfterEach
public void disableAdminEventsV2() {
runOnServer.run(session -> {
// enable Admin v2 events on the server
System.clearProperty("kc.admin-v2.client-service.events.enabled");
});
}

@Test
public void createClientFiresV2Event() throws Exception {
createTestClient();
Expand Down
Loading
0