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
1b85ce07
Commit
1b85ce07
authored
Jul 07, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Streamline OAuth2 resource server auto-config class conditions
Fixes gh-22233
parent
b8bc219b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
12 deletions
+14
-12
OAuth2ResourceServerAutoConfiguration.java
...source/servlet/OAuth2ResourceServerAutoConfiguration.java
+3
-0
Oauth2ResourceServerConfiguration.java
...2/resource/servlet/Oauth2ResourceServerConfiguration.java
+1
-5
OAuth2ResourceServerAutoConfigurationTests.java
...e/servlet/OAuth2ResourceServerAutoConfigurationTests.java
+10
-7
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerAutoConfiguration.java
View file @
1b85ce07
...
...
@@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.security.oauth2.resource.servlet;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties
;
import
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
;
...
...
@@ -24,6 +25,7 @@ import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServic
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for OAuth2 resource server support.
...
...
@@ -34,6 +36,7 @@ import org.springframework.context.annotation.Import;
@Configuration
(
proxyBeanMethods
=
false
)
@AutoConfigureBefore
({
SecurityAutoConfiguration
.
class
,
UserDetailsServiceAutoConfiguration
.
class
})
@EnableConfigurationProperties
(
OAuth2ResourceServerProperties
.
class
)
@ConditionalOnClass
(
BearerTokenAuthenticationToken
.
class
)
@ConditionalOnWebApplication
(
type
=
ConditionalOnWebApplication
.
Type
.
SERVLET
)
@Import
({
Oauth2ResourceServerConfiguration
.
JwtConfiguration
.
class
,
Oauth2ResourceServerConfiguration
.
OpaqueTokenConfiguration
.
class
})
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/Oauth2ResourceServerConfiguration.java
View file @
1b85ce07
...
...
@@ -20,9 +20,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.security.oauth2.jwt.JwtDecoder
;
import
org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken
;
import
org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken
;
import
org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector
;
/**
* Configuration classes for OAuth2 Resource Server These should be {@code @Import} in a
...
...
@@ -33,7 +30,7 @@ import org.springframework.security.oauth2.server.resource.introspection.OpaqueT
class
Oauth2ResourceServerConfiguration
{
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
(
{
JwtAuthenticationToken
.
class
,
JwtDecoder
.
class
}
)
@ConditionalOnClass
(
JwtDecoder
.
class
)
@Import
({
OAuth2ResourceServerJwtConfiguration
.
JwtDecoderConfiguration
.
class
,
OAuth2ResourceServerJwtConfiguration
.
OAuth2WebSecurityConfigurerAdapter
.
class
})
static
class
JwtConfiguration
{
...
...
@@ -41,7 +38,6 @@ class Oauth2ResourceServerConfiguration {
}
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
({
BearerTokenAuthenticationToken
.
class
,
OpaqueTokenIntrospector
.
class
})
@Import
({
OAuth2ResourceServerOpaqueTokenConfiguration
.
OpaqueTokenIntrospectionClientConfiguration
.
class
,
OAuth2ResourceServerOpaqueTokenConfiguration
.
OAuth2WebSecurityConfigurerAdapter
.
class
})
static
class
OpaqueTokenConfiguration
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerAutoConfigurationTests.java
View file @
1b85ce07
...
...
@@ -50,7 +50,6 @@ import org.springframework.security.oauth2.jwt.JwtDecoder;
import
org.springframework.security.oauth2.jwt.JwtIssuerValidator
;
import
org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken
;
import
org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider
;
import
org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken
;
import
org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector
;
import
org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter
;
import
org.springframework.security.web.FilterChainProxy
;
...
...
@@ -262,21 +261,25 @@ class OAuth2ResourceServerAutoConfigurationTests {
}
@Test
void
autoConfigurationShouldBeConditionalOn
JwtAuthenticationToken
Class
()
{
void
autoConfigurationShouldBeConditionalOn
ResourceServer
Class
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://jwk-set-uri.com"
)
.
withUserConfiguration
(
JwtDecoderConfig
.
class
)
.
withClassLoader
(
new
FilteredClassLoader
(
JwtAuthenticationToken
.
class
))
.
run
((
context
)
->
assertThat
(
getBearerTokenFilter
(
context
)).
isNull
());
.
withClassLoader
(
new
FilteredClassLoader
(
BearerTokenAuthenticationToken
.
class
)).
run
((
context
)
->
{
assertThat
(
context
).
doesNotHaveBean
(
OAuth2ResourceServerAutoConfiguration
.
class
);
assertThat
(
getBearerTokenFilter
(
context
)).
isNull
();
});
}
@Test
void
autoConfigurationShouldBeConditionalOnJwtDecoderClass
()
{
void
autoConfiguration
ForJwt
ShouldBeConditionalOnJwtDecoderClass
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://jwk-set-uri.com"
)
.
withUserConfiguration
(
JwtDecoderConfig
.
class
)
.
withClassLoader
(
new
FilteredClassLoader
(
JwtDecoder
.
class
))
.
run
((
context
)
->
assertThat
(
getBearerTokenFilter
(
context
)).
isNull
());
.
withClassLoader
(
new
FilteredClassLoader
(
JwtDecoder
.
class
)).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
OAuth2ResourceServerAutoConfiguration
.
class
);
assertThat
(
getBearerTokenFilter
(
context
)).
isNull
();
});
}
@Test
...
...
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