Search in sources :

Example 6 with CasEvent

use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.

the class DefaultCasEventListener method handleCasAuthenticationPolicyFailureEvent.

/**
     * Handle cas authentication policy failure event.
     *
     * @param event the event
     */
@EventListener
public void handleCasAuthenticationPolicyFailureEvent(final CasAuthenticationPolicyFailureEvent event) {
    if (this.casEventRepository != null) {
        final CasEvent dto = prepareCasEvent(event);
        dto.setPrincipalId(event.getAuthentication().getPrincipal().getId());
        dto.putId(CasAuthenticationPolicyFailureEvent.class.getSimpleName());
        this.casEventRepository.save(dto);
    }
}
Also used : AbstractCasEvent(org.apereo.cas.support.events.AbstractCasEvent) CasEvent(org.apereo.cas.support.events.dao.CasEvent) CasAuthenticationPolicyFailureEvent(org.apereo.cas.support.events.authentication.CasAuthenticationPolicyFailureEvent) EventListener(org.springframework.context.event.EventListener)

Example 7 with CasEvent

use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.

the class DefaultCasEventListener method handleCasTicketGrantingTicketCreatedEvent.

/**
     * Handle TGT creation event.
     *
     * @param event the event
     */
@EventListener
public void handleCasTicketGrantingTicketCreatedEvent(final CasTicketGrantingTicketCreatedEvent event) {
    if (this.casEventRepository != null) {
        final CasEvent dto = prepareCasEvent(event);
        dto.putCreationTime(event.getTicketGrantingTicket().getCreationTime());
        dto.putId(TicketIdSanitizationUtils.sanitize(event.getTicketGrantingTicket().getId()));
        dto.setPrincipalId(event.getTicketGrantingTicket().getAuthentication().getPrincipal().getId());
        this.casEventRepository.save(dto);
    }
}
Also used : AbstractCasEvent(org.apereo.cas.support.events.AbstractCasEvent) CasEvent(org.apereo.cas.support.events.dao.CasEvent) EventListener(org.springframework.context.event.EventListener)

Example 8 with CasEvent

use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.

the class AbstractCasEventRepositoryTests method verifySave.

@Test
public void verifySave() {
    final TicketGrantingTicket ticket = new MockTicketGrantingTicket("casuser");
    final CasTicketGrantingTicketCreatedEvent event = new CasTicketGrantingTicketCreatedEvent(this, ticket);
    final CasEvent dto = new CasEvent();
    dto.setType(event.getClass().getCanonicalName());
    dto.putTimestamp(event.getTimestamp());
    dto.putCreationTime(event.getTicketGrantingTicket().getCreationTime());
    dto.putId(event.getTicketGrantingTicket().getId());
    dto.setPrincipalId(event.getTicketGrantingTicket().getAuthentication().getPrincipal().getId());
    getRepositoryInstance().save(dto);
    final Collection<CasEvent> col = getRepositoryInstance().load();
    assertEquals(col.size(), 1);
    assertFalse(col.stream().findFirst().get().getProperties().isEmpty());
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) CasTicketGrantingTicketCreatedEvent(org.apereo.cas.support.events.ticket.CasTicketGrantingTicketCreatedEvent) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) CasEvent(org.apereo.cas.support.events.dao.CasEvent) Test(org.junit.Test)

Example 9 with CasEvent

use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.

the class BaseAuthenticationRequestRiskCalculator method calculate.

@Override
public final AuthenticationRiskScore calculate(final Authentication authentication, final RegisteredService service, final HttpServletRequest request) {
    final Principal principal = authentication.getPrincipal();
    final Collection<CasEvent> events = getCasTicketGrantingTicketCreatedEventsFor(principal.getId());
    if (events.isEmpty()) {
        return new AuthenticationRiskScore(HIGHEST_RISK_SCORE);
    }
    final AuthenticationRiskScore score = new AuthenticationRiskScore(calculateScore(request, authentication, service, events));
    LOGGER.debug("Calculated authentication risk score by [{}] is [{}]", getClass().getSimpleName(), score);
    return score;
}
Also used : AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) CasEvent(org.apereo.cas.support.events.dao.CasEvent) Principal(org.apereo.cas.authentication.principal.Principal)

