Search in sources :

Example 1 with GeoLocationRequest

use of org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest 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;
}
Also used : AbstractCasEvent(org.apereo.cas.support.events.AbstractCasEvent) CasEvent(org.apereo.cas.support.events.dao.CasEvent) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)

Example 2 with GeoLocationRequest

use of org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest in project cas by apereo.

the class AdaptiveMultifactorAuthenticationPolicyEventResolver method checkRequestGeoLocation.

private boolean checkRequestGeoLocation(final String clientIp, final String mfaMethod, final String pattern) {
    if (this.geoLocationService != null) {
        final GeoLocationRequest location = WebUtils.getHttpServletRequestGeoLocationFromRequestContext();
        final GeoLocationResponse loc = this.geoLocationService.locate(clientIp, location);
        if (loc != null) {
            final String address = loc.build();
            if (address.matches(pattern)) {
                LOGGER.debug("Current address [{}] at [{}] matches the provided pattern [{}] for " + "adaptive authentication and is required to use [{}]", address, clientIp, pattern, mfaMethod);
                return true;
            }
        }
    }
    return false;
}
Also used : GeoLocationResponse(org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)

Example 3 with GeoLocationRequest

use of org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest in project cas by apereo.

the class HttpRequestUtils method getHttpServletRequestGeoLocation.

/**
 * Gets http servlet request geo location.
 *
 * @param request the request
 * @return the http servlet request geo location
 */
public static GeoLocationRequest getHttpServletRequestGeoLocation(final HttpServletRequest request) {
    final int latIndex = 0;
    final int longIndex = 1;
    final int accuracyIndex = 2;
    final int timeIndex = 3;
    final GeoLocationRequest loc = new GeoLocationRequest();
    if (request != null) {
        final String geoLocationParam = request.getParameter("geolocation");
        if (StringUtils.isNotBlank(geoLocationParam)) {
            final List<String> geoLocation = Splitter.on(",").splitToList(geoLocationParam);
            loc.setLatitude(geoLocation.get(latIndex));
            loc.setLongitude(geoLocation.get(longIndex));
            loc.setAccuracy(geoLocation.get(accuracyIndex));
            loc.setTimestamp(geoLocation.get(timeIndex));
        }
    }
    return loc;
}
Also used : GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)

Example 4 with GeoLocationRequest

use of org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest in project cas by apereo.

the class CasEvent method getGeoLocation.

/**
 * Gets geo location.
 *
 * @return the geo location
 */
@JsonIgnore
public GeoLocationRequest getGeoLocation() {
    val request = new GeoLocationRequest();
    request.setAccuracy(get(FIELD_GEO_ACCURACY));
    request.setTimestamp(get(FIELD_GEO_TIMESTAMP));
    request.setLongitude(get(FIELD_GEO_LONGITUDE));
    request.setLatitude(get(FIELD_GEO_LATITUDE));
    return request;
}
Also used : lombok.val(lombok.val) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 5 with GeoLocationRequest

use of org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest in project cas by apereo.

the class DefaultAdaptiveAuthenticationPolicyTests method verifyActionGeoLocationRejected.

@Test
public void verifyActionGeoLocationRejected() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, USER_AGENT);
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val geoRequest = new GeoLocationRequest(51.5, -0.118);
    val props = new AdaptiveAuthenticationProperties();
    props.getPolicy().setRejectCountries("UK");
    val service = mock(GeoLocationService.class);
    val response = new GeoLocationResponse();
    response.addAddress("UK");
    response.setLatitude(Double.parseDouble(geoRequest.getLatitude()));
    response.setLongitude(Double.parseDouble(geoRequest.getLongitude()));
    when(service.locate(anyString(), any())).thenReturn(response);
    val p = new DefaultAdaptiveAuthenticationPolicy(service, IPAddressIntelligenceService.allowed(), props);
    assertFalse(p.apply(new MockRequestContext(), USER_AGENT, geoRequest));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) GeoLocationResponse(org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockRequestContext(org.springframework.webflow.test.MockRequestContext) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) Test(org.junit.jupiter.api.Test)

Aggregations

GeoLocationRequest (org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)20 lombok.val (lombok.val)13 GeoLocationResponse (org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse)7 Test (org.junit.jupiter.api.Test)7 AdaptiveAuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties)5 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)5 MockRequestContext (org.springframework.webflow.test.MockRequestContext)5 CasEvent (org.apereo.cas.support.events.dao.CasEvent)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 GeoLocationService (org.apereo.cas.authentication.adaptive.geo.GeoLocationService)3 ClientInfoHolder (org.apereo.inspektr.common.web.ClientInfoHolder)3 BigDecimal (java.math.BigDecimal)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Authentication (org.apereo.cas.authentication.Authentication)2 RegisteredService (org.apereo.cas.services.RegisteredService)2 CasEventRepository (org.apereo.cas.support.events.CasEventRepository)2 WebUtils (org.apereo.cas.web.support.WebUtils)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 Collection (java.util.Collection)1