Search in sources :

Example 1 with AuthDetailsRepresentation

use of org.keycloak.representations.idm.AuthDetailsRepresentation 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 2 with AuthDetailsRepresentation

use of org.keycloak.representations.idm.AuthDetailsRepresentation 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 3 with AuthDetailsRepresentation

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

the class AssertAdminEvents method defaultAuthDetails.

private AuthDetailsRepresentation defaultAuthDetails() {
    String accessTokenString = context.getAdminClient().tokenManager().getAccessTokenString();
    try {
        JWSInput input = new JWSInput(accessTokenString);
        AccessToken token = input.readJsonContent(AccessToken.class);
        AuthDetailsRepresentation authDetails = new AuthDetailsRepresentation();
        String realmId = token.getIssuer().substring(token.getIssuer().lastIndexOf('/') + 1);
        authDetails.setRealmId(realmId);
        authDetails.setUserId(token.getSubject());
        return authDetails;
    } catch (JWSInputException jwe) {
        throw new RuntimeException(jwe);
    }
}
Also used : AccessToken(org.keycloak.representations.AccessToken) JWSInputException(org.keycloak.jose.jws.JWSInputException) JWSInput(org.keycloak.jose.jws.JWSInput) AuthDetailsRepresentation(org.keycloak.representations.idm.AuthDetailsRepresentation)

Example 4 with AuthDetailsRepresentation

use of org.keycloak.representations.idm.AuthDetailsRepresentation 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

AuthDetailsRepresentation (org.keycloak.representations.idm.AuthDetailsRepresentation)4 AdminEventRepresentation (org.keycloak.representations.idm.AdminEventRepresentation)3 Test (org.junit.Test)2 RealmResource (org.keycloak.admin.client.resource.RealmResource)1 JWSInput (org.keycloak.jose.jws.JWSInput)1 JWSInputException (org.keycloak.jose.jws.JWSInputException)1 AccessToken (org.keycloak.representations.AccessToken)1