Example 10 with CasEvent

use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.

the class GeoLocationAuthenticationRequestRiskCalculator method calculateScore.

@Override
protected BigDecimal calculateScore(final HttpServletRequest request, final Authentication authentication, final RegisteredService service, final Collection<CasEvent> events) {
    final GeoLocationRequest loc = WebUtils.getHttpServletRequestGeoLocation();
    if (loc.isValid()) {
        LOGGER.debug("Filtering authentication events for geolocation [{}]", loc);
        final long count = events.stream().filter(e -> e.getGeoLocation().equals(loc)).count();
        LOGGER.debug("Total authentication events found for [{}]: [{}]", loc, count);
        if (count == events.size()) {
            LOGGER.debug("Principal [{}] has always authenticated from [{}]", authentication.getPrincipal(), loc);
            return LOWEST_RISK_SCORE;
        }
        return getFinalAveragedScore(count, events.size());
    } else {
        final String remoteAddr = ClientInfoHolder.getClientInfo().getClientIpAddress();
        LOGGER.debug("Filtering authentication events for location based on ip [{}]", remoteAddr);
        final GeoLocationResponse response = this.geoLocationService.locate(remoteAddr);
        if (response != null) {
            final long count = events.stream().filter(e -> e.getGeoLocation().equals(new GeoLocationRequest(response.getLatitude(), response.getLongitude()))).count();
            LOGGER.debug("Total authentication events found for location of [{}]: [{}]", remoteAddr, count);
            if (count == events.size()) {
                LOGGER.debug("Principal [{}] has always authenticated from [{}]", authentication.getPrincipal(), loc);
                return LOWEST_RISK_SCORE;
            }
            return getFinalAveragedScore(count, events.size());
        }
    }
    LOGGER.debug("Request does not contain enough geolocation data");
    return HIGHEST_RISK_SCORE;
}
Also used : CasEventRepository(org.apereo.cas.support.events.CasEventRepository) Logger(org.slf4j.Logger) Collection(java.util.Collection) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) LoggerFactory(org.slf4j.LoggerFactory) GeoLocationService(org.apereo.cas.authentication.adaptive.geo.GeoLocationService) Autowired(org.springframework.beans.factory.annotation.Autowired) RegisteredService(org.apereo.cas.services.RegisteredService) BigDecimal(java.math.BigDecimal) GeoLocationResponse(org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Authentication(org.apereo.cas.authentication.Authentication) ClientInfoHolder(org.apereo.inspektr.common.web.ClientInfoHolder) Qualifier(org.springframework.beans.factory.annotation.Qualifier) WebUtils(org.apereo.cas.web.support.WebUtils) CasEvent(org.apereo.cas.support.events.dao.CasEvent) GeoLocationResponse(org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)

Aggregations

CasEvent (org.apereo.cas.support.events.dao.CasEvent)10 AbstractCasEvent (org.apereo.cas.support.events.AbstractCasEvent)5 EventListener (org.springframework.context.event.EventListener)4 BigDecimal (java.math.BigDecimal)2 Collection (java.util.Collection)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Authentication (org.apereo.cas.authentication.Authentication)2 GeoLocationRequest (org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)2 RegisteredService (org.apereo.cas.services.RegisteredService)2 CasEventRepository (org.apereo.cas.support.events.CasEventRepository)2 CasAuthenticationPolicyFailureEvent (org.apereo.cas.support.events.authentication.CasAuthenticationPolicyFailureEvent)2 CasTicketGrantingTicketCreatedEvent (org.apereo.cas.support.events.ticket.CasTicketGrantingTicketCreatedEvent)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ZonedDateTime (java.time.ZonedDateTime)1 Date (java.util.Date)1 AuthenticationRiskScore (org.apereo.cas.api.AuthenticationRiskScore)1 GeoLocationResponse (org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse)1 GeoLocationService (org.apereo.cas.authentication.adaptive.geo.GeoLocationService)1 Principal (org.apereo.cas.authentication.principal.Principal)1