Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
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
DEMO
spring-boot
Commits
8708a07a
Commit
8708a07a
authored
Nov 19, 2015
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure RestTemplate interceptors remain mutable
Fixes gh-4553
parent
3dda029c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
2 deletions
+38
-2
ResourceServerTokenServicesConfiguration.java
...h2/resource/ResourceServerTokenServicesConfiguration.java
+1
-2
ResourceServerTokenServicesConfigurationTests.java
...source/ResourceServerTokenServicesConfigurationTests.java
+37
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java
View file @
8708a07a
...
@@ -114,8 +114,7 @@ public class ResourceServerTokenServicesConfiguration {
...
@@ -114,8 +114,7 @@ public class ResourceServerTokenServicesConfiguration {
this
.
details
=
DEFAULT_RESOURCE_DETAILS
;
this
.
details
=
DEFAULT_RESOURCE_DETAILS
;
}
}
OAuth2RestTemplate
template
=
getTemplate
();
OAuth2RestTemplate
template
=
getTemplate
();
template
.
setInterceptors
(
Arrays
.<
ClientHttpRequestInterceptor
>
asList
(
template
.
getInterceptors
().
add
(
new
AcceptJsonRequestInterceptor
());
new
AcceptJsonRequestInterceptor
()));
AuthorizationCodeAccessTokenProvider
accessTokenProvider
=
new
AuthorizationCodeAccessTokenProvider
();
AuthorizationCodeAccessTokenProvider
accessTokenProvider
=
new
AuthorizationCodeAccessTokenProvider
();
accessTokenProvider
.
setTokenRequestEnhancer
(
new
AcceptJsonRequestEnhancer
());
accessTokenProvider
.
setTokenRequestEnhancer
(
new
AcceptJsonRequestEnhancer
());
template
.
setAccessTokenProvider
(
accessTokenProvider
);
template
.
setAccessTokenProvider
(
accessTokenProvider
);
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java
View file @
8708a07a
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
security
.
oauth2
.
resource
;
package
org
.
springframework
.
boot
.
autoconfigure
.
security
.
oauth2
.
resource
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -41,11 +42,17 @@ import org.springframework.context.annotation.Configuration;
...
@@ -41,11 +42,17 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.http.HttpRequest
;
import
org.springframework.http.client.ClientHttpRequestExecution
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.authority.AuthorityUtils
;
import
org.springframework.security.core.authority.AuthorityUtils
;
import
org.springframework.security.oauth2.client.OAuth2RestTemplate
;
import
org.springframework.security.oauth2.provider.token.DefaultTokenServices
;
import
org.springframework.security.oauth2.provider.token.DefaultTokenServices
;
import
org.springframework.security.oauth2.provider.token.RemoteTokenServices
;
import
org.springframework.security.oauth2.provider.token.RemoteTokenServices
;
import
org.springframework.social.connect.ConnectionFactoryLocator
;
import
org.springframework.social.connect.ConnectionFactoryLocator
;
import
org.springframework.stereotype.Component
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
...
@@ -147,6 +154,19 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -147,6 +154,19 @@ public class ResourceServerTokenServicesConfigurationTests {
assertNotNull
(
services
);
assertNotNull
(
services
);
}
}
@Test
public
void
userInfoWithCustomizer
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
"security.oauth2.resource.userInfoUri:http://example.com"
,
"security.oauth2.resource.tokenInfoUri:http://example.com"
,
"security.oauth2.resource.preferTokenInfo:false"
);
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
,
Customizer
.
class
).
environment
(
this
.
environment
).
web
(
false
).
run
();
UserInfoTokenServices
services
=
this
.
context
.
getBean
(
UserInfoTokenServices
.
class
);
assertNotNull
(
services
);
}
@Test
@Test
public
void
switchToJwt
()
{
public
void
switchToJwt
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
...
@@ -245,4 +265,21 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -245,4 +265,21 @@ public class ResourceServerTokenServicesConfigurationTests {
}
}
@Component
protected
static
class
Customizer
implements
UserInfoRestTemplateCustomizer
{
@Override
public
void
customize
(
OAuth2RestTemplate
template
)
{
template
.
getInterceptors
().
add
(
new
ClientHttpRequestInterceptor
()
{
@Override
public
ClientHttpResponse
intercept
(
HttpRequest
request
,
byte
[]
body
,
ClientHttpRequestExecution
execution
)
throws
IOException
{
return
execution
.
execute
(
request
,
body
);
}
});
}
}
}
}
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