Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
5c2937b0
Commit
5c2937b0
authored
Apr 15, 2016
by
Matt Reynolds
Committed by
Dave Syer
Apr 26, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
filter basic auth credentials from Eureka replica data for display
so they don't appear on the dashboard Fixes gh-974
parent
d1a31a9a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
1 deletion
+93
-1
EurekaController.java
...amework/cloud/netflix/eureka/server/EurekaController.java
+29
-1
EurekaControllerReplicasTest.java
...d/netflix/eureka/server/EurekaControllerReplicasTest.java
+64
-0
No files found.
spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaController.java
View file @
5c2937b0
...
...
@@ -75,6 +75,7 @@ public class EurekaController {
}
model
.
put
(
"statusInfo"
,
statusInfo
);
populateInstanceInfo
(
model
,
statusInfo
);
filterReplicas
(
model
,
statusInfo
);
return
"eureka/status"
;
}
...
...
@@ -148,7 +149,7 @@ public class EurekaController {
for
(
PeerEurekaNode
node
:
list
)
{
try
{
URI
uri
=
new
URI
(
node
.
getServiceUrl
());
String
href
=
node
.
getServiceUrl
(
);
String
href
=
scrubBasicAuth
(
node
.
getServiceUrl
()
);
replicas
.
put
(
uri
.
getHost
(),
href
);
}
catch
(
Exception
ex
)
{
...
...
@@ -267,4 +268,31 @@ public class EurekaController {
}
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
);
}
}
spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/EurekaControllerReplicasTest.java
0 → 100644
View file @
5c2937b0
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"
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment