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
f52003f9
Commit
f52003f9
authored
Aug 29, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
d03b8e14
9b5e5f32
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
14 deletions
+85
-14
OAuth2RestOperationsConfiguration.java
...rity/oauth2/client/OAuth2RestOperationsConfiguration.java
+2
-4
OAuth2RestOperationsConfigurationTests.java
...oauth2/client/OAuth2RestOperationsConfigurationTests.java
+83
-10
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java
View file @
f52003f9
...
@@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
...
@@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import
org.springframework.boot.autoconfigure.condition.NoneNestedConditions
;
import
org.springframework.boot.autoconfigure.condition.NoneNestedConditions
;
import
org.springframework.boot.autoconfigure.condition.SpringBootCondition
;
import
org.springframework.boot.autoconfigure.condition.SpringBootCondition
;
import
org.springframework.boot.autoconfigure.security.SecurityProperties
;
import
org.springframework.boot.autoconfigure.security.SecurityProperties
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration.OAuth2ClientIdCondition
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
@@ -64,7 +63,6 @@ import org.springframework.util.StringUtils;
...
@@ -64,7 +63,6 @@ import org.springframework.util.StringUtils;
*/
*/
@Configuration
@Configuration
@ConditionalOnClass
(
EnableOAuth2Client
.
class
)
@ConditionalOnClass
(
EnableOAuth2Client
.
class
)
@Conditional
(
OAuth2ClientIdCondition
.
class
)
public
class
OAuth2RestOperationsConfiguration
{
public
class
OAuth2RestOperationsConfiguration
{
@Configuration
@Configuration
...
@@ -88,7 +86,7 @@ public class OAuth2RestOperationsConfiguration {
...
@@ -88,7 +86,7 @@ public class OAuth2RestOperationsConfiguration {
@Configuration
@Configuration
@ConditionalOnBean
(
OAuth2ClientConfiguration
.
class
)
@ConditionalOnBean
(
OAuth2ClientConfiguration
.
class
)
@Conditional
(
NoClientCredentialsCondition
.
class
)
@Conditional
(
{
OAuth2ClientIdCondition
.
class
,
NoClientCredentialsCondition
.
class
}
)
@Import
(
OAuth2ProtectedResourceDetailsConfiguration
.
class
)
@Import
(
OAuth2ProtectedResourceDetailsConfiguration
.
class
)
protected
static
class
SessionScopedConfiguration
{
protected
static
class
SessionScopedConfiguration
{
...
@@ -127,7 +125,7 @@ public class OAuth2RestOperationsConfiguration {
...
@@ -127,7 +125,7 @@ public class OAuth2RestOperationsConfiguration {
// refresh tokens you need to @EnableOAuth2Client
// refresh tokens you need to @EnableOAuth2Client
@Configuration
@Configuration
@ConditionalOnMissingBean
(
OAuth2ClientConfiguration
.
class
)
@ConditionalOnMissingBean
(
OAuth2ClientConfiguration
.
class
)
@Conditional
(
NoClientCredentialsCondition
.
class
)
@Conditional
(
{
OAuth2ClientIdCondition
.
class
,
NoClientCredentialsCondition
.
class
}
)
@Import
(
OAuth2ProtectedResourceDetailsConfiguration
.
class
)
@Import
(
OAuth2ProtectedResourceDetailsConfiguration
.
class
)
protected
static
class
RequestScopedConfiguration
{
protected
static
class
RequestScopedConfiguration
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java
View file @
f52003f9
...
@@ -19,14 +19,22 @@ package org.springframework.boot.autoconfigure.security.oauth2.client;
...
@@ -19,14 +19,22 @@ package org.springframework.boot.autoconfigure.security.oauth2.client;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.rules.ExpectedException
;
import
org.mockito.Mockito
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.autoconfigure.security.SecurityProperties
;
import
org.springframework.boot.autoconfigure.web.servlet.MockServletWebServerFactory
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
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.security.oauth2.client.DefaultOAuth2ClientContext
;
import
org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ClientConfiguration
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -45,23 +53,88 @@ public class OAuth2RestOperationsConfigurationTests {
...
@@ -45,23 +53,88 @@ public class OAuth2RestOperationsConfigurationTests {
public
ExpectedException
thrown
=
ExpectedException
.
none
();
public
ExpectedException
thrown
=
ExpectedException
.
none
();
@Test
@Test
public
void
client
IdConditionMatches
()
throws
Exception
{
public
void
client
CredentialsWithClientId
()
throws
Exception
{
TestPropertyValues
.
of
(
"security.oauth2.client.client-id=acme"
)
TestPropertyValues
.
of
(
"security.oauth2.client.client-id=acme"
)
.
applyTo
(
this
.
environment
);
.
applyTo
(
this
.
environment
);
this
.
context
=
new
SpringApplicationBuilder
(
initializeContext
(
OAuth2RestOperationsConfiguration
.
class
,
true
);
OAuth2RestOperationsConfiguration
.
class
).
environment
(
this
.
environment
)
.
web
(
WebApplicationType
.
NONE
).
run
();
assertThat
(
this
.
context
.
getBean
(
OAuth2RestOperationsConfiguration
.
class
))
assertThat
(
this
.
context
.
getBean
(
OAuth2RestOperationsConfiguration
.
class
))
.
isNotNull
();
.
isNotNull
();
assertThat
(
this
.
context
.
getBean
(
ClientCredentialsResourceDetails
.
class
))
.
isNotNull
();
}
@Test
public
void
clientCredentialsWithNoClientId
()
throws
Exception
{
initializeContext
(
OAuth2RestOperationsConfiguration
.
class
,
true
);
assertThat
(
this
.
context
.
getBean
(
OAuth2RestOperationsConfiguration
.
class
))
.
isNotNull
();
assertThat
(
this
.
context
.
getBean
(
ClientCredentialsResourceDetails
.
class
))
.
isNotNull
();
}
@Test
public
void
requestScopedWithClientId
()
throws
Exception
{
TestPropertyValues
.
of
(
"security.oauth2.client.client-id=acme"
)
.
applyTo
(
this
.
environment
);
initializeContext
(
ConfigForRequestScopedConfiguration
.
class
,
false
);
assertThat
(
this
.
context
.
containsBean
(
"oauth2ClientContext"
))
.
isTrue
();
}
@Test
public
void
requestScopedWithNoClientId
()
throws
Exception
{
initializeContext
(
ConfigForRequestScopedConfiguration
.
class
,
false
);
this
.
thrown
.
expect
(
NoSuchBeanDefinitionException
.
class
);
this
.
context
.
getBean
(
DefaultOAuth2ClientContext
.
class
);
}
@Test
public
void
sessionScopedWithClientId
()
throws
Exception
{
TestPropertyValues
.
of
(
"security.oauth2.client.client-id=acme"
)
.
applyTo
(
this
.
environment
);
initializeContext
(
ConfigForSessionScopedConfiguration
.
class
,
false
);
assertThat
(
this
.
context
.
containsBean
(
"oauth2ClientContext"
))
.
isTrue
();
}
}
@Test
@Test
public
void
clientIdConditionDoesNotMatch
()
throws
Exception
{
public
void
sessionScopedWithNoClientId
()
throws
Exception
{
this
.
context
=
new
SpringApplicationBuilder
(
initializeContext
(
ConfigForSessionScopedConfiguration
.
class
,
false
);
OAuth2RestOperationsConfiguration
.
class
).
environment
(
this
.
environment
)
.
web
(
WebApplicationType
.
NONE
).
run
();
this
.
thrown
.
expect
(
NoSuchBeanDefinitionException
.
class
);
this
.
thrown
.
expect
(
NoSuchBeanDefinitionException
.
class
);
this
.
context
.
getBean
(
OAuth2RestOperationsConfiguration
.
class
);
this
.
context
.
getBean
(
DefaultOAuth2ClientContext
.
class
);
}
private
void
initializeContext
(
Class
<?>
configuration
,
boolean
isClientCredentials
)
{
this
.
context
=
new
SpringApplicationBuilder
(
configuration
)
.
environment
(
this
.
environment
)
.
web
(!
isClientCredentials
).
run
();
}
@Configuration
@Import
({
OAuth2RestOperationsConfiguration
.
class
})
protected
static
class
WebApplicationConfiguration
{
@Bean
public
MockServletWebServerFactory
webServerFactory
()
{
return
new
MockServletWebServerFactory
();
}
}
@Configuration
@Import
({
OAuth2ClientConfiguration
.
class
,
OAuth2RestOperationsConfiguration
.
class
})
protected
static
class
ConfigForSessionScopedConfiguration
extends
WebApplicationConfiguration
{
@Bean
public
SecurityProperties
securityProperties
()
{
return
Mockito
.
mock
(
SecurityProperties
.
class
);
}
}
@Configuration
protected
static
class
ConfigForRequestScopedConfiguration
extends
WebApplicationConfiguration
{
}
}
}
}
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