use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.
the class DefaultCasEventListener method handleCasAuthenticationTransactionFailureEvent.
/**
* Handle cas authentication policy failure event.
*
* @param event the event
*/
@EventListener
public void handleCasAuthenticationTransactionFailureEvent(final CasAuthenticationTransactionFailureEvent event) {
if (this.casEventRepository != null) {
final CasEvent dto = prepareCasEvent(event);
dto.setPrincipalId(event.getCredential().getId());
dto.putId(CasAuthenticationPolicyFailureEvent.class.getSimpleName());
this.casEventRepository.save(dto);
}
}
use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.
the class DefaultCasEventListener method handleCasRiskyAuthenticationDetectedEvent.
/**
* Handle cas risky authentication detected event.
*
* @param event the event
*/
@EventListener
public void handleCasRiskyAuthenticationDetectedEvent(final CasRiskyAuthenticationDetectedEvent event) {
if (this.casEventRepository != null) {
final CasEvent dto = prepareCasEvent(event);
dto.putId(event.getService().getName());
dto.setPrincipalId(event.getAuthentication().getPrincipal().getId());
this.casEventRepository.save(dto);
}
}
use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.
the class DefaultCasEventListener method prepareCasEvent.
private static CasEvent prepareCasEvent(final AbstractCasEvent event) {
final CasEvent dto = new CasEvent();
dto.setType(event.getClass().getCanonicalName());
dto.putTimestamp(event.getTimestamp());
dto.setCreationTime(DateTimeUtils.zonedDateTimeOf(event.getTimestamp()).toString());
final ClientInfo clientInfo = ClientInfoHolder.getClientInfo();
dto.putClientIpAddress(clientInfo.getClientIpAddress());
dto.putServerIpAddress(clientInfo.getServerIpAddress());
dto.putAgent(WebUtils.getHttpServletRequestUserAgentFromRequestContext());
final GeoLocationRequest location = WebUtils.getHttpServletRequestGeoLocationFromRequestContext();
if (location != null) {
dto.putGeoLocation(location);
}
return dto;
}
use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.
the class DateTimeAuthenticationRequestRiskCalculator method calculateScore.
@Override
protected BigDecimal calculateScore(final HttpServletRequest request, final Authentication authentication, final RegisteredService service, final Collection<CasEvent> events) {
final ZonedDateTime timestamp = ZonedDateTime.now(ZoneOffset.UTC);
LOGGER.debug("Filtering authentication events for timestamp [{}]", timestamp);
final int hoursFromNow = timestamp.plusHours(windowInHours).getHour();
final int hoursBeforeNow = timestamp.minusHours(windowInHours).getHour();
final long count = events.stream().map(time -> {
final Instant instant = ChronoZonedDateTime.from(time.getCreationTime()).toInstant();
final ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
return zdt.getHour();
}).filter(hour -> hour <= hoursFromNow && hour >= hoursBeforeNow).count();
LOGGER.debug("Total authentication events found for [{}] in a [{}]h window: [{}]", timestamp, windowInHours, count);
if (count == events.size()) {
LOGGER.debug("Principal [{}] has always authenticated from [{}]", authentication.getPrincipal(), timestamp);
return LOWEST_RISK_SCORE;
}
return getFinalAveragedScore(count, events.size());
}
use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.
the class MockTicketGrantingTicketCreatedEventProducer method createEvent.
private static void createEvent(final int i, final CasEventRepository casEventRepository) {
final CasEvent dto = new CasEvent();
dto.setType(CasTicketGrantingTicketCreatedEvent.class.getName());
dto.putTimestamp(new Date().getTime());
dto.setCreationTime(ZonedDateTime.now(ZoneOffset.UTC).minusDays(5).toString());
dto.putId(TicketIdSanitizationUtils.sanitize("TGT-" + i + "-" + RandomStringUtils.randomAlphanumeric(16)));
dto.setPrincipalId("casuser");
dto.putClientIpAddress(getMockClientIpAddress());
dto.putServerIpAddress("127.0.0.1");
dto.putAgent(getMockUserAgent());
dto.putGeoLocation(getMockGeoLocation());
casEventRepository.save(dto);
}
Aggregations