use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.
the class MongoDbCasEventRepository method getEventsForPrincipal.
@Override
public Stream<? extends CasEvent> getEventsForPrincipal(final String id) {
val query = new Query();
query.addCriteria(Criteria.where(PRINCIPAL_ID_PARAM).is(id));
return this.mongoTemplate.stream(query, CasEvent.class, this.collectionName).stream();
}
use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.
the class MongoDbCasEventRepository method getEventsForPrincipal.
@Override
public Stream<? extends CasEvent> getEventsForPrincipal(final String principal, final ZonedDateTime dateTime) {
val query = new Query();
query.addCriteria(Criteria.where(PRINCIPAL_ID_PARAM).is(principal).and(CREATION_TIME_PARAM).gte(dateTime.toString()));
return this.mongoTemplate.stream(query, CasEvent.class, this.collectionName).stream();
}
use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.
the class AbstractCasEventRepositoryTests method getCasEvent.
private CasEvent getCasEvent(final String user) {
val ticket = new MockTicketGrantingTicket(user);
val event = new CasTicketGrantingTicketCreatedEvent(this, ticket);
val dto = new CasEvent();
dto.setType(event.getClass().getCanonicalName());
dto.putTimestamp(event.getTimestamp());
dto.setCreationTime(event.getTicketGrantingTicket().getCreationTime().format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
dto.putEventId(event.getTicketGrantingTicket().getId());
dto.putClientIpAddress("1.2.3.4");
dto.putServerIpAddress("1.2.3.4");
val location = new GeoLocationRequest(1234, 1234);
location.setAccuracy("80");
location.setTimestamp(String.valueOf(event.getTimestamp()));
dto.putGeoLocation(location);
dto.setPrincipalId(event.getTicketGrantingTicket().getAuthentication().getPrincipal().getId());
return dto;
}
use of org.apereo.cas.support.events.dao.CasEvent in project cas by apereo.
the class CasAuthenticationAuthenticationEventListener method prepareCasEvent.
private static CasEvent prepareCasEvent(final AbstractCasEvent event) {
val dto = new CasEvent();
dto.setType(event.getClass().getCanonicalName());
dto.putTimestamp(event.getTimestamp());
val dt = DateTimeUtils.zonedDateTimeOf(Instant.ofEpochMilli(event.getTimestamp()));
dto.setCreationTime(dt.toString());
val clientInfo = ClientInfoHolder.getClientInfo();
if (clientInfo != null) {
dto.putClientIpAddress(clientInfo.getClientIpAddress());
dto.putServerIpAddress(clientInfo.getServerIpAddress());
dto.putAgent(clientInfo.getUserAgent());
val location = HttpRequestUtils.getHttpServletRequestGeoLocation(clientInfo.getGeoLocation());
dto.putGeoLocation(location);
} else {
LOGGER.trace("No client information is available. The final event cannot track client location, user agent or IP addresses");
}
return dto;
}
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 Supplier<Stream<? extends CasEvent>> events) {
val loc = WebUtils.getHttpServletRequestGeoLocation(request);
if (loc != null && loc.isValid()) {
LOGGER.debug("Filtering authentication events for geolocation [{}]", loc);
val count = events.get().filter(e -> e.getGeoLocation().equals(loc)).count();
LOGGER.debug("Total authentication events found for [{}]: [{}]", loc, count);
return calculateScoreBasedOnEventsCount(authentication, events, count);
}
val remoteAddr = ClientInfoHolder.getClientInfo().getClientIpAddress();
LOGGER.debug("Filtering authentication events for location based on ip [{}]", remoteAddr);
val response = this.geoLocationService.locate(remoteAddr);
if (response != null) {
val count = events.get().filter(e -> e.getGeoLocation().equals(new GeoLocationRequest(response.getLatitude(), response.getLongitude()))).count();
LOGGER.debug("Total authentication events found for location of [{}]: [{}]", remoteAddr, count);
return calculateScoreBasedOnEventsCount(authentication, events, count);
}
LOGGER.debug("Request does not contain enough geolocation data");
return HIGHEST_RISK_SCORE;
}
Aggregations