Search in sources :

Example 1 with EventType

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

the class JpaEventQuery method type.

@Override
public EventQuery type(EventType... types) {
    List<String> eventStrings = new LinkedList<String>();
    for (EventType e : types) {
        eventStrings.add(e.toString());
    }
    predicates.add(root.get("type").in(eventStrings));
    return this;
}
Also used : EventType(org.keycloak.events.EventType) LinkedList(java.util.LinkedList)

Example 2 with EventType

use of org.keycloak.events.EventType 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)

Example 3 with EventType

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

the class LoginActionsService method brokerLoginFlow.

protected Response brokerLoginFlow(String authSessionId, String code, String execution, String clientId, String tabId, String flowPath) {
    boolean firstBrokerLogin = flowPath.equals(FIRST_BROKER_LOGIN_PATH);
    EventType eventType = firstBrokerLogin ? EventType.IDENTITY_PROVIDER_FIRST_LOGIN : EventType.IDENTITY_PROVIDER_POST_LOGIN;
    event.event(eventType);
    SessionCodeChecks checks = checksForCode(authSessionId, code, execution, clientId, tabId, flowPath);
    if (!checks.verifyActiveAndValidAction(AuthenticationSessionModel.Action.AUTHENTICATE.name(), ClientSessionCode.ActionType.LOGIN)) {
        return checks.getResponse();
    }
    event.detail(Details.CODE_ID, code);
    final AuthenticationSessionModel authSession = checks.getAuthenticationSession();
    processLocaleParam(authSession);
    String noteKey = firstBrokerLogin ? AbstractIdpAuthenticator.BROKERED_CONTEXT_NOTE : PostBrokerLoginConstants.PBL_BROKERED_IDENTITY_CONTEXT;
    SerializedBrokeredIdentityContext serializedCtx = SerializedBrokeredIdentityContext.readFromAuthenticationSession(authSession, noteKey);
    if (serializedCtx == null) {
        ServicesLogger.LOGGER.notFoundSerializedCtxInClientSession(noteKey);
        throw new WebApplicationException(ErrorPage.error(session, authSession, Response.Status.BAD_REQUEST, "Not found serialized context in authenticationSession."));
    }
    BrokeredIdentityContext brokerContext = serializedCtx.deserialize(session, authSession);
    final String identityProviderAlias = brokerContext.getIdpConfig().getAlias();
    String flowId = firstBrokerLogin ? brokerContext.getIdpConfig().getFirstBrokerLoginFlowId() : brokerContext.getIdpConfig().getPostBrokerLoginFlowId();
    if (flowId == null) {
        ServicesLogger.LOGGER.flowNotConfigForIDP(identityProviderAlias);
        throw new WebApplicationException(ErrorPage.error(session, authSession, Response.Status.BAD_REQUEST, "Flow not configured for identity provider"));
    }
    AuthenticationFlowModel brokerLoginFlow = realm.getAuthenticationFlowById(flowId);
    if (brokerLoginFlow == null) {
        ServicesLogger.LOGGER.flowNotFoundForIDP(flowId, identityProviderAlias);
        throw new WebApplicationException(ErrorPage.error(session, authSession, Response.Status.BAD_REQUEST, "Flow not found for identity provider"));
    }
    event.detail(Details.IDENTITY_PROVIDER, identityProviderAlias).detail(Details.IDENTITY_PROVIDER_USERNAME, brokerContext.getUsername());
    AuthenticationProcessor processor = new AuthenticationProcessor() {

        @Override
        public Response authenticateOnly() throws AuthenticationFlowException {
            Response challenge = super.authenticateOnly();
            if (challenge != null) {
                if ("true".equals(authenticationSession.getAuthNote(FORWARDED_PASSIVE_LOGIN))) {
                    // forwarded passive login is incompatible with challenges created by the broker flows.
                    logger.errorf("Challenge encountered when executing %s flow. Auth requests with prompt=none are incompatible with challenges", flowPath);
                    LoginProtocol protocol = session.getProvider(LoginProtocol.class, authSession.getProtocol());
                    protocol.setRealm(realm).setHttpHeaders(headers).setUriInfo(session.getContext().getUri()).setEventBuilder(event);
                    return protocol.sendError(authSession, Error.PASSIVE_INTERACTION_REQUIRED);
                }
            }
            return challenge;
        }

        @Override
        protected Response authenticationComplete() {
            if (firstBrokerLogin) {
                authSession.setAuthNote(AbstractIdpAuthenticator.FIRST_BROKER_LOGIN_SUCCESS, identityProviderAlias);
            } else {
                String authStateNoteKey = PostBrokerLoginConstants.PBL_AUTH_STATE_PREFIX + identityProviderAlias;
                authSession.setAuthNote(authStateNoteKey, "true");
            }
            return redirectToAfterBrokerLoginEndpoint(authSession, firstBrokerLogin);
        }
    };
    return processFlow(checks.isActionRequest(), execution, authSession, flowPath, brokerLoginFlow, null, processor);
}
Also used : Response(javax.ws.rs.core.Response) AuthenticationSessionModel(org.keycloak.sessions.AuthenticationSessionModel) RootAuthenticationSessionModel(org.keycloak.sessions.RootAuthenticationSessionModel) WebApplicationException(javax.ws.rs.WebApplicationException) EventType(org.keycloak.events.EventType) AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel) SerializedBrokeredIdentityContext(org.keycloak.authentication.authenticators.broker.util.SerializedBrokeredIdentityContext) AuthenticationProcessor(org.keycloak.authentication.AuthenticationProcessor) OIDCLoginProtocol(org.keycloak.protocol.oidc.OIDCLoginProtocol) LoginProtocol(org.keycloak.protocol.LoginProtocol) BrokeredIdentityContext(org.keycloak.broker.provider.BrokeredIdentityContext) SerializedBrokeredIdentityContext(org.keycloak.authentication.authenticators.broker.util.SerializedBrokeredIdentityContext)

