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
c0d76735
Commit
c0d76735
authored
Mar 29, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove need for http basic auth client filter.
https://github.com/Netflix/eureka/releases/tag/v1.4.5
restores http basic auth.
parent
0b9ea25d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
61 deletions
+6
-61
EurekaClientAutoConfiguration.java
...k/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
+4
-59
EurekaClientAutoConfigurationTests.java
...ud/netflix/eureka/EurekaClientAutoConfigurationTests.java
+2
-2
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
View file @
c0d76735
...
...
@@ -21,11 +21,6 @@ import java.lang.annotation.ElementType;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.util.Collection
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -61,8 +56,6 @@ import com.netflix.appinfo.InstanceInfo;
import
com.netflix.discovery.DiscoveryClient.DiscoveryClientOptionalArgs
;
import
com.netflix.discovery.EurekaClient
;
import
com.netflix.discovery.EurekaClientConfig
;
import
com.sun.jersey.api.client.filter.ClientFilter
;
import
com.sun.jersey.api.client.filter.HTTPBasicAuthFilter
;
import
static
org
.
springframework
.
cloud
.
commons
.
util
.
IdUtils
.
getDefaultInstanceId
;
...
...
@@ -147,16 +140,14 @@ public class EurekaClientAutoConfiguration {
@Autowired
private
ApplicationContext
context
;
@Autowired
@Autowired
(
required
=
false
)
private
DiscoveryClientOptionalArgs
optionalArgs
;
@Bean
(
destroyMethod
=
"shutdown"
)
@ConditionalOnMissingBean
(
value
=
EurekaClient
.
class
,
search
=
SearchStrategy
.
CURRENT
)
public
EurekaClient
eurekaClient
(
ApplicationInfoManager
manager
,
EurekaClientConfig
config
)
{
DiscoveryClientOptionalArgs
args
=
EurekaClientAutoConfiguration
.
getOptionalArgs
(
config
,
this
.
optionalArgs
);
return
new
CloudEurekaClient
(
manager
,
config
,
args
,
this
.
context
);
return
new
CloudEurekaClient
(
manager
,
config
,
this
.
optionalArgs
,
this
.
context
);
}
@Bean
...
...
@@ -175,7 +166,7 @@ public class EurekaClientAutoConfiguration {
@Autowired
private
ApplicationContext
context
;
@Autowired
@Autowired
(
required
=
false
)
private
DiscoveryClientOptionalArgs
optionalArgs
;
@Bean
(
destroyMethod
=
"shutdown"
)
...
...
@@ -185,9 +176,7 @@ public class EurekaClientAutoConfiguration {
public
EurekaClient
eurekaClient
(
ApplicationInfoManager
manager
,
EurekaClientConfig
config
,
EurekaInstanceConfig
instance
)
{
manager
.
getInfo
();
// force initialization
DiscoveryClientOptionalArgs
args
=
EurekaClientAutoConfiguration
.
getOptionalArgs
(
config
,
this
.
optionalArgs
);
return
new
CloudEurekaClient
(
manager
,
config
,
args
,
this
.
context
);
return
new
CloudEurekaClient
(
manager
,
config
,
this
.
optionalArgs
,
this
.
context
);
}
@Bean
...
...
@@ -247,48 +236,4 @@ public class EurekaClientAutoConfiguration {
}
public
static
DiscoveryClientOptionalArgs
getOptionalArgs
(
EurekaClientConfig
config
,
DiscoveryClientOptionalArgs
optionalArgs
)
{
Collection
<
ClientFilter
>
filters
=
new
LinkedHashSet
<>();
if
(
optionalArgs
instanceof
MutableDiscoveryClientOptionalArgs
)
{
MutableDiscoveryClientOptionalArgs
mutable
=
(
MutableDiscoveryClientOptionalArgs
)
optionalArgs
;
filters
=
mutable
.
getAdditionalFilters
()
!=
null
?
mutable
.
getAdditionalFilters
()
:
filters
;
ClientFilter
filter
=
getAuthFilter
(
config
);
if
(
filter
!=
null
)
{
filters
.
add
(
filter
);
}
mutable
.
setAdditionalFilters
(
filters
);
}
return
optionalArgs
;
}
private
static
ClientFilter
getAuthFilter
(
EurekaClientConfig
config
)
{
// Netflix throws away the basic auth credentials from the service URL at runtime,
// so we look at the default zone and try and lift some credentials from there,
// assuming that they don't change from host to host. If they do change from host
// to host user will have to create a custom ClientFilter.
List
<
String
>
urls
=
config
.
getEurekaServerServiceUrls
(
EurekaClientConfigBean
.
DEFAULT_ZONE
);
for
(
String
url
:
urls
)
{
try
{
String
authority
=
new
URI
(
url
).
getAuthority
();
authority
=
authority
!=
null
&&
authority
.
contains
(
"@"
)
?
authority
.
substring
(
0
,
authority
.
indexOf
(
"@"
))
:
null
;
if
(
authority
!=
null
)
{
String
[]
values
=
StringUtils
.
split
(
authority
,
":"
);
if
(
values
==
null
)
{
values
=
new
String
[]
{
authority
,
""
};
}
return
new
HTTPBasicAuthFilter
(
values
[
0
],
values
[
1
]);
}
}
catch
(
URISyntaxException
e
)
{
// This should not occur
throw
new
IllegalArgumentException
(
"Cannot parse service URL: "
+
url
,
e
);
}
}
return
null
;
}
}
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfigurationTests.java
View file @
c0d76735
...
...
@@ -114,8 +114,8 @@ public class EurekaClientAutoConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"server.port=8989"
,
"eureka.client.serviceUrl.defaultZone=http://user:foo@example.com:80/eureka"
);
setupContext
(
MockClientConfiguration
.
class
);
ApacheHttpClient4
http
=
this
.
context
.
getBean
(
ApacheHttpClient4
.
class
);
Mockito
.
verify
(
http
).
addFilter
(
Matchers
.
any
(
HTTPBasicAuthFilter
.
class
));
//
ApacheHttpClient4 http = this.context.getBean(ApacheHttpClient4.class);
//
Mockito.verify(http).addFilter(Matchers.any(HTTPBasicAuthFilter.class));
}
private
void
testNonSecurePort
(
String
propName
)
{
...
...
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