Search in sources :

Example 21 with CasEvent

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

the class IpAddressAuthenticationRequestRiskCalculator method calculateScore.

@Override
protected BigDecimal calculateScore(final HttpServletRequest request, final Authentication authentication, final RegisteredService service, final Supplier<Stream<? extends CasEvent>> events) {
    val remoteAddr = ClientInfoHolder.getClientInfo().getClientIpAddress();
    LOGGER.debug("Filtering authentication events for ip address [{}]", remoteAddr);
    val count = events.get().filter(e -> e.getClientIpAddress().equalsIgnoreCase(remoteAddr)).count();
    LOGGER.debug("Total authentication events found for [{}]: [{}]", remoteAddr, count);
    return calculateScoreBasedOnEventsCount(authentication, events, count);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) CasEventRepository(org.apereo.cas.support.events.CasEventRepository) BigDecimal(java.math.BigDecimal) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) Stream(java.util.stream.Stream) Authentication(org.apereo.cas.authentication.Authentication) lombok.val(lombok.val) ClientInfoHolder(org.apereo.inspektr.common.web.ClientInfoHolder) Supplier(java.util.function.Supplier) RegisteredService(org.apereo.cas.services.RegisteredService) CasEvent(org.apereo.cas.support.events.dao.CasEvent)

Example 22 with CasEvent

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

the class UserAgentAuthenticationRequestRiskCalculator method calculateScore.

@Override
protected BigDecimal calculateScore(final HttpServletRequest request, final Authentication authentication, final RegisteredService service, final Supplier<Stream<? extends CasEvent>> events) {
    val agent = HttpRequestUtils.getHttpServletRequestUserAgent(request);
    LOGGER.debug("Filtering authentication events for user agent [{}]", agent);
    val count = events.get().filter(e -> StringUtils.isNotBlank(e.getAgent())).filter(e -> e.getAgent().equalsIgnoreCase(agent)).count();
    LOGGER.debug("Total authentication events found for [{}]: [{}]", agent, count);
    return calculateScoreBasedOnEventsCount(authentication, events, count);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) CasEventRepository(org.apereo.cas.support.events.CasEventRepository) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) RegisteredService(org.apereo.cas.services.RegisteredService) HttpRequestUtils(org.apereo.cas.util.HttpRequestUtils) BigDecimal(java.math.BigDecimal) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) Stream(java.util.stream.Stream) Authentication(org.apereo.cas.authentication.Authentication) CasEvent(org.apereo.cas.support.events.dao.CasEvent)

Example 23 with CasEvent

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

the class MongoDbCasEventRepository method getEventsOfType.

@Override
public Stream<? extends CasEvent> getEventsOfType(final String type) {
    val query = new Query();
    query.addCriteria(Criteria.where(TYPE_PARAM).is(type));
    return this.mongoTemplate.stream(query, CasEvent.class, this.collectionName).stream();
}
Also used : lombok.val(lombok.val) Query(org.springframework.data.mongodb.core.query.Query) CasEvent(org.apereo.cas.support.events.dao.CasEvent)

Example 24 with CasEvent

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

the class MongoDbCasEventRepository method getEventsOfType.

@Override
public Stream<? extends CasEvent> getEventsOfType(final String type, final ZonedDateTime dateTime) {
    val query = new Query();
    query.addCriteria(Criteria.where(TYPE_PARAM).is(type).and(CREATION_TIME_PARAM).gte(dateTime.toString()));
    return this.mongoTemplate.stream(query, CasEvent.class, this.collectionName).stream();
}
Also used : lombok.val(lombok.val) Query(org.springframework.data.mongodb.core.query.Query) CasEvent(org.apereo.cas.support.events.dao.CasEvent)

Aggregations

CasEvent (org.apereo.cas.support.events.dao.CasEvent)24 lombok.val (lombok.val)15 Query (org.springframework.data.mongodb.core.query.Query)7 BigDecimal (java.math.BigDecimal)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 Slf4j (lombok.extern.slf4j.Slf4j)6 Authentication (org.apereo.cas.authentication.Authentication)6 RegisteredService (org.apereo.cas.services.RegisteredService)6 AbstractCasEvent (org.apereo.cas.support.events.AbstractCasEvent)6 CasEventRepository (org.apereo.cas.support.events.CasEventRepository)6 Supplier (java.util.function.Supplier)4 Stream (java.util.stream.Stream)4 GeoLocationRequest (org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)4 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)4 CasTicketGrantingTicketCreatedEvent (org.apereo.cas.support.events.ticket.CasTicketGrantingTicketCreatedEvent)4 EventListener (org.springframework.context.event.EventListener)4 ClientInfoHolder (org.apereo.inspektr.common.web.ClientInfoHolder)3 ZoneOffset (java.time.ZoneOffset)2 ZonedDateTime (java.time.ZonedDateTime)2 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)2