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
3f4c32fc
Commit
3f4c32fc
authored
Dec 20, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
b084e182
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
50 deletions
+30
-50
OAuth2RestOperationsConfiguration.java
...rity/oauth2/client/OAuth2RestOperationsConfiguration.java
+20
-37
OAuth2AutoConfigurationTests.java
...nfigure/security/oauth2/OAuth2AutoConfigurationTests.java
+10
-13
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java
View file @
3f4c32fc
...
@@ -16,12 +16,6 @@
...
@@ -16,12 +16,6 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
security
.
oauth2
.
client
;
package
org
.
springframework
.
boot
.
autoconfigure
.
security
.
oauth2
.
client
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
...
@@ -76,7 +70,7 @@ import org.springframework.util.StringUtils;
...
@@ -76,7 +70,7 @@ import org.springframework.util.StringUtils;
public
class
OAuth2RestOperationsConfiguration
{
public
class
OAuth2RestOperationsConfiguration
{
@Configuration
@Configuration
@Conditional
OnClientCredentials
@Conditional
(
ClientCredentialsCondition
.
class
)
protected
static
class
SingletonScopedConfiguration
{
protected
static
class
SingletonScopedConfiguration
{
@Bean
@Bean
...
@@ -96,7 +90,7 @@ public class OAuth2RestOperationsConfiguration {
...
@@ -96,7 +90,7 @@ public class OAuth2RestOperationsConfiguration {
@Configuration
@Configuration
@ConditionalOnBean
(
OAuth2ClientConfiguration
.
class
)
@ConditionalOnBean
(
OAuth2ClientConfiguration
.
class
)
@Conditional
OnNotClientCredentials
@Conditional
(
NoClientCredentialsCondition
.
class
)
@Import
(
OAuth2ProtectedResourceDetailsConfiguration
.
class
)
@Import
(
OAuth2ProtectedResourceDetailsConfiguration
.
class
)
protected
static
class
SessionScopedConfiguration
{
protected
static
class
SessionScopedConfiguration
{
...
@@ -126,15 +120,13 @@ public class OAuth2RestOperationsConfiguration {
...
@@ -126,15 +120,13 @@ public class OAuth2RestOperationsConfiguration {
}
}
/*
// When the authentication is per cookie but the stored token is an oauth2 one, we can
* When the authentication is per cookie but the stored token is an oauth2 one, we can
// pass that on to a client that wants to call downstream. We don't even need an
* pass that on to a client that wants to call downstream. We don't even need an
// OAuth2ClientContextFilter until we need to refresh the access token. To handle
* OAuth2ClientContextFilter until we need to refresh the access token. To handle
// refresh tokens you need to @EnableOAuth2Client
* refresh tokens you need to {@code @EnableOAuth2Client}
*/
@Configuration
@Configuration
@ConditionalOnMissingBean
(
OAuth2ClientConfiguration
.
class
)
@ConditionalOnMissingBean
(
OAuth2ClientConfiguration
.
class
)
@Conditional
OnNotClientCredentials
@Conditional
(
NoClientCredentialsCondition
.
class
)
@Import
(
OAuth2ProtectedResourceDetailsConfiguration
.
class
)
@Import
(
OAuth2ProtectedResourceDetailsConfiguration
.
class
)
protected
static
class
RequestScopedConfiguration
{
protected
static
class
RequestScopedConfiguration
{
...
@@ -182,22 +174,24 @@ public class OAuth2RestOperationsConfiguration {
...
@@ -182,22 +174,24 @@ public class OAuth2RestOperationsConfiguration {
}
}
@Conditional
(
ClientCredentialsCondition
.
class
)
/**
@Target
({
ElementType
.
TYPE
,
ElementType
.
METHOD
})
* Condition to check for no client credentials.
@Retention
(
RetentionPolicy
.
RUNTIME
)
*/
@Documented
static
class
NoClientCredentialsCondition
extends
NoneNestedConditions
{
public
static
@interface
ConditionalOnClientCredentials
{
}
NoClientCredentialsCondition
()
{
super
(
ConfigurationPhase
.
PARSE_CONFIGURATION
);
}
@Conditional
(
NotClientCredentialsCondition
.
class
)
@Conditional
(
ClientCredentialsCondition
.
class
)
@Target
({
ElementType
.
TYPE
,
ElementType
.
METHOD
})
static
class
ClientCredentialsActivated
{
@Retention
(
RetentionPolicy
.
RUNTIME
)
}
@Documented
public
static
@interface
ConditionalOnNotClientCredentials
{
}
}
/**
* Condition to check for client credentials.
*/
static
class
ClientCredentialsCondition
extends
AnyNestedCondition
{
static
class
ClientCredentialsCondition
extends
AnyNestedCondition
{
ClientCredentialsCondition
()
{
ClientCredentialsCondition
()
{
...
@@ -211,17 +205,6 @@ public class OAuth2RestOperationsConfiguration {
...
@@ -211,17 +205,6 @@ public class OAuth2RestOperationsConfiguration {
@ConditionalOnNotWebApplication
@ConditionalOnNotWebApplication
static
class
NoWebApplication
{
static
class
NoWebApplication
{
}
}
}
static
class
NotClientCredentialsCondition
extends
NoneNestedConditions
{
NotClientCredentialsCondition
()
{
super
(
ConfigurationPhase
.
PARSE_CONFIGURATION
);
}
@ConditionalOnClientCredentials
static
class
ClientCredentialsActivated
{
}
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java
View file @
3f4c32fc
...
@@ -21,7 +21,6 @@ import java.util.Arrays;
...
@@ -21,7 +21,6 @@ import java.util.Arrays;
import
java.util.List
;
import
java.util.List
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.aop.support.AopUtils
;
import
org.springframework.aop.support.AopUtils
;
...
@@ -196,8 +195,8 @@ public class OAuth2AutoConfigurationTests {
...
@@ -196,8 +195,8 @@ public class OAuth2AutoConfigurationTests {
"security.oauth2.client.clientId=client"
,
"security.oauth2.client.clientId=client"
,
"security.oauth2.client.grantType=client_credentials"
);
"security.oauth2.client.grantType=client_credentials"
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
OAuth2ClientContext
.
class
).
getAccessTokenRequest
())
OAuth2ClientContext
bean
=
this
.
context
.
getBean
(
OAuth2ClientContext
.
class
);
.
isNotNull
();
assertThat
(
bean
.
getAccessTokenRequest
())
.
isNotNull
();
assertThat
(
countBeans
(
ClientCredentialsResourceDetails
.
class
)).
isEqualTo
(
1
);
assertThat
(
countBeans
(
ClientCredentialsResourceDetails
.
class
)).
isEqualTo
(
1
);
assertThat
(
countBeans
(
OAuth2ClientContext
.
class
)).
isEqualTo
(
1
);
assertThat
(
countBeans
(
OAuth2ClientContext
.
class
)).
isEqualTo
(
1
);
}
}
...
@@ -211,17 +210,15 @@ public class OAuth2AutoConfigurationTests {
...
@@ -211,17 +210,15 @@ public class OAuth2AutoConfigurationTests {
"security.oauth2.client.clientId=client"
,
"security.oauth2.client.clientId=client"
,
"security.oauth2.client.grantType=client_credentials"
);
"security.oauth2.client.grantType=client_credentials"
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
// Th
r
primary context is fine (not session scoped):
// Th
e
primary context is fine (not session scoped):
assertThat
(
this
.
context
.
getBean
(
OAuth2ClientContext
.
class
).
getAccessTokenRequest
())
OAuth2ClientContext
bean
=
this
.
context
.
getBean
(
OAuth2ClientContext
.
class
);
.
isNotNull
();
assertThat
(
bean
.
getAccessTokenRequest
())
.
isNotNull
();
assertThat
(
countBeans
(
ClientCredentialsResourceDetails
.
class
)).
isEqualTo
(
1
);
assertThat
(
countBeans
(
ClientCredentialsResourceDetails
.
class
)).
isEqualTo
(
1
);
/*
// Kind of a bug (should ideally be 1), but the cause is in Spring OAuth2 (there
* Kind of a bug (should ideally be 1), but the cause is in Spring OAuth2 (there
// is no need for the extra session-scoped bean). What this test proves is that
* is no need for the extra session-scoped bean). What this test proves is that
// even if the user screws up and does @EnableOAuth2Client for client credentials,
* even if the user screws up and does @EnableOAuth2Client for client credentials,
// it will still just about work (because of the @Primary annotation on the
* it will still just about work (because of the @Primary annotation on the
// Boot-created instance of OAuth2ClientContext).
* Boot-created instance of OAuth2ClientContext).
*/
assertThat
(
countBeans
(
OAuth2ClientContext
.
class
)).
isEqualTo
(
2
);
assertThat
(
countBeans
(
OAuth2ClientContext
.
class
)).
isEqualTo
(
2
);
}
}
...
...
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