Commit 5c2937b0 by Matt Reynolds Committed by Dave Syer

filter basic auth credentials from Eureka replica data for display

so they don't appear on the dashboard Fixes gh-974
parent d1a31a9a
...@@ -75,6 +75,7 @@ public class EurekaController { ...@@ -75,6 +75,7 @@ public class EurekaController {
} }
model.put("statusInfo", statusInfo); model.put("statusInfo", statusInfo);
populateInstanceInfo(model, statusInfo); populateInstanceInfo(model, statusInfo);
filterReplicas(model, statusInfo);
return "eureka/status"; return "eureka/status";
} }
...@@ -148,7 +149,7 @@ public class EurekaController { ...@@ -148,7 +149,7 @@ public class EurekaController {
for (PeerEurekaNode node : list) { for (PeerEurekaNode node : list) {
try { try {
URI uri = new URI(node.getServiceUrl()); URI uri = new URI(node.getServiceUrl());
String href = node.getServiceUrl(); String href = scrubBasicAuth(node.getServiceUrl());
replicas.put(uri.getHost(), href); replicas.put(uri.getHost(), href);
} }
catch (Exception ex) { catch (Exception ex) {
...@@ -267,4 +268,31 @@ public class EurekaController { ...@@ -267,4 +268,31 @@ public class EurekaController {
} }
model.put("instanceInfo", instanceMap); model.put("instanceInfo", instanceMap);
} }
protected void filterReplicas(Map<String, Object> model, StatusInfo statusInfo) {
Map<String, String> applicationStats = statusInfo.getApplicationStats();
if(applicationStats.get("registered-replicas").contains("@")){
applicationStats.put("registered-replicas", scrubBasicAuth(applicationStats.get("registered-replicas")));
}
if(applicationStats.get("unavailable-replicas").contains("@")){
applicationStats.put("unavailable-replicas",scrubBasicAuth(applicationStats.get("unavailable-replicas")));
}
if(applicationStats.get("available-replicas").contains("@")){
applicationStats.put("available-replicas",scrubBasicAuth(applicationStats.get("available-replicas")));
}
model.put("applicationStats", applicationStats);
}
private String scrubBasicAuth(String urlList){
String[] urls=urlList.split(",");
String filteredUrls="";
for(String u : urls){
if(u.contains("@")){
filteredUrls+=u.substring(0,u.indexOf("//")+2)+u.substring(u.indexOf("@")+1,u.length())+",";
}else{
filteredUrls+=u+",";
}
}
return filteredUrls.substring(0,filteredUrls.length()-1);
}
} }
package org.springframework.cloud.netflix.eureka.server;
import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import com.netflix.eureka.util.StatusInfo;
public class EurekaControllerReplicasTest {
String noAuthList1 = "http://test1.com";
String noAuthList2 = noAuthList1+",http://test2.com";
String authList1 = "http://user:pwd@test1.com";
String authList2 = authList1+",http://user2:pwd2@test2.com";
String empty = new String();
@Test
public void testFilterReplicasNoAuth() throws Exception {
Map<String, Object> model=new HashMap<String, Object>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().
add("registered-replicas", empty).
add("available-replicas",noAuthList1).
add("unavailable-replicas",noAuthList2).
build();
EurekaController controller = new EurekaController(null);
controller.filterReplicas(model,statusInfo);
@SuppressWarnings("unchecked")
Map<String,String> results = (Map<String, String>) model.get("applicationStats");
assertEquals(empty,results.get("registered-replicas"));
assertEquals(noAuthList1,results.get("available-replicas"));
assertEquals(noAuthList2,results.get("unavailable-replicas"));
}
@Test
public void testFilterReplicasAuth() throws Exception {
Map<String, Object> model=new HashMap<String, Object>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().
add("registered-replicas", authList2).
add("available-replicas",authList1).
add("unavailable-replicas",empty).
build();
EurekaController controller = new EurekaController(null);
controller.filterReplicas(model,statusInfo);
@SuppressWarnings("unchecked")
Map<String,String> results = (Map<String, String>) model.get("applicationStats");
assertEquals(empty,results.get("unavailable-replicas"));
assertEquals(noAuthList1,results.get("available-replicas"));
assertEquals(noAuthList2,results.get("registered-replicas"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment