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);
}
}
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);
}
}
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());
}
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;
}
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;
}
Aggregations