Example 4 with EventType

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

the class RealmAdminResource method getRealmEventsConfig.

/**
 * Get the events provider configuration
 *
 * Returns JSON object with events provider configuration
 *
 * @return
 */
@GET
@NoCache
@Path("events/config")
@Produces(MediaType.APPLICATION_JSON)
public RealmEventsConfigRepresentation getRealmEventsConfig() {
    auth.realm().requireViewEvents();
    RealmEventsConfigRepresentation config = ModelToRepresentation.toEventsConfigReprensetation(realm);
    if (config.getEnabledEventTypes() == null || config.getEnabledEventTypes().isEmpty()) {
        List<String> eventTypes = Arrays.stream(EventType.values()).filter(EventType::isSaveByDefault).map(EventType::name).collect(Collectors.toList());
        config.setEnabledEventTypes(eventTypes);
    }
    return config;
}
Also used : RealmEventsConfigRepresentation(org.keycloak.representations.idm.RealmEventsConfigRepresentation) EventType(org.keycloak.events.EventType) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

EventType (org.keycloak.events.EventType)4 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 NoCache (org.jboss.resteasy.annotations.cache.NoCache)2 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 AuthenticationProcessor (org.keycloak.authentication.AuthenticationProcessor)1 SerializedBrokeredIdentityContext (org.keycloak.authentication.authenticators.broker.util.SerializedBrokeredIdentityContext)1 BrokeredIdentityContext (org.keycloak.broker.provider.BrokeredIdentityContext)1 EventQuery (org.keycloak.events.EventQuery)1 EventStoreProvider (org.keycloak.events.EventStoreProvider)1 AdminEventQuery (org.keycloak.events.admin.AdminEventQuery)1 AuthenticationFlowModel (org.keycloak.models.AuthenticationFlowModel)1 ModelToRepresentation (org.keycloak.models.utils.ModelToRepresentation)1 LoginProtocol (org.keycloak.protocol.LoginProtocol)1 OIDCLoginProtocol (org.keycloak.protocol.oidc.OIDCLoginProtocol)1 RealmEventsConfigRepresentation (org.keycloak.representations.idm.RealmEventsConfigRepresentation)1