Search in sources :

Example 6 with AdminEventRepresentation

use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.

the class RealmTest method smtpPasswordSecret.

@Test
public void smtpPasswordSecret() {
    RealmRepresentation rep = RealmBuilder.create().testEventListener().testMail().build();
    rep.setRealm("realm-with-smtp");
    rep.getSmtpServer().put("user", "user");
    rep.getSmtpServer().put("password", "secret");
    adminClient.realms().create(rep);
    RealmRepresentation returned = adminClient.realm("realm-with-smtp").toRepresentation();
    assertEquals(ComponentRepresentation.SECRET_VALUE, returned.getSmtpServer().get("password"));
    KeycloakTestingClient.Server serverClient = testingClient.server("realm-with-smtp");
    RealmRepresentation internalRep = serverClient.fetch(RunHelpers.internalRealm());
    assertEquals("secret", internalRep.getSmtpServer().get("password"));
    adminClient.realm("realm-with-smtp").update(rep);
    AdminEventRepresentation event = testingClient.testing().pollAdminEvent();
    assertFalse(event.getRepresentation().contains("some secret value!!"));
    assertTrue(event.getRepresentation().contains(ComponentRepresentation.SECRET_VALUE));
    internalRep = serverClient.fetch(RunHelpers.internalRealm());
    assertEquals("secret", internalRep.getSmtpServer().get("password"));
    RealmRepresentation realm = adminClient.realms().findAll().stream().filter(r -> r.getRealm().equals("realm-with-smtp")).findFirst().get();
    assertEquals(ComponentRepresentation.SECRET_VALUE, realm.getSmtpServer().get("password"));
    adminClient.realm("realm-with-smtp").remove();
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) KeycloakTestingClient(org.keycloak.testsuite.client.KeycloakTestingClient) AbstractAdminTest(org.keycloak.testsuite.admin.AbstractAdminTest) Test(org.junit.Test)

Example 7 with AdminEventRepresentation

use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.

the class AssertAdminEvents method assertEmpty.

public void assertEmpty() {
    AdminEventRepresentation event = fetchNextEvent();
    Assert.assertNull("Empty admin event queue expected, but there is " + event, event);
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation)

Example 8 with AdminEventRepresentation

use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.

the class AssertAdminEvents method poll.

public AdminEventRepresentation poll() {
    AdminEventRepresentation event = fetchNextEvent();
    Assert.assertNotNull("Admin event expected", event);
    return event;
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation)

Example 9 with AdminEventRepresentation

use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.

the class AbstractProtocolMapperTest method testAddAllBuiltinMappers.

protected void testAddAllBuiltinMappers(ProtocolMappersResource resource, String protocolName, String adminEventPath) {
    List<ProtocolMapperRepresentation> oldMappers = resource.getMappersPerProtocol(protocolName);
    List<ProtocolMapperRepresentation> builtins = builtinMappers.get(protocolName);
    List<ProtocolMapperRepresentation> mappersToAdd = mappersToAdd(oldMappers, builtins);
    // This is used by admin console to add builtin mappers
    resource.createMapper(mappersToAdd);
    AdminEventRepresentation adminEvent = assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, adminEventPath + "/add-models", ResourceType.PROTOCOL_MAPPER);
    try {
        List<ProtocolMapperRepresentation> eventMappers = JsonSerialization.readValue(new ByteArrayInputStream(adminEvent.getRepresentation().getBytes()), new TypeReference<List<ProtocolMapperRepresentation>>() {
        });
        Assert.assertEquals(eventMappers.size(), mappersToAdd.size());
        for (int i = 0; i < mappersToAdd.size(); i++) {
            ProtocolMapperRepresentation repExpected = mappersToAdd.get(i);
            ProtocolMapperRepresentation repActual = eventMappers.get(i);
            assertEqualMappers(repExpected, repActual);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    List<ProtocolMapperRepresentation> newMappers = resource.getMappersPerProtocol(protocolName);
    assertEquals(oldMappers.size() + mappersToAdd.size(), newMappers.size());
    for (ProtocolMapperRepresentation rep : mappersToAdd) {
        assertTrue(containsMapper(newMappers, rep));
    }
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) ByteArrayInputStream(java.io.ByteArrayInputStream) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 10 with AdminEventRepresentation

use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.

the class PartialImportTest method testAddUsersWithTermsAndConditions.

@Test
public void testAddUsersWithTermsAndConditions() {
    assertAdminEvents.clear();
    setFail();
    addUsersWithTermsAndConditions();
    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();
        assertTrue(user.getUsername().startsWith(USER_PREFIX));
        Assert.assertTrue(userIds.contains(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)

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