Search in sources :

Example 1 with AdminEventRepresentation

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

the class UserTotpTest method setupTotp.

@Test
public void setupTotp() {
    totpPage.open();
    loginPage.login("test-user@localhost", "password");
    events.expectLogin().client("account").detail(Details.REDIRECT_URI, getAccountRedirectUrl() + "?path=totp").assertEvent();
    Assert.assertTrue(totpPage.isCurrent());
    Assert.assertFalse(driver.getPageSource().contains("Remove Google"));
    totpPage.configure(totp.generateTOTP(totpPage.getTotpSecret()));
    Assert.assertEquals("Mobile authenticator configured.", profilePage.getSuccess());
    events.expectAccount(EventType.UPDATE_TOTP).assertEvent();
    Assert.assertTrue(driver.getPageSource().contains("pficon-delete"));
    List<UserRepresentation> users = adminClient.realms().realm("test").users().search("test-user@localhost", null, null, null, 0, 1);
    String userId = users.get(0).getId();
    testingClient.testing().clearAdminEventQueue();
    CredentialRepresentation totpCredential = adminClient.realms().realm("test").users().get(userId).credentials().stream().filter(c -> OTPCredentialModel.TYPE.equals(c.getType())).findFirst().get();
    adminClient.realms().realm("test").users().get(userId).removeCredential(totpCredential.getId());
    totpPage.open();
    Assert.assertFalse(driver.getPageSource().contains("pficon-delete"));
    AdminEventRepresentation event = testingClient.testing().pollAdminEvent();
    Assert.assertNotNull(event);
    Assert.assertEquals(OperationType.ACTION.name(), event.getOperationType());
    Assert.assertEquals("users/" + userId + "/credentials/" + totpCredential.getId(), event.getResourcePath());
}
Also used : CredentialRepresentation(org.keycloak.representations.idm.CredentialRepresentation) AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 2 with AdminEventRepresentation

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

the class AdminEventStoreProviderTest method create.

private AdminEventRepresentation create(long time, String realmId, OperationType operation, String authRealmId, String authClientId, String authUserId, String authIpAddress, String resourcePath, String resourceType, String error) {
    AdminEventRepresentation e = new AdminEventRepresentation();
    e.setTime(time);
    e.setRealmId(realmId);
    e.setOperationType(operation.toString());
    AuthDetailsRepresentation authDetails = new AuthDetailsRepresentation();
    authDetails.setRealmId(authRealmId);
    authDetails.setClientId(authClientId);
    authDetails.setUserId(authUserId);
    authDetails.setIpAddress(authIpAddress);
    e.setAuthDetails(authDetails);
    e.setResourcePath(resourcePath);
    e.setResourceType(resourceType);
    e.setError(error);
    return e;
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) AuthDetailsRepresentation(org.keycloak.representations.idm.AuthDetailsRepresentation)

Example 3 with AdminEventRepresentation

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

the class AdminEventTest method testGetRepresentation.

@Test
public void testGetRepresentation() {
    configRep.setAdminEventsDetailsEnabled(Boolean.TRUE);
    saveConfig();
    createUser("user2");
    AdminEventRepresentation event = events().stream().filter(adminEventRep -> adminEventRep.getOperationType().equals("CREATE")).findFirst().orElseThrow(() -> new IllegalStateException("Wasn't able to obtain CREATE admin event."));
    assertThat(event.getRepresentation(), is(notNullValue()));
    assertThat(event.getRepresentation(), allOf(containsString("foo"), containsString("bar")));
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) Test(org.junit.Test)

Example 4 with AdminEventRepresentation

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

the class AdminEventTest method adminEventAttributeTest.

@Test
public void adminEventAttributeTest() {
    createUser("user5");
    List<AdminEventRepresentation> events = events();
    assertThat(events().size(), is(equalTo(1)));
    AdminEventRepresentation event = events.get(0);
    assertThat(event.getTime(), is(greaterThan(0L)));
    assertThat(event.getRealmId(), is(equalTo(realmName())));
    assertThat(event.getOperationType(), is(equalTo("CREATE")));
    assertThat(event.getResourcePath(), is(notNullValue()));
    assertThat(event.getError(), is(nullValue()));
    AuthDetailsRepresentation details = event.getAuthDetails();
    assertThat(details.getRealmId(), is(equalTo("master")));
    assertThat(details.getClientId(), is(notNullValue()));
    assertThat(details.getUserId(), is(notNullValue()));
    assertThat(details.getIpAddress(), is(notNullValue()));
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) AuthDetailsRepresentation(org.keycloak.representations.idm.AuthDetailsRepresentation) Test(org.junit.Test)

Example 5 with AdminEventRepresentation

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

the class AdminEventTest method checkUpdateRealmEventsConfigEvent.

private void checkUpdateRealmEventsConfigEvent(int size) {
    List<AdminEventRepresentation> events = events();
    assertThat(events.size(), is(equalTo(size)));
    AdminEventRepresentation event = events().get(0);
    assertThat(event.getOperationType(), is(equalTo("UPDATE")));
    assertThat(event.getRealmId(), is(equalTo(realmName())));
    assertThat(event.getResourcePath(), is(equalTo("events/config")));
    assertThat(event.getAuthDetails().getRealmId(), is(equalTo("master")));
    assertThat(event.getRepresentation(), is(notNullValue()));
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation)

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