use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.
the class PartialImportTest method testAddUsers.
@Test
public void testAddUsers() {
assertAdminEvents.clear();
setFail();
addUsers();
PartialImportResults results = doImport();
assertEquals(NUM_ENTITIES, results.getAdded());
// Need to do this way as admin events from partial import are unsorted
Set<String> userIds = new HashSet<>();
for (int i = 0; i < NUM_ENTITIES; i++) {
AdminEventRepresentation adminEvent = assertAdminEvents.poll();
Assert.assertEquals(realmId, adminEvent.getRealmId());
Assert.assertEquals(OperationType.CREATE.name(), adminEvent.getOperationType());
Assert.assertTrue(adminEvent.getResourcePath().startsWith("users/"));
String userId = adminEvent.getResourcePath().substring(6);
userIds.add(userId);
}
assertAdminEvents.assertEmpty();
for (PartialImportResult result : results.getResults()) {
String id = result.getId();
UserResource userRsc = testRealmResource().users().get(id);
UserRepresentation user = userRsc.toRepresentation();
Assert.assertThat(user.getUsername(), startsWith(USER_PREFIX));
Assert.assertThat(userIds, hasItem(id));
}
}
use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.
the class IdentityProviderTest method testUpdate.
@Test
public void testUpdate() {
IdentityProviderRepresentation newIdentityProvider = createRep("update-identity-provider", "oidc");
newIdentityProvider.getConfig().put(IdentityProviderModel.SYNC_MODE, "IMPORT");
newIdentityProvider.getConfig().put("clientId", "clientId");
newIdentityProvider.getConfig().put("clientSecret", "some secret value");
create(newIdentityProvider);
IdentityProviderResource identityProviderResource = realm.identityProviders().get("update-identity-provider");
assertNotNull(identityProviderResource);
IdentityProviderRepresentation representation = identityProviderResource.toRepresentation();
assertNotNull(representation);
assertEquals("update-identity-provider", representation.getAlias());
representation.setAlias("changed-alias");
representation.setEnabled(false);
representation.setStoreToken(true);
representation.getConfig().put("clientId", "changedClientId");
identityProviderResource.update(representation);
AdminEventRepresentation event = assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.identityProviderPath("update-identity-provider"), representation, ResourceType.IDENTITY_PROVIDER);
assertFalse(event.getRepresentation().contains("some secret value"));
assertTrue(event.getRepresentation().contains(ComponentRepresentation.SECRET_VALUE));
identityProviderResource = realm.identityProviders().get(representation.getInternalId());
assertNotNull(identityProviderResource);
representation = identityProviderResource.toRepresentation();
assertFalse(representation.isEnabled());
assertTrue(representation.isStoreToken());
assertEquals("changedClientId", representation.getConfig().get("clientId"));
assertEquals("some secret value", testingClient.testing("admin-client-test").getIdentityProviderConfig("changed-alias").get("clientSecret"));
representation.getConfig().put("clientSecret", "${vault.key}");
identityProviderResource.update(representation);
event = assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.identityProviderPath(representation.getInternalId()), representation, ResourceType.IDENTITY_PROVIDER);
assertThat(event.getRepresentation(), containsString("${vault.key}"));
assertThat(event.getRepresentation(), not(containsString(ComponentRepresentation.SECRET_VALUE)));
assertThat(identityProviderResource.toRepresentation().getConfig(), hasEntry("clientSecret", "${vault.key}"));
assertEquals("${vault.key}", testingClient.testing("admin-client-test").getIdentityProviderConfig("changed-alias").get("clientSecret"));
}
use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.
the class AdminEventTest method retrieveAdminEventTest.
@Test
public void retrieveAdminEventTest() {
createUser("user1");
List<AdminEventRepresentation> events = events();
assertThat(events.size(), is(equalTo(1)));
AdminEventRepresentation event = events().get(0);
assertThat(event.getOperationType(), is(equalTo("CREATE")));
assertThat(event.getRealmId(), is(equalTo(realmName())));
assertThat(event.getAuthDetails().getRealmId(), is(equalTo("master")));
assertThat(event.getRepresentation(), is(nullValue()));
}
use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.
the class AdminEventTest method defaultMaxResults.
@Test
public void defaultMaxResults() {
RealmResource realm = adminClient.realms().realm("test");
AdminEventRepresentation event = new AdminEventRepresentation();
event.setOperationType(OperationType.CREATE.toString());
event.setAuthDetails(new AuthDetailsRepresentation());
event.setRealmId(realm.toRepresentation().getId());
for (int i = 0; i < 110; i++) {
testingClient.testing("test").onAdminEvent(event, false);
}
assertThat(realm.getAdminEvents(null, null, null, null, null, null, null, null, null, null).size(), is(equalTo(100)));
assertThat(realm.getAdminEvents(null, null, null, null, null, null, null, null, 0, 105).size(), is(equalTo(105)));
assertThat(realm.getAdminEvents(null, null, null, null, null, null, null, null, 0, 1000).size(), is(greaterThanOrEqualTo(110)));
}
Aggregations