Search in sources :

Example 6 with GeoLocationRequest

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

the class DefaultAdaptiveAuthenticationPolicyTests method verifyActionWithNoClientInfo.

@Test
public void verifyActionWithNoClientInfo() {
    val props = new AdaptiveAuthenticationProperties();
    val service = mock(GeoLocationService.class);
    val p = new DefaultAdaptiveAuthenticationPolicy(service, IPAddressIntelligenceService.allowed(), props);
    assertTrue(p.apply(new MockRequestContext(), "something", new GeoLocationRequest()));
}
Also used : lombok.val(lombok.val) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) MockRequestContext(org.springframework.webflow.test.MockRequestContext) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) Test(org.junit.jupiter.api.Test)

Example 7 with GeoLocationRequest

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

the class GeoLocationServiceTests method verifyLocate.

@Test
public void verifyLocate() {
    HttpsURLConnection.setDefaultHostnameVerifier(CasSSLContext.disabled().getHostnameVerifier());
    HttpsURLConnection.setDefaultSSLSocketFactory(CasSSLContext.disabled().getSslContext().getSocketFactory());
    val svc = new DummyGeoLocationService();
    assertNotNull(svc.locate("1.2.3.4", new GeoLocationRequest(1, 1)));
    assertNotNull(svc.locate(new GeoLocationRequest(1, 1)));
}
Also used : lombok.val(lombok.val) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) Test(org.junit.jupiter.api.Test)

Example 8 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 geoLocationParam the geo location param
 * @return the http servlet request geo location
 */
public static GeoLocationRequest getHttpServletRequestGeoLocation(final String geoLocationParam) {
    val loc = new GeoLocationRequest();
    if (StringUtils.isNotBlank(geoLocationParam) && !StringUtils.equalsIgnoreCase(geoLocationParam, "unknown")) {
        val geoLocation = Splitter.on(",").splitToList(geoLocationParam);
        loc.setLatitude(geoLocation.get(GEO_LOC_LAT_INDEX));
        loc.setLongitude(geoLocation.get(GEO_LOC_LONG_INDEX));
        loc.setAccuracy(geoLocation.get(GEO_LOC_ACCURACY_INDEX));
        loc.setTimestamp(geoLocation.get(GEO_LOC_TIME_INDEX));
    }
    return loc;
}
Also used : lombok.val(lombok.val) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)

Example 9 with GeoLocationRequest

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

the class InfluxDbCasEventRepository method load.

@Override
public Stream<? extends CasEvent> load() {
    val results = influxDbConnectionFactory.query(InfluxDbEvent.class);
    return results.stream().map(flux -> {
        val event = new CasEvent();
        val geo = Unchecked.supplier(() -> MAPPER.readValue(flux.getGeoLocation(), new TypeReference<GeoLocationRequest>() {
        })).get();
        event.putGeoLocation(geo);
        event.setPrincipalId(flux.getPrincipalId());
        event.setType(flux.getType());
        event.setCreationTime(flux.getCreationTime());
        event.putClientIpAddress(flux.getClientIpAddress());
        event.putServerIpAddress(flux.getServerIpAddress());
        event.putEventId(flux.getValue());
        event.putTimestamp(Long.valueOf(flux.getTimestamp()));
        return event;
    });
}
Also used : lombok.val(lombok.val) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)

Example 10 with GeoLocationRequest

use of org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest 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;
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) CasTicketGrantingTicketCreatedEvent(org.apereo.cas.support.events.ticket.CasTicketGrantingTicketCreatedEvent) CasEvent(org.apereo.cas.support.events.dao.CasEvent) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)

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