[java-idp-integration-tests] 03/04: Allow admin flows from EC2 IP addresses
Tom Zeller
tzeller at dragonacea.biz
Tue Jun 8 15:08:27 UTC 2021
This is an automated email from the git hooks/post-receive script.
tzeller pushed a commit to branch main
in repository java-idp-integration-tests.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=4865daef991e2ba7b5b0f5cb514dfee763823cfc
commit 4865daef991e2ba7b5b0f5cb514dfee763823cfc
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Tue Jun 8 09:53:34 2021 -0500
Allow admin flows from EC2 IP addresses
If system property 'EC2' is 'true',add public and local IPV4 address to
conf/access-control.xml.
---
.../shibboleth/idp/test/BaseIntegrationTest.java | 80 ++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
index 1e47a5c..ed1c430 100644
--- a/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
@@ -53,11 +53,19 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterI
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.httpclient.HttpClientBuilder;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.net.URLBuilder;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
import net.shibboleth.utilities.java.support.xml.ParserPool;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.util.EntityUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Platform;
@@ -640,6 +648,16 @@ public abstract class BaseIntegrationTest
final String envPublicServerAddress = System.getProperty(SERVER_ADDRESS_PROPERTY);
log.debug("System property '{}' is '{}'", SERVER_ADDRESS_PROPERTY, envPublicServerAddress);
+ if (Boolean.getBoolean("EC2")) {
+ final String publicIPV4address = getEC2PublicIPV4();
+ address = publicIPV4address;
+ secureAddress = publicIPV4address;
+
+ final String privateIPV4address = getEC2PrivateIPV4();
+ privateAddress = privateIPV4address;
+ privateSecureAddress = privateIPV4address;
+ }
+
if (envPublicServerAddress != null) {
address = envPublicServerAddress;
secureAddress = envPublicServerAddress;
@@ -1823,4 +1841,66 @@ public abstract class BaseIntegrationTest
driver.findElement(By.name(SUBMIT_FORM_INPUT_NAME)).click();
}
+ /**
+ * Get EC2 metadata.
+ *
+ * @return EC2 metadata or null
+ */
+ @Nullable
+ public String getEC2Metadata(@Nonnull final String url) {
+ log.debug("Get EC2 metadata '{}'", url);
+ final HttpGet httpget = new HttpGet(url);
+ final HttpClientBuilder builder = new HttpClientBuilder();
+ try {
+ final HttpClient httpClient = builder.buildClient();
+ final HttpResponse response = httpClient.execute(httpget);
+ log.trace("EC2 metadata response '{}'", response);
+ try {
+ final HttpEntity entity = response.getEntity();
+ if (entity != null) {
+ long len = entity.getContentLength();
+ if (len != -1) {
+ final String metadata = EntityUtils.toString(entity);
+ log.info("EC2 '{}'='{}'", url, metadata);
+ return metadata;
+ }
+ }
+ } finally {
+ if (response instanceof CloseableHttpResponse) {
+ ((CloseableHttpResponse) response).close();
+ }
+ if (httpClient instanceof CloseableHttpClient) {
+ ((CloseableHttpClient) httpClient).close();
+ }
+ }
+ } catch (Exception e) {
+ log.error("Status page response error '{}'", e);
+ }
+ return null;
+ }
+
+ /**
+ * Get EC2 private IPV4 address.
+ *
+ * @return EC2 private IPV4 address or null
+ */
+ @Nullable
+ public String getEC2PrivateIPV4() {
+ log.info("Attempting to get private IPV4 address from EC2");
+ final String url = "http://169.254.169.254/latest/meta-data/local-ipv4";
+ return getEC2Metadata(url);
+ }
+
+ /**
+ * Get EC2 public IPV4 address.
+ *
+ * @return EC2 public IPV4 address or null
+ */
+ @Nullable
+ public String getEC2PublicIPV4() {
+ log.info("Attempting to get public IPV4 address from EC2");
+ final String url = "http://169.254.169.254/latest/meta-data/public-ipv4";
+ return getEC2Metadata(url);
+ }
+
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list