Search in sources :

Example 11 with AdminEventRepresentation

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));
    }
}
Also used : PartialImportResult(org.keycloak.partialimport.PartialImportResult) AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) PartialImportResults(org.keycloak.partialimport.PartialImportResults) UserResource(org.keycloak.admin.client.resource.UserResource) HashSet(java.util.HashSet) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Example 12 with AdminEventRepresentation

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"));
}
Also used : IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Test(org.junit.Test)

Example 13 with AdminEventRepresentation

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()));
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) Test(org.junit.Test)

Example 14 with AdminEventRepresentation

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)));
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) AuthDetailsRepresentation(org.keycloak.representations.idm.AuthDetailsRepresentation) Test(org.junit.Test)

Aggregations

AdminEventRepresentation (org.keycloak.representations.idm.AdminEventRepresentation)14 Test (org.junit.Test)9 AuthDetailsRepresentation (org.keycloak.representations.idm.AuthDetailsRepresentation)3 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)3 HashSet (java.util.HashSet)2 UserResource (org.keycloak.admin.client.resource.UserResource)2 PartialImportResult (org.keycloak.partialimport.PartialImportResult)2 PartialImportResults (org.keycloak.partialimport.PartialImportResults)2 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IdentityProviderResource (org.keycloak.admin.client.resource.IdentityProviderResource)1 RealmResource (org.keycloak.admin.client.resource.RealmResource)1 CredentialRepresentation (org.keycloak.representations.idm.CredentialRepresentation)1 IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)1 ProtocolMapperRepresentation (org.keycloak.representations.idm.ProtocolMapperRepresentation)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)1