Search in sources :

Example 1 with EventStoreProvider

use of org.keycloak.events.EventStoreProvider in project keycloak by keycloak.

the class ClearExpiredEvents method run.

@Override
public void run(KeycloakSession session) {
    long currentTimeMillis = Time.currentTimeMillis();
    EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
    if (eventStore != null) {
        eventStore.clearExpiredEvents();
    }
    long took = Time.currentTimeMillis() - currentTimeMillis;
    logger.debugf("ClearExpiredEvents finished in %d ms", took);
}
Also used : EventStoreProvider(org.keycloak.events.EventStoreProvider)

Example 2 with EventStoreProvider

use of org.keycloak.events.EventStoreProvider in project keycloak by keycloak.

the class TestingResourceProvider method getAdminEvents.

/**
 * Get admin events
 *
 * Returns all admin events, or filters events based on URL query parameters listed here
 *
 * @param realmId
 * @param operationTypes
 * @param authRealm
 * @param authClient
 * @param authUser user id
 * @param authIpAddress
 * @param resourcePath
 * @param dateFrom
 * @param dateTo
 * @param firstResult
 * @param maxResults
 * @return
 */
@Path("query-admin-events")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Stream<AdminEventRepresentation> getAdminEvents(@QueryParam("realmId") String realmId, @QueryParam("operationTypes") List<String> operationTypes, @QueryParam("authRealm") String authRealm, @QueryParam("authClient") String authClient, @QueryParam("authUser") String authUser, @QueryParam("authIpAddress") String authIpAddress, @QueryParam("resourcePath") String resourcePath, @QueryParam("dateFrom") String dateFrom, @QueryParam("dateTo") String dateTo, @QueryParam("first") Integer firstResult, @QueryParam("max") Integer maxResults) {
    EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
    AdminEventQuery query = eventStore.createAdminQuery();
    if (realmId != null) {
        query.realm(realmId);
    }
    if (authRealm != null) {
        query.authRealm(authRealm);
    }
    if (authClient != null) {
        query.authClient(authClient);
    }
    if (authUser != null) {
        query.authUser(authUser);
    }
    if (authIpAddress != null) {
        query.authIpAddress(authIpAddress);
    }
    if (resourcePath != null) {
        query.resourcePath(resourcePath);
    }
    if (operationTypes != null && !operationTypes.isEmpty()) {
        OperationType[] t = new OperationType[operationTypes.size()];
        for (int i = 0; i < t.length; i++) {
            t[i] = OperationType.valueOf(operationTypes.get(i));
        }
        query.operation(t);
    }
    if (dateFrom != null) {
        Date from = formatDate(dateFrom, "Date(From)");
        query.fromTime(from);
    }
    if (dateTo != null) {
        Date to = formatDate(dateTo, "Date(To)");
        query.toTime(to);
    }
    if (firstResult != null || maxResults != null) {
        if (firstResult == null) {
            firstResult = 0;
        }
        if (maxResults == null) {
            maxResults = 100;
        }
        query.firstResult(firstResult);
        query.maxResults(maxResults);
    }
    return query.getResultStream().map(ModelToRepresentation::toRepresentation);
}
Also used : AdminEventQuery(org.keycloak.events.admin.AdminEventQuery) OperationType(org.keycloak.events.admin.OperationType) ModelToRepresentation(org.keycloak.models.utils.ModelToRepresentation) Date(java.util.Date) EventStoreProvider(org.keycloak.events.EventStoreProvider) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 3 with EventStoreProvider

use of org.keycloak.events.EventStoreProvider in project keycloak by keycloak.

the class TestingResourceProvider method clearAdminEventStore.

@GET
@Path("/clear-admin-event-store-for-realm")
@Produces(MediaType.APPLICATION_JSON)
public Response clearAdminEventStore(@QueryParam("realmId") String realmId) {
    EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
    eventStore.clearAdmin(realmId);
    return Response.noContent().build();
}
Also used : EventStoreProvider(org.keycloak.events.EventStoreProvider) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with EventStoreProvider

use of org.keycloak.events.EventStoreProvider in project keycloak by keycloak.

the class TestingResourceProvider method clearAdminEventStore.

@GET
@Path("/clear-admin-event-store")
@Produces(MediaType.APPLICATION_JSON)
public Response clearAdminEventStore() {
    EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
    eventStore.clearAdmin();
    return Response.noContent().build();
}
Also used : EventStoreProvider(org.keycloak.events.EventStoreProvider) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with EventStoreProvider

use of org.keycloak.events.EventStoreProvider in project keycloak by keycloak.

the class TestingResourceProvider method queryEvents.

/**
 * Query events
 * <p>
 * Returns all events, or filters them based on URL query parameters listed here
 *
 * @param realmId     The realm
 * @param types       The types of events to return
 * @param client      App or oauth client name
 * @param user        User id
 * @param dateFrom    From date
 * @param dateTo      To date
 * @param ipAddress   IP address
 * @param firstResult Paging offset
 * @param maxResults  Paging size
 * @return
 */
@Path("query-events")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Stream<EventRepresentation> queryEvents(@QueryParam("realmId") String realmId, @QueryParam("type") List<String> types, @QueryParam("client") String client, @QueryParam("user") String user, @QueryParam("dateFrom") String dateFrom, @QueryParam("dateTo") String dateTo, @QueryParam("ipAddress") String ipAddress, @QueryParam("first") Integer firstResult, @QueryParam("max") Integer maxResults) {
    EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
    EventQuery query = eventStore.createQuery();
    if (realmId != null) {
        query.realm(realmId);
    }
    if (client != null) {
        query.client(client);
    }
    if (types != null & !types.isEmpty()) {
        EventType[] t = new EventType[types.size()];
        for (int i = 0; i < t.length; i++) {
            t[i] = EventType.valueOf(types.get(i));
        }
        query.type(t);
    }
    if (user != null) {
        query.user(user);
    }
    if (dateFrom != null) {
        Date from = formatDate(dateFrom, "Date(From)");
        query.fromDate(from);
    }
    if (dateTo != null) {
        Date to = formatDate(dateTo, "Date(To)");
        query.toDate(to);
    }
    if (ipAddress != null) {
        query.ipAddress(ipAddress);
    }
    if (firstResult != null) {
        query.firstResult(firstResult);
    }
    if (maxResults != null) {
        query.maxResults(maxResults);
    }
    return query.getResultStream().map(ModelToRepresentation::toRepresentation);
}
Also used : EventType(org.keycloak.events.EventType) AdminEventQuery(org.keycloak.events.admin.AdminEventQuery) EventQuery(org.keycloak.events.EventQuery) ModelToRepresentation(org.keycloak.models.utils.ModelToRepresentation) Date(java.util.Date) EventStoreProvider(org.keycloak.events.EventStoreProvider) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

EventStoreProvider (org.keycloak.events.EventStoreProvider)17 Path (javax.ws.rs.Path)14 GET (javax.ws.rs.GET)10 Produces (javax.ws.rs.Produces)9 NoCache (org.jboss.resteasy.annotations.cache.NoCache)4 Date (java.util.Date)3 AdminEventQuery (org.keycloak.events.admin.AdminEventQuery)3 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 Test (org.junit.Test)2 OperationType (org.keycloak.events.admin.OperationType)2 ModelToRepresentation (org.keycloak.models.utils.ModelToRepresentation)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1