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