Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoayyed committed Jun 9, 2018
1 parent e92014e commit e8de766
Show file tree
Hide file tree
Showing 23 changed files with 187 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public class GeoLocationResponse {
* Add address.
*
* @param address the address
* @return the geo location response
*/
public void addAddress(final String address) {
public GeoLocationResponse addAddress(final String address) {
if (StringUtils.isNotBlank(address)) {
this.addresses.add(address);
}
return this;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.apereo.cas.configuration.model.support.geo;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
* This is {@link BaseGeoLocationProperties}.
*
* @author Misagh Moayyed
* @since 6.0.0
*/
@Getter
@Setter
public abstract class BaseGeoLocationProperties implements Serializable {
private static final long serialVersionUID = 4548572400079087989L;

/**
* The access key for ip-stack used to look up ip addresses
* for geo locations. See <a href="http://ipstack.com">this link</a> for more info.
*/
private String ipStackApiAccessKey;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.apereo.cas.configuration.model.support.geo.googlemaps;

import org.apereo.cas.configuration.support.RequiresModule;
import org.apereo.cas.configuration.support.RequiredProperty;
import java.io.Serializable;
import lombok.Getter;
import lombok.Setter;
import org.apereo.cas.configuration.model.support.geo.BaseGeoLocationProperties;
import org.apereo.cas.configuration.support.RequiredProperty;
import org.apereo.cas.configuration.support.RequiresModule;

/**
* This is {@link GoogleMapsProperties}.
Expand All @@ -13,10 +13,9 @@
* @since 5.0.0
*/
@RequiresModule(name = "cas-server-support-geolocation-googlemaps")

@Getter
@Setter
public class GoogleMapsProperties implements Serializable {
public class GoogleMapsProperties extends BaseGeoLocationProperties {

private static final long serialVersionUID = 4661113818711911462L;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.apereo.cas.configuration.model.support.geo.maxmind;

import org.apereo.cas.configuration.support.RequiresModule;
import org.apereo.cas.configuration.support.RequiredProperty;
import org.springframework.core.io.Resource;
import java.io.Serializable;
import lombok.Getter;
import lombok.Setter;
import org.apereo.cas.configuration.model.support.geo.BaseGeoLocationProperties;
import org.apereo.cas.configuration.support.RequiredProperty;
import org.apereo.cas.configuration.support.RequiresModule;
import org.springframework.core.io.Resource;

/**
* This is {@link MaxmindProperties}.
Expand All @@ -16,7 +16,7 @@
@RequiresModule(name = "cas-server-support-geolocation-maxmind")
@Getter
@Setter
public class MaxmindProperties implements Serializable {
public class MaxmindProperties extends BaseGeoLocationProperties {

private static final long serialVersionUID = 7883029275219817797L;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.apereo.cas.support.events.service;

import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/**
* This is {@link CasRegisteredServicesDeletedEvent}.
*
* @author Misagh Moayyed
* @since 6.0.0
*/
@Slf4j
@ToString
public class CasRegisteredServicesDeletedEvent extends BaseCasRegisteredServiceEvent {
private static final long serialVersionUID = -8963214046458085393L;

public CasRegisteredServicesDeletedEvent(final Object source) {
super(source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public interface ServicesManager {
*/
RegisteredService save(RegisteredService registeredService, boolean publishEvent);

/**
* Delete all entries in the underlying storage service.
*/
void deleteAll();

/**
* Delete the entry for this RegisteredService.
*
Expand All @@ -41,6 +46,7 @@ public interface ServicesManager {
*/
RegisteredService delete(long id);


/**
* Delete the entry for this RegisteredService.
*
Expand Down
3 changes: 3 additions & 0 deletions ci/init-travis-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ else
echo -e "Secure environment variables are available...\n"
fi

echo -e "Stopping current services...\n"
sudo service mysql stop

echo -e "Setting build environment...\n"
sudo mkdir -p /etc/cas/config /etc/cas/saml /etc/cas/services

Expand Down
16 changes: 8 additions & 8 deletions ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ branchName="master"
prepCommand="echo 'Running command...'; "
gradle="sudo ./gradlew $@"
gradleBuild=""
gradleBuildOptions="--stacktrace --build-cache --configure-on-demand --no-daemon --parallel "
gradleBuildOptions="--stacktrace --build-cache --configure-on-demand --no-daemon "

echo -e "***********************************************"
echo -e "Gradle build started at `date`"
Expand All @@ -24,7 +24,7 @@ elif [ "$MATRIX_JOB_TYPE" == "SNAPSHOT" ]; then
gradleBuild="$gradleBuild assemble uploadArchives -x test -x javadoc -x check \
-DenableIncremental=true -DskipNpmLint=true -DskipNestedConfigMetadataGen=true
-DpublishSnapshots=true -DsonatypeUsername=${SONATYPE_USER} \
-DsonatypePassword=${SONATYPE_PWD}"
-DsonatypePassword=${SONATYPE_PWD} --parallel "
fi
else
echo -e "*******************************************************************************************************"
Expand All @@ -33,16 +33,16 @@ elif [ "$MATRIX_JOB_TYPE" == "SNAPSHOT" ]; then
fi
elif [ "$MATRIX_JOB_TYPE" == "CFGMETADATA" ]; then
gradleBuild="$gradleBuild :api:cas-server-core-api-configuration-model:build -x check -x test -x javadoc \
-DskipGradleLint=true -DskipSass=true \
-DskipGradleLint=true -DskipSass=true --parallel \
-DskipNodeModulesCleanUp=true -DskipNpmCache=true "
elif [ "$MATRIX_JOB_TYPE" == "STYLE" ]; then
gradleBuild="$gradleBuild check -x test -x javadoc -DenableIncremental=true \
-DskipGradleLint=true -DskipSass=true -DskipNestedConfigMetadataGen=true \
-DskipNodeModulesCleanUp=true -DskipNpmCache=true "
-DskipNodeModulesCleanUp=true -DskipNpmCache=true --parallel "
elif [ "$MATRIX_JOB_TYPE" == "JAVADOC" ]; then
gradleBuild="$gradleBuild javadoc -x test -x check -DskipNpmLint=true \
-DskipGradleLint=true -DskipSass=true -DenableIncremental=true -DskipNestedConfigMetadataGen=true \
-DskipNodeModulesCleanUp=true -DskipNpmCache=true "
-DskipNodeModulesCleanUp=true -DskipNpmCache=true --parallel "
elif [ "$MATRIX_JOB_TYPE" == "TEST" ]; then
if [ "$MATRIX_SERVER" == "NONE" ]; then
gradleBuild="$gradleBuild test "
Expand Down Expand Up @@ -89,17 +89,17 @@ elif [ "$MATRIX_JOB_TYPE" == "TEST" ]; then
elif [ "$MATRIX_SERVER" == "ALL" ]; then
gradleBuild="$gradleBuild testAll "
fi
gradleBuild="$gradleBuild coveralls -x javadoc -x check \
gradleBuild="$gradleBuild coveralls -x javadoc -x check --parallel \
-DskipNpmLint=true -DskipGradleLint=true -DskipSass=true -DskipNpmLint=true \
-DskipNodeModulesCleanUp=true -DskipNpmCache=true -DskipNestedConfigMetadataGen=true "
elif [ "$MATRIX_JOB_TYPE" == "DEPANALYZE" ]; then
gradleBuild="$gradleBuild dependencyCheckAnalyze dependencyCheckUpdate -x javadoc -x check \
-DskipNpmLint=true -DskipGradleLint=true -DskipSass=true -DskipNpmLint=true \
-DskipNpmLint=true -DskipGradleLint=true --parallel -DskipSass=true -DskipNpmLint=true \
-DskipNodeModulesCleanUp=true -DskipNpmCache=true -DskipNestedConfigMetadataGen=true "
elif [ "$MATRIX_JOB_TYPE" == "DEPUPDATE" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "$branchName" ]; then
gradleBuild="$gradleBuild dependencyUpdates -Drevision=release -x javadoc -x check \
-DskipNpmLint=true -DskipGradleLint=true -DskipSass=true -DskipNestedConfigMetadataGen=true \
-DskipNodeModulesCleanUp=true -DskipNpmCache=true "
-DskipNodeModulesCleanUp=true -DskipNpmCache=true --parallel "
fi

if [[ "${TRAVIS_COMMIT_MESSAGE}" == *"[show streams]"* ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apereo.cas.util.CollectionUtils;
import org.apereo.cas.util.EncodingUtils;
import org.apereo.cas.util.gen.DefaultRandomStringGenerator;

Expand Down Expand Up @@ -73,7 +74,8 @@ public String generate(final Principal principal, final Service service) {
LOGGER.debug("Found principal attributes [{}] to use when generating persistent identifiers", attributes);
final String principalId;
if (StringUtils.isNotBlank(this.attribute) && attributes.containsKey(this.attribute)) {
principalId = attributes.get(this.attribute).toString();
final Object attributeValue = attributes.get(this.attribute);
principalId = CollectionUtils.firstElement(attributeValue).get().toString();
LOGGER.debug("Using attribute [{}] to establish principal id [{}] to generate persistent identifier", this.attribute, principalId);
} else {
principalId = principal.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apereo.cas.support.events.service.CasRegisteredServicePreDeleteEvent;
import org.apereo.cas.support.events.service.CasRegisteredServicePreSaveEvent;
import org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent;
import org.apereo.cas.support.events.service.CasRegisteredServicesDeletedEvent;
import org.apereo.cas.support.events.service.CasRegisteredServicesLoadedEvent;
import org.apereo.cas.util.DateTimeUtils;
import org.apereo.inspektr.audit.annotation.Audit;
Expand Down Expand Up @@ -200,6 +201,13 @@ public Collection<RegisteredService> load() {
return services.values();
}

@Override
public synchronized void deleteAll() {
this.services.forEach((k, v) -> delete(v));
this.services.clear();
publishEvent(new CasRegisteredServicesDeletedEvent(this));
}

private void evaluateExpiredServiceDefinitions() {
this.services.values()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,17 @@ public void verifyGeneratedIdsMatch() {
CoreAuthenticationTestUtils.getRegisteredService());
assertEquals("ujWTRNKPPso8S+4geOvcOZtv778=", result);
}

@Test
public void verifyGeneratedIdsMatchMultiValuedAttribute() {
final String salt = "whydontyoustringmealong";
final ShibbolethCompatiblePersistentIdGenerator gen = new ShibbolethCompatiblePersistentIdGenerator(salt);
gen.setAttribute("uid");
final AnonymousRegisteredServiceUsernameAttributeProvider provider = new AnonymousRegisteredServiceUsernameAttributeProvider(gen);
final String result = provider.resolveUsername(CoreAuthenticationTestUtils.getPrincipal("anyuser",
CollectionUtils.wrap("uid", CollectionUtils.wrap("obegon"))),
CoreAuthenticationTestUtils.getService("https://sp.testshib.org/shibboleth-sp"),
CoreAuthenticationTestUtils.getRegisteredService());
assertEquals("lykoGRE9QbbrsEBlHJVEz0U8AJ0=", result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
Expand Down Expand Up @@ -205,6 +206,21 @@ public static HttpResponse executeGet(final String url,
return null;
}

/**
* Execute get http response.
*
* @param url the url
* @return the http response
*/
public static HttpResponse executeGet(final String url) {
try {
return executeGet(url, null, null, new LinkedHashMap<>());
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}

/**
* Execute get http response.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ protected BigDecimal calculateScore(final HttpServletRequest request, final Auth
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();
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import org.apereo.cas.authentication.CoreAuthenticationTestUtils;
import org.apereo.cas.services.RegisteredService;
import org.apereo.cas.services.RegisteredServiceTestUtils;
import org.apereo.cas.util.junit.ConditionalIgnore;
import org.apereo.cas.util.junit.RunningStandaloneCondition;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.TestPropertySource;
Expand All @@ -20,7 +18,6 @@
* @since 5.1.0
*/
@TestPropertySource(properties = "cas.authn.adaptive.risk.dateTime.enabled=true")
@ConditionalIgnore(condition = RunningStandaloneCondition.class)
public class DateTimeAuthenticationRequestRiskCalculatorTests extends BaseAuthenticationRequestRiskCalculatorTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Misagh Moayyed
* @since 5.1.0
*/
@TestPropertySource(properties = "cas.authn.adaptive.risk.geoLocation.enabled=true")
@TestPropertySource(properties = {"cas.authn.adaptive.risk.geoLocation.enabled=true", "cas.googleMaps.ipStackApiAccessKey=6bde37c76ad15c8a5c828fafad8b0bc4"})
public class GeoLocationAuthenticationRequestRiskCalculatorTests extends BaseAuthenticationRequestRiskCalculatorTests {

@Test
Expand All @@ -36,7 +36,7 @@ public void verifyTestWhenAuthnEventsFoundForUser() {
final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("casuser");
final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("107.181.69.221");
request.setRemoteAddr("172.217.11.174");
request.setLocalAddr("127.0.0.1");
ClientInfoHolder.setClientInfo(new ClientInfo(request));
final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class MockTicketGrantingTicketCreatedEventProducer {
"88.190.229.170", "84.112.33.25", "160.180.130.93", "91.185.129.0", "95.31.18.119", "5.190.113.226",
"68.178.213.203", "17.173.254.223", "216.15.125.0", "196.25.255.250", "219.75.27.16", "201.83.41.11",
"93.210.15.68", "217.31.113.162", "98.167.59.226", "70.114.164.59", "72.201.90.0", "119.235.235.85",
"219.93.183.103");
"219.93.183.103", "172.217.11.174");

private static final List<Pair<String, String>> ALL_GEOLOCS = Arrays.asList(Pair.of("40.71", "-74.005"),
Pair.of("48.85", "2.35"), Pair.of("45.46", "9.18"), Pair.of("34.04", "-111.09"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public GeoLocationService geoLocationService() {
builder.apiKey(properties.getApiKey())
.connectTimeout(Beans.newDuration(properties.getConnectTimeout()).toMillis(), TimeUnit.MILLISECONDS);

return new GoogleMapsGeoLocationService(builder.build());
final GoogleMapsGeoLocationService svc = new GoogleMapsGeoLocationService(builder.build());
svc.setIpStackAccessKey(properties.getIpStackApiAccessKey());
return svc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.google.maps.GeocodingApi;
import com.google.maps.model.GeocodingResult;
import com.google.maps.model.LatLng;
import io.userinfo.client.UserInfo;
import io.userinfo.client.model.Info;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse;
Expand All @@ -31,15 +29,6 @@ public GeoLocationResponse locate(final InetAddress address) {
return locate(address.getHostAddress());
}

@Override
public GeoLocationResponse locate(final String address) {
final Info info = UserInfo.getInfo(address);
if (info != null && info.getPosition() != null) {
return locate(info.getPosition().getLatitude(), info.getPosition().getLongitude());
}
return null;
}

@Override
public GeoLocationResponse locate(final Double latitude, final Double longitude) {
if (latitude == null || longitude == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public GeoLocationService geoLocationService() {
throw new IllegalArgumentException("No geolocation services have been defined for Maxmind");
}

return new MaxmindDatabaseGeoLocationService(cityDatabase, countryDatabase);
final MaxmindDatabaseGeoLocationService svc = new MaxmindDatabaseGeoLocationService(cityDatabase, countryDatabase);
svc.setIpStackAccessKey(properties.getIpStackApiAccessKey());
return svc;
}
}
Loading

0 comments on commit e8de766

Please sign in to comment.