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
9192444c
Commit
9192444c
authored
Oct 03, 2017
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
99101bae
Changes
31
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
524 additions
and
426 deletions
+524
-426
AbstractWebEndpointIntegrationTests.java
...ate/endpoint/web/AbstractWebEndpointIntegrationTests.java
+1
-1
DataSourceInitializationConfiguration.java
...configure/jdbc/DataSourceInitializationConfiguration.java
+2
-1
DataSourceInitializer.java
...mework/boot/autoconfigure/jdbc/DataSourceInitializer.java
+0
-1
DataSourceInitializerInvoker.java
...boot/autoconfigure/jdbc/DataSourceInitializerInvoker.java
+20
-17
DataSourceSchemaCreatedEvent.java
...boot/autoconfigure/jdbc/DataSourceSchemaCreatedEvent.java
+2
-1
HibernateJpaAutoConfiguration.java
.../autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java
+1
-1
HibernateJpaConfiguration.java
...boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java
+3
-5
CommonOAuth2Provider.java
...onfigure/security/oauth2/client/CommonOAuth2Provider.java
+2
-1
OAuth2ClientAutoConfiguration.java
...security/oauth2/client/OAuth2ClientAutoConfiguration.java
+0
-1
OAuth2ClientProperties.java
...figure/security/oauth2/client/OAuth2ClientProperties.java
+3
-4
OAuth2ClientPropertiesRegistrationAdapter.java
...th2/client/OAuth2ClientPropertiesRegistrationAdapter.java
+5
-5
OAuth2ClientRegistrationRepositoryConfiguration.java
...ient/OAuth2ClientRegistrationRepositoryConfiguration.java
+1
-3
OAuth2WebSecurityConfiguration.java
...ecurity/oauth2/client/OAuth2WebSecurityConfiguration.java
+3
-7
MessageSourceAutoConfigurationTests.java
...onfigure/context/MessageSourceAutoConfigurationTests.java
+56
-41
HttpMessageConvertersTests.java
...k/boot/autoconfigure/http/HttpMessageConvertersTests.java
+4
-4
DataSourceInitializerInvokerTests.java
...autoconfigure/jdbc/DataSourceInitializerInvokerTests.java
+30
-45
KafkaAutoConfigurationTests.java
...boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java
+177
-144
AbstractJpaAutoConfigurationTests.java
...oconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java
+11
-13
HibernateJpaAutoConfigurationTests.java
...configure/orm/jpa/HibernateJpaAutoConfigurationTests.java
+17
-15
CommonOAuth2ProviderTests.java
...ure/security/oauth2/client/CommonOAuth2ProviderTests.java
+3
-4
OAuth2ClientPropertiesRegistrationAdapterTests.java
...lient/OAuth2ClientPropertiesRegistrationAdapterTests.java
+2
-1
OAuth2ClientPropertiesTests.java
...e/security/oauth2/client/OAuth2ClientPropertiesTests.java
+1
-0
OAuth2ClientRegistrationRepositoryConfigurationTests.java
...OAuth2ClientRegistrationRepositoryConfigurationTests.java
+16
-7
OAuth2WebSecurityConfigurationTests.java
...ty/oauth2/client/OAuth2WebSecurityConfigurationTests.java
+61
-42
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+42
-44
DevToolsIntegrationTests.java
...amework/boot/devtools/tests/DevToolsIntegrationTests.java
+3
-0
pom.xml
spring-boot-samples/spring-boot-sample-oauth2-client/pom.xml
+2
-1
ExampleController.java
...src/main/java/sample/oauth2/client/ExampleController.java
+16
-3
SampleOAuth2ClientApplication.java
...a/sample/oauth2/client/SampleOAuth2ClientApplication.java
+16
-3
SampleOAuth2ClientApplicationTests.java
...ple/oauth2/client/SampleOAuth2ClientApplicationTests.java
+23
-9
TestRestTemplate.java
...pringframework/boot/test/web/client/TestRestTemplate.java
+1
-2
No files found.
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java
View file @
9192444c
...
@@ -63,7 +63,7 @@ import static org.mockito.Mockito.verify;
...
@@ -63,7 +63,7 @@ import static org.mockito.Mockito.verify;
*/
*/
public
abstract
class
AbstractWebEndpointIntegrationTests
<
T
extends
ConfigurableApplicationContext
>
{
public
abstract
class
AbstractWebEndpointIntegrationTests
<
T
extends
ConfigurableApplicationContext
>
{
private
static
final
Duration
TIMEOUT
=
Duration
.
of
Seconds
(
30
);
private
static
final
Duration
TIMEOUT
=
Duration
.
of
Minutes
(
2
);
private
final
Class
<?>
exporterConfiguration
;
private
final
Class
<?>
exporterConfiguration
;
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration.java
View file @
9192444c
...
@@ -30,7 +30,8 @@ import org.springframework.core.type.AnnotationMetadata;
...
@@ -30,7 +30,8 @@ import org.springframework.core.type.AnnotationMetadata;
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@Configuration
@Configuration
@Import
({
DataSourceInitializerInvoker
.
class
,
DataSourceInitializationConfiguration
.
Registrar
.
class
})
@Import
({
DataSourceInitializerInvoker
.
class
,
DataSourceInitializationConfiguration
.
Registrar
.
class
})
class
DataSourceInitializationConfiguration
{
class
DataSourceInitializationConfiguration
{
/**
/**
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java
View file @
9192444c
...
@@ -119,7 +119,6 @@ class DataSourceInitializer {
...
@@ -119,7 +119,6 @@ class DataSourceInitializer {
String
username
=
this
.
properties
.
getDataUsername
();
String
username
=
this
.
properties
.
getDataUsername
();
String
password
=
this
.
properties
.
getDataPassword
();
String
password
=
this
.
properties
.
getDataPassword
();
runScripts
(
scripts
,
username
,
password
);
runScripts
(
scripts
,
username
,
password
);
}
}
}
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvoker.java
View file @
9192444c
...
@@ -37,7 +37,8 @@ import org.springframework.context.ApplicationListener;
...
@@ -37,7 +37,8 @@ import org.springframework.context.ApplicationListener;
class
DataSourceInitializerInvoker
class
DataSourceInitializerInvoker
implements
ApplicationListener
<
DataSourceSchemaCreatedEvent
>,
InitializingBean
{
implements
ApplicationListener
<
DataSourceSchemaCreatedEvent
>,
InitializingBean
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
DataSourceInitializerInvoker
.
class
);
private
static
final
Log
logger
=
LogFactory
.
getLog
(
DataSourceInitializerInvoker
.
class
);
private
final
ObjectProvider
<
DataSource
>
dataSource
;
private
final
ObjectProvider
<
DataSource
>
dataSource
;
...
@@ -50,8 +51,7 @@ class DataSourceInitializerInvoker
...
@@ -50,8 +51,7 @@ class DataSourceInitializerInvoker
private
boolean
initialized
;
private
boolean
initialized
;
DataSourceInitializerInvoker
(
ObjectProvider
<
DataSource
>
dataSource
,
DataSourceInitializerInvoker
(
ObjectProvider
<
DataSource
>
dataSource
,
DataSourceProperties
properties
,
DataSourceProperties
properties
,
ApplicationContext
applicationContext
)
{
ApplicationContext
applicationContext
)
{
this
.
dataSource
=
dataSource
;
this
.
dataSource
=
dataSource
;
this
.
properties
=
properties
;
this
.
properties
=
properties
;
this
.
applicationContext
=
applicationContext
;
this
.
applicationContext
=
applicationContext
;
...
@@ -63,24 +63,27 @@ class DataSourceInitializerInvoker
...
@@ -63,24 +63,27 @@ class DataSourceInitializerInvoker
if
(
initializer
!=
null
)
{
if
(
initializer
!=
null
)
{
boolean
schemaCreated
=
this
.
dataSourceInitializer
.
createSchema
();
boolean
schemaCreated
=
this
.
dataSourceInitializer
.
createSchema
();
if
(
schemaCreated
)
{
if
(
schemaCreated
)
{
try
{
initialize
(
initializer
);
this
.
applicationContext
.
publishEvent
(
new
DataSourceSchemaCreatedEvent
(
initializer
.
getDataSource
()));
// The listener might not be registered yet, so don't rely on it.
if
(!
this
.
initialized
)
{
this
.
dataSourceInitializer
.
initSchema
();
this
.
initialized
=
true
;
}
}
catch
(
IllegalStateException
ex
)
{
logger
.
warn
(
"Could not send event to complete DataSource initialization ("
+
ex
.
getMessage
()
+
")"
);
}
}
}
}
}
}
}
private
void
initialize
(
DataSourceInitializer
initializer
)
{
try
{
this
.
applicationContext
.
publishEvent
(
new
DataSourceSchemaCreatedEvent
(
initializer
.
getDataSource
()));
// The listener might not be registered yet, so don't rely on it.
if
(!
this
.
initialized
)
{
this
.
dataSourceInitializer
.
initSchema
();
this
.
initialized
=
true
;
}
}
catch
(
IllegalStateException
ex
)
{
logger
.
warn
(
"Could not send event to complete DataSource initialization ("
+
ex
.
getMessage
()
+
")"
);
}
}
@Override
@Override
public
void
onApplicationEvent
(
DataSourceSchemaCreatedEvent
event
)
{
public
void
onApplicationEvent
(
DataSourceSchemaCreatedEvent
event
)
{
// NOTE the event can happen more than once and
// NOTE the event can happen more than once and
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceSchemaCreatedEvent.java
View file @
9192444c
...
@@ -26,7 +26,8 @@ import org.springframework.context.ApplicationEvent;
...
@@ -26,7 +26,8 @@ import org.springframework.context.ApplicationEvent;
* are executed or when Hibernate initializes the database.
* are executed or when Hibernate initializes the database.
*
*
* @author Dave Syer
* @author Dave Syer
* @since 1.1.0
* @author Stephane Nicoll
* @since 2.0.0
*/
*/
@SuppressWarnings
(
"serial"
)
@SuppressWarnings
(
"serial"
)
public
class
DataSourceSchemaCreatedEvent
extends
ApplicationEvent
{
public
class
DataSourceSchemaCreatedEvent
extends
ApplicationEvent
{
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java
View file @
9192444c
...
@@ -53,7 +53,7 @@ import org.springframework.util.ClassUtils;
...
@@ -53,7 +53,7 @@ import org.springframework.util.ClassUtils;
@Conditional
(
HibernateEntityManagerCondition
.
class
)
@Conditional
(
HibernateEntityManagerCondition
.
class
)
@EnableConfigurationProperties
(
JpaProperties
.
class
)
@EnableConfigurationProperties
(
JpaProperties
.
class
)
@AutoConfigureAfter
({
DataSourceAutoConfiguration
.
class
})
@AutoConfigureAfter
({
DataSourceAutoConfiguration
.
class
})
@Import
(
JpaHibernate
Configuration
.
class
)
@Import
(
HibernateJpa
Configuration
.
class
)
public
class
HibernateJpaAutoConfiguration
{
public
class
HibernateJpaAutoConfiguration
{
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
+
20
)
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
+
20
)
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/
JpaHibernate
Configuration.java
→
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/
HibernateJpa
Configuration.java
View file @
9192444c
...
@@ -50,10 +50,9 @@ import org.springframework.util.ClassUtils;
...
@@ -50,10 +50,9 @@ import org.springframework.util.ClassUtils;
*/
*/
@Configuration
@Configuration
@ConditionalOnSingleCandidate
(
DataSource
.
class
)
@ConditionalOnSingleCandidate
(
DataSource
.
class
)
public
class
JpaHibernate
Configuration
extends
JpaBaseConfiguration
{
class
HibernateJpa
Configuration
extends
JpaBaseConfiguration
{
private
static
final
Log
logger
=
LogFactory
private
static
final
Log
logger
=
LogFactory
.
getLog
(
HibernateJpaConfiguration
.
class
);
.
getLog
(
JpaHibernateConfiguration
.
class
);
private
static
final
String
JTA_PLATFORM
=
"hibernate.transaction.jta.platform"
;
private
static
final
String
JTA_PLATFORM
=
"hibernate.transaction.jta.platform"
;
...
@@ -74,8 +73,7 @@ public class JpaHibernateConfiguration extends JpaBaseConfiguration {
...
@@ -74,8 +73,7 @@ public class JpaHibernateConfiguration extends JpaBaseConfiguration {
private
final
HibernateDefaultDdlAutoProvider
defaultDdlAutoProvider
;
private
final
HibernateDefaultDdlAutoProvider
defaultDdlAutoProvider
;
public
JpaHibernateConfiguration
(
DataSource
dataSource
,
HibernateJpaConfiguration
(
DataSource
dataSource
,
JpaProperties
jpaProperties
,
JpaProperties
jpaProperties
,
ObjectProvider
<
JtaTransactionManager
>
jtaTransactionManager
,
ObjectProvider
<
JtaTransactionManager
>
jtaTransactionManager
,
ObjectProvider
<
TransactionManagerCustomizers
>
transactionManagerCustomizers
,
ObjectProvider
<
TransactionManagerCustomizers
>
transactionManagerCustomizers
,
ObjectProvider
<
List
<
SchemaManagementProvider
>>
providers
)
{
ObjectProvider
<
List
<
SchemaManagementProvider
>>
providers
)
{
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/CommonOAuth2Provider.java
View file @
9192444c
...
@@ -99,7 +99,8 @@ public enum CommonOAuth2Provider {
...
@@ -99,7 +99,8 @@ public enum CommonOAuth2Provider {
protected
final
ClientRegistration
.
Builder
getBuilder
(
String
registrationId
,
protected
final
ClientRegistration
.
Builder
getBuilder
(
String
registrationId
,
ClientAuthenticationMethod
method
,
String
redirectUri
)
{
ClientAuthenticationMethod
method
,
String
redirectUri
)
{
ClientRegistration
.
Builder
builder
=
new
ClientRegistration
.
Builder
(
registrationId
);
ClientRegistration
.
Builder
builder
=
new
ClientRegistration
.
Builder
(
registrationId
);
builder
.
clientAuthenticationMethod
(
method
);
builder
.
clientAuthenticationMethod
(
method
);
builder
.
authorizationGrantType
(
AuthorizationGrantType
.
AUTHORIZATION_CODE
);
builder
.
authorizationGrantType
(
AuthorizationGrantType
.
AUTHORIZATION_CODE
);
builder
.
redirectUri
(
redirectUri
);
builder
.
redirectUri
(
redirectUri
);
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientAutoConfiguration.java
View file @
9192444c
...
@@ -42,4 +42,3 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio
...
@@ -42,4 +42,3 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio
public
class
OAuth2ClientAutoConfiguration
{
public
class
OAuth2ClientAutoConfiguration
{
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientProperties.java
View file @
9192444c
...
@@ -98,8 +98,7 @@ public class OAuth2ClientProperties {
...
@@ -98,8 +98,7 @@ public class OAuth2ClientProperties {
private
ClientAuthenticationMethod
clientAuthenticationMethod
;
private
ClientAuthenticationMethod
clientAuthenticationMethod
;
/**
/**
* Authorization grant type. May be left bank then using a pre-defined
* Authorization grant type. May be left bank then using a pre-defined provider.
* provider.
*/
*/
private
AuthorizationGrantType
authorizationGrantType
;
private
AuthorizationGrantType
authorizationGrantType
;
...
@@ -204,8 +203,8 @@ public class OAuth2ClientProperties {
...
@@ -204,8 +203,8 @@ public class OAuth2ClientProperties {
private
String
userInfoUri
;
private
String
userInfoUri
;
/**
/**
* Name of the attribute that will be used to extract the username from the
* Name of the attribute that will be used to extract the username from the
call
*
call
to 'userInfoUri'.
* to 'userInfoUri'.
*/
*/
private
String
userNameAttribute
;
private
String
userNameAttribute
;
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java
View file @
9192444c
...
@@ -51,10 +51,9 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
...
@@ -51,10 +51,9 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
return
clientRegistrations
;
return
clientRegistrations
;
}
}
private
static
ClientRegistration
getClientRegistration
(
String
registrationId
,
Registration
properties
,
private
static
ClientRegistration
getClientRegistration
(
String
registrationId
,
Map
<
String
,
Provider
>
providers
)
{
Registration
properties
,
Map
<
String
,
Provider
>
providers
)
{
Builder
builder
=
getBuilder
(
registrationId
,
properties
.
getProvider
(),
Builder
builder
=
getBuilder
(
registrationId
,
properties
.
getProvider
(),
providers
);
providers
);
copyIfNotNull
(
properties:
:
getClientId
,
builder:
:
clientId
);
copyIfNotNull
(
properties:
:
getClientId
,
builder:
:
clientId
);
copyIfNotNull
(
properties:
:
getClientSecret
,
builder:
:
clientSecret
);
copyIfNotNull
(
properties:
:
getClientSecret
,
builder:
:
clientSecret
);
copyIfNotNull
(
properties:
:
getClientAuthenticationMethod
,
copyIfNotNull
(
properties:
:
getClientAuthenticationMethod
,
...
@@ -75,7 +74,8 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
...
@@ -75,7 +74,8 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
if
(
provider
==
null
&&
!
providers
.
containsKey
(
providerId
))
{
if
(
provider
==
null
&&
!
providers
.
containsKey
(
providerId
))
{
throw
new
IllegalStateException
(
"Unknown provider ID '"
+
providerId
+
"'"
);
throw
new
IllegalStateException
(
"Unknown provider ID '"
+
providerId
+
"'"
);
}
}
Builder
builder
=
(
provider
!=
null
?
provider
.
getBuilder
(
registrationId
)
:
new
Builder
(
registrationId
));
Builder
builder
=
(
provider
!=
null
?
provider
.
getBuilder
(
registrationId
)
:
new
Builder
(
registrationId
));
if
(
providers
.
containsKey
(
providerId
))
{
if
(
providers
.
containsKey
(
providerId
))
{
return
getBuilder
(
builder
,
providers
.
get
(
providerId
));
return
getBuilder
(
builder
,
providers
.
get
(
providerId
));
}
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientRegistrationRepositoryConfiguration.java
View file @
9192444c
...
@@ -54,8 +54,7 @@ class OAuth2ClientRegistrationRepositoryConfiguration {
...
@@ -54,8 +54,7 @@ class OAuth2ClientRegistrationRepositoryConfiguration {
private
final
OAuth2ClientProperties
properties
;
private
final
OAuth2ClientProperties
properties
;
OAuth2ClientRegistrationRepositoryConfiguration
(
OAuth2ClientRegistrationRepositoryConfiguration
(
OAuth2ClientProperties
properties
)
{
OAuth2ClientProperties
properties
)
{
this
.
properties
=
properties
;
this
.
properties
=
properties
;
}
}
...
@@ -103,4 +102,3 @@ class OAuth2ClientRegistrationRepositoryConfiguration {
...
@@ -103,4 +102,3 @@ class OAuth2ClientRegistrationRepositoryConfiguration {
}
}
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfiguration.java
View file @
9192444c
...
@@ -36,7 +36,8 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio
...
@@ -36,7 +36,8 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio
class
OAuth2WebSecurityConfiguration
{
class
OAuth2WebSecurityConfiguration
{
@Configuration
@Configuration
static
class
OAuth2WebSecurityConfigurationAdapter
extends
WebSecurityConfigurerAdapter
{
static
class
OAuth2WebSecurityConfigurationAdapter
extends
WebSecurityConfigurerAdapter
{
private
final
ClientRegistrationRepository
clientRegistrationRepository
;
private
final
ClientRegistrationRepository
clientRegistrationRepository
;
...
@@ -47,15 +48,10 @@ class OAuth2WebSecurityConfiguration {
...
@@ -47,15 +48,10 @@ class OAuth2WebSecurityConfiguration {
@Override
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
http
.
authorizeRequests
().
anyRequest
().
authenticated
().
and
().
oauth2Login
()
.
authorizeRequests
()
.
anyRequest
()
.
authenticated
().
and
()
.
oauth2Login
()
.
clients
(
this
.
clientRegistrationRepository
);
.
clients
(
this
.
clientRegistrationRepository
);
}
}
}
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java
View file @
9192444c
...
@@ -44,86 +44,97 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -44,86 +44,97 @@ import static org.assertj.core.api.Assertions.assertThat;
public
class
MessageSourceAutoConfigurationTests
{
public
class
MessageSourceAutoConfigurationTests
{
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
.
withConfiguration
(
MessageSourceAutoConfiguration
.
class
));
AutoConfigurations
.
of
(
MessageSourceAutoConfiguration
.
class
));
@Test
@Test
public
void
testDefaultMessageSource
()
{
public
void
testDefaultMessageSource
()
{
this
.
contextRunner
.
run
((
context
)
->
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
assertThat
(
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
))
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
))
.
isEqualTo
(
"Foo message"
));
.
isEqualTo
(
"Foo message"
));
}
}
@Test
@Test
public
void
testMessageSourceCreated
()
{
public
void
testMessageSourceCreated
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
)
.
run
((
context
)
->
assertThat
(
context
.
getMessage
(
.
run
((
context
)
->
assertThat
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
)).
isEqualTo
(
"bar"
));
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
))
.
isEqualTo
(
"bar"
));
}
}
@Test
@Test
public
void
testEncodingWorks
()
{
public
void
testEncodingWorks
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/swedish"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/swedish"
)
.
run
((
context
)
->
assertThat
(
context
.
getMessage
(
.
run
((
context
)
->
assertThat
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
)).
isEqualTo
(
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
))
"Some text with some swedish öäå!"
));
.
isEqualTo
(
"Some text with some swedish öäå!"
));
}
}
@Test
@Test
public
void
testMultipleMessageSourceCreated
()
{
public
void
testMultipleMessageSourceCreated
()
{
this
.
contextRunner
.
withPropertyValues
(
this
.
contextRunner
"spring.messages.basename:test/messages,test/messages2"
).
run
((
context
)
->
{
.
withPropertyValues
(
assertThat
(
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
))
"spring.messages.basename:test/messages,test/messages2"
)
.
isEqualTo
(
"bar"
);
.
run
((
context
)
->
{
assertThat
(
context
.
getMessage
(
"foo-foo"
,
null
,
"Foo-Foo message"
,
Locale
.
UK
))
assertThat
(
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
))
.
isEqualTo
(
"bar-bar"
);
.
isEqualTo
(
"bar"
);
});
assertThat
(
context
.
getMessage
(
"foo-foo"
,
null
,
"Foo-Foo message"
,
Locale
.
UK
)).
isEqualTo
(
"bar-bar"
);
});
}
}
@Test
@Test
public
void
testBadEncoding
()
{
public
void
testBadEncoding
()
{
// Bad encoding just means the messages are ignored
// Bad encoding just means the messages are ignored
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.encoding:rubbish"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.encoding:rubbish"
)
.
run
((
context
)
->
assertThat
(
context
.
getMessage
(
.
run
((
context
)
->
assertThat
(
"foo"
,
null
,
"blah"
,
Locale
.
UK
)).
isEqualTo
(
"blah"
));
context
.
getMessage
(
"foo"
,
null
,
"blah"
,
Locale
.
UK
))
.
isEqualTo
(
"blah"
));
}
}
@Test
@Test
@Ignore
(
"Expected to fail per gh-1075"
)
@Ignore
(
"Expected to fail per gh-1075"
)
public
void
testMessageSourceFromPropertySourceAnnotation
()
{
public
void
testMessageSourceFromPropertySourceAnnotation
()
{
this
.
contextRunner
.
withUserConfiguration
(
Config
.
class
).
run
((
context
)
->
this
.
contextRunner
.
withUserConfiguration
(
Config
.
class
)
assertThat
(
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
))
.
run
((
context
)
->
assertThat
(
.
isEqualTo
(
"bar"
));
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
))
.
isEqualTo
(
"bar"
));
}
}
@Test
@Test
public
void
testFallbackDefault
()
{
public
void
testFallbackDefault
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
)
.
run
((
context
)
->
assertThat
(
isFallbackToSystemLocale
(
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
MessageSource
.
class
))).
isTrue
());
isFallbackToSystemLocale
(
context
.
getBean
(
MessageSource
.
class
)))
.
isTrue
());
}
}
@Test
@Test
public
void
testFallbackTurnOff
()
{
public
void
testFallbackTurnOff
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
,
this
.
contextRunner
"spring.messages.fallback-to-system-locale:false"
).
run
((
context
)
->
.
withPropertyValues
(
"spring.messages.basename:test/messages"
,
assertThat
(
isFallbackToSystemLocale
(
context
.
getBean
(
MessageSource
.
class
)))
"spring.messages.fallback-to-system-locale:false"
)
.
isFalse
());
.
run
((
context
)
->
assertThat
(
isFallbackToSystemLocale
(
context
.
getBean
(
MessageSource
.
class
)))
.
isFalse
());
}
}
@Test
@Test
public
void
testFormatMessageDefault
()
{
public
void
testFormatMessageDefault
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
)
.
run
((
context
)
->
assertThat
(
isAlwaysUseMessageFormat
(
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
MessageSource
.
class
))).
isFalse
());
isAlwaysUseMessageFormat
(
context
.
getBean
(
MessageSource
.
class
)))
.
isFalse
());
}
}
@Test
@Test
public
void
testFormatMessageOn
()
throws
Exception
{
public
void
testFormatMessageOn
()
throws
Exception
{
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
,
this
.
contextRunner
"spring.messages.always-use-message-format:true"
).
run
((
context
)
->
.
withPropertyValues
(
"spring.messages.basename:test/messages"
,
assertThat
(
isAlwaysUseMessageFormat
(
context
.
getBean
(
MessageSource
.
class
)))
"spring.messages.always-use-message-format:true"
)
.
isTrue
());
.
run
((
context
)
->
assertThat
(
isAlwaysUseMessageFormat
(
context
.
getBean
(
MessageSource
.
class
)))
.
isTrue
());
}
}
private
boolean
isFallbackToSystemLocale
(
MessageSource
messageSource
)
{
private
boolean
isFallbackToSystemLocale
(
MessageSource
messageSource
)
{
...
@@ -139,16 +150,19 @@ public class MessageSourceAutoConfigurationTests {
...
@@ -139,16 +150,19 @@ public class MessageSourceAutoConfigurationTests {
@Test
@Test
public
void
testUseCodeAsDefaultMessageDefault
()
{
public
void
testUseCodeAsDefaultMessageDefault
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
)
.
run
((
context
)
->
assertThat
(
isUseCodeAsDefaultMessage
(
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
MessageSource
.
class
))).
isFalse
());
isUseCodeAsDefaultMessage
(
context
.
getBean
(
MessageSource
.
class
)))
.
isFalse
());
}
}
@Test
@Test
public
void
testUseCodeAsDefaultMessageOn
()
{
public
void
testUseCodeAsDefaultMessageOn
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.messages.basename:test/messages"
,
this
.
contextRunner
"spring.messages.use-code-as-default-message:true"
).
run
((
context
)
->
.
withPropertyValues
(
"spring.messages.basename:test/messages"
,
assertThat
(
isUseCodeAsDefaultMessage
(
"spring.messages.use-code-as-default-message:true"
)
context
.
getBean
(
MessageSource
.
class
))).
isTrue
());
.
run
((
context
)
->
assertThat
(
isUseCodeAsDefaultMessage
(
context
.
getBean
(
MessageSource
.
class
)))
.
isTrue
());
}
}
private
boolean
isUseCodeAsDefaultMessage
(
MessageSource
messageSource
)
{
private
boolean
isUseCodeAsDefaultMessage
(
MessageSource
messageSource
)
{
...
@@ -167,8 +181,9 @@ public class MessageSourceAutoConfigurationTests {
...
@@ -167,8 +181,9 @@ public class MessageSourceAutoConfigurationTests {
public
void
existingMessageSourceInParentIsIgnored
()
{
public
void
existingMessageSourceInParentIsIgnored
()
{
this
.
contextRunner
.
run
((
parent
)
->
this
.
contextRunner
.
withParent
(
parent
)
this
.
contextRunner
.
run
((
parent
)
->
this
.
contextRunner
.
withParent
(
parent
)
.
withPropertyValues
(
"spring.messages.basename:test/messages"
)
.
withPropertyValues
(
"spring.messages.basename:test/messages"
)
.
run
((
context
)
->
assertThat
(
context
.
getMessage
(
.
run
((
context
)
->
assertThat
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
)).
isEqualTo
(
"bar"
)));
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
))
.
isEqualTo
(
"bar"
)));
}
}
@Configuration
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java
View file @
9192444c
...
@@ -114,8 +114,8 @@ public class HttpMessageConvertersTests {
...
@@ -114,8 +114,8 @@ public class HttpMessageConvertersTests {
@Override
@Override
protected
List
<
HttpMessageConverter
<?>>
postProcessConverters
(
protected
List
<
HttpMessageConverter
<?>>
postProcessConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
List
<
HttpMessageConverter
<?>>
converters
)
{
converters
.
removeIf
(
(
converters
.
removeIf
(
converter
)
->
converter
instanceof
MappingJackson2XmlHttpMessageConverter
);
MappingJackson2XmlHttpMessageConverter
.
class
::
isInstance
);
return
converters
;
return
converters
;
}
}
...
@@ -141,8 +141,8 @@ public class HttpMessageConvertersTests {
...
@@ -141,8 +141,8 @@ public class HttpMessageConvertersTests {
@Override
@Override
protected
List
<
HttpMessageConverter
<?>>
postProcessPartConverters
(
protected
List
<
HttpMessageConverter
<?>>
postProcessPartConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
List
<
HttpMessageConverter
<?>>
converters
)
{
converters
.
removeIf
(
(
converters
.
removeIf
(
converter
)
->
converter
instanceof
MappingJackson2XmlHttpMessageConverter
);
MappingJackson2XmlHttpMessageConverter
.
class
::
isInstance
);
return
converters
;
return
converters
;
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java
View file @
9192444c
...
@@ -58,16 +58,14 @@ import static org.junit.Assert.fail;
...
@@ -58,16 +58,14 @@ import static org.junit.Assert.fail;
public
class
DataSourceInitializerInvokerTests
{
public
class
DataSourceInitializerInvokerTests
{
private
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
private
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
.
withConfiguration
(
AutoConfigurations
.
of
(
DataSourceAutoConfiguration
.
class
))
AutoConfigurations
.
of
(
DataSourceAutoConfiguration
.
class
))
.
withPropertyValues
(
"spring.datasource.initialize=false"
,
.
withPropertyValues
(
"spring.datasource.initialize=false"
,
"spring.datasource.url:jdbc:hsqldb:mem:init-"
"spring.datasource.url:jdbc:hsqldb:mem:init-"
+
UUID
.
randomUUID
().
toString
());
+
UUID
.
randomUUID
().
toString
());
@Test
@Test
public
void
dataSourceInitialized
()
{
public
void
dataSourceInitialized
()
{
this
.
contextRunner
this
.
contextRunner
.
withPropertyValues
(
"spring.datasource.initialize:true"
)
.
withPropertyValues
(
"spring.datasource.initialize:true"
)
.
run
((
context
)
->
{
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
DataSource
.
class
);
assertThat
(
context
).
hasSingleBean
(
DataSource
.
class
);
DataSource
dataSource
=
context
.
getBean
(
DataSource
.
class
);
DataSource
dataSource
=
context
.
getBean
(
DataSource
.
class
);
...
@@ -76,11 +74,9 @@ public class DataSourceInitializerInvokerTests {
...
@@ -76,11 +74,9 @@ public class DataSourceInitializerInvokerTests {
});
});
}
}
@Test
@Test
public
void
initializationAppliesToCustomDataSource
()
{
public
void
initializationAppliesToCustomDataSource
()
{
this
.
contextRunner
this
.
contextRunner
.
withUserConfiguration
(
OneDataSource
.
class
)
.
withUserConfiguration
(
OneDataSource
.
class
)
.
withPropertyValues
(
"spring.datasource.initialize:true"
)
.
withPropertyValues
(
"spring.datasource.initialize:true"
)
.
run
((
context
)
->
{
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
DataSource
.
class
);
assertThat
(
context
).
hasSingleBean
(
DataSource
.
class
);
...
@@ -88,11 +84,10 @@ public class DataSourceInitializerInvokerTests {
...
@@ -88,11 +84,10 @@ public class DataSourceInitializerInvokerTests {
});
});
}
}
private
void
assertDataSourceIsInitialized
(
DataSource
dataSource
)
{
private
void
assertDataSourceIsInitialized
(
DataSource
dataSource
)
{
JdbcOperations
template
=
new
JdbcTemplate
(
dataSource
);
JdbcOperations
template
=
new
JdbcTemplate
(
dataSource
);
assertThat
(
template
.
queryForObject
(
"SELECT COUNT(*) from BAR"
,
assertThat
(
template
.
queryForObject
(
"SELECT COUNT(*) from BAR"
,
Integer
.
class
))
Integer
.
class
))
.
isEqualTo
(
1
);
.
isEqualTo
(
1
);
}
}
@Test
@Test
...
@@ -133,13 +128,11 @@ public class DataSourceInitializerInvokerTests {
...
@@ -133,13 +128,11 @@ public class DataSourceInitializerInvokerTests {
@Test
@Test
public
void
dataSourceInitializedWithExplicitSqlScriptEncoding
()
{
public
void
dataSourceInitializedWithExplicitSqlScriptEncoding
()
{
this
.
contextRunner
this
.
contextRunner
.
withPropertyValues
(
"spring.datasource.initialize:true"
,
.
withPropertyValues
(
"spring.datasource.initialize:true"
,
"spring.datasource.sqlScriptEncoding:UTF-8"
,
"spring.datasource.sqlScriptEncoding:UTF-8"
,
"spring.datasource.schema:"
"spring.datasource.schema:"
+
getRelativeLocationFor
(
"encoding-schema.sql"
),
+
getRelativeLocationFor
(
"encoding-schema.sql"
),
"spring.datasource.data:"
+
getRelativeLocationFor
(
"encoding-data.sql"
))
"spring.datasource.data:"
+
getRelativeLocationFor
(
"encoding-data.sql"
))
.
run
((
context
)
->
{
.
run
((
context
)
->
{
DataSource
dataSource
=
context
.
getBean
(
DataSource
.
class
);
DataSource
dataSource
=
context
.
getBean
(
DataSource
.
class
);
assertThat
(
dataSource
).
isInstanceOf
(
HikariDataSource
.
class
);
assertThat
(
dataSource
).
isInstanceOf
(
HikariDataSource
.
class
);
...
@@ -161,15 +154,14 @@ public class DataSourceInitializerInvokerTests {
...
@@ -161,15 +154,14 @@ public class DataSourceInitializerInvokerTests {
@Test
@Test
public
void
initializationDoesNotApplyWithSeveralDataSources
()
{
public
void
initializationDoesNotApplyWithSeveralDataSources
()
{
this
.
contextRunner
this
.
contextRunner
.
withUserConfiguration
(
TwoDataSources
.
class
)
.
withUserConfiguration
(
TwoDataSources
.
class
)
.
withPropertyValues
(
"spring.datasource.initialize:true"
)
.
withPropertyValues
(
"spring.datasource.initialize:true"
)
.
run
((
context
)
->
{
.
run
((
context
)
->
{
assertThat
(
context
.
getBeanNamesForType
(
DataSource
.
class
)).
hasSize
(
2
);
assertThat
(
context
.
getBeanNamesForType
(
DataSource
.
class
)).
hasSize
(
2
);
assertDataSourceNotInitialized
(
context
.
getBean
(
assertDataSourceNotInitialized
(
"oneDataSource"
,
DataSource
.
class
));
context
.
getBean
(
"oneDataSource"
,
DataSource
.
class
));
assertDataSourceNotInitialized
(
context
.
getBean
(
assertDataSourceNotInitialized
(
"twoDataSource"
,
DataSource
.
class
));
context
.
getBean
(
"twoDataSource"
,
DataSource
.
class
));
});
});
}
}
...
@@ -185,8 +177,7 @@ public class DataSourceInitializerInvokerTests {
...
@@ -185,8 +177,7 @@ public class DataSourceInitializerInvokerTests {
private
void
assertDataSourceNotInitialized
(
DataSource
dataSource
)
{
private
void
assertDataSourceNotInitialized
(
DataSource
dataSource
)
{
JdbcOperations
template
=
new
JdbcTemplate
(
dataSource
);
JdbcOperations
template
=
new
JdbcTemplate
(
dataSource
);
try
{
try
{
template
.
queryForObject
(
"SELECT COUNT(*) from BAR"
,
template
.
queryForObject
(
"SELECT COUNT(*) from BAR"
,
Integer
.
class
);
Integer
.
class
);
fail
(
"Query should have failed as BAR table does not exist"
);
fail
(
"Query should have failed as BAR table does not exist"
);
}
}
catch
(
BadSqlGrammarException
ex
)
{
catch
(
BadSqlGrammarException
ex
)
{
...
@@ -199,16 +190,13 @@ public class DataSourceInitializerInvokerTests {
...
@@ -199,16 +190,13 @@ public class DataSourceInitializerInvokerTests {
@Test
@Test
public
void
dataSourceInitializedWithSchemaCredentials
()
{
public
void
dataSourceInitializedWithSchemaCredentials
()
{
this
.
contextRunner
this
.
contextRunner
.
withPropertyValues
(
"spring.datasource.initialize:true"
,
.
withPropertyValues
(
"spring.datasource.initialize:true"
,
"spring.datasource.sqlScriptEncoding:UTF-8"
,
"spring.datasource.sqlScriptEncoding:UTF-8"
,
"spring.datasource.schema:"
"spring.datasource.schema:"
+
getRelativeLocationFor
(
"encoding-schema.sql"
),
+
getRelativeLocationFor
(
"encoding-schema.sql"
),
"spring.datasource.data:"
+
getRelativeLocationFor
(
"encoding-data.sql"
),
"spring.datasource.data:"
"spring.datasource.schema-username:admin"
,
+
getRelativeLocationFor
(
"encoding-data.sql"
),
"spring.datasource.schema-password:admin"
).
run
((
context
)
->
{
"spring.datasource.schema-username:admin"
,
"spring.datasource.schema-password:admin"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasFailed
();
assertThat
(
context
).
hasFailed
();
assertThat
(
context
.
getStartupFailure
())
assertThat
(
context
.
getStartupFailure
())
.
isInstanceOf
(
BeanCreationException
.
class
);
.
isInstanceOf
(
BeanCreationException
.
class
);
...
@@ -217,16 +205,13 @@ public class DataSourceInitializerInvokerTests {
...
@@ -217,16 +205,13 @@ public class DataSourceInitializerInvokerTests {
@Test
@Test
public
void
dataSourceInitializedWithDataCredentials
()
{
public
void
dataSourceInitializedWithDataCredentials
()
{
this
.
contextRunner
this
.
contextRunner
.
withPropertyValues
(
"spring.datasource.initialize:true"
,
.
withPropertyValues
(
"spring.datasource.initialize:true"
,
"spring.datasource.sqlScriptEncoding:UTF-8"
,
"spring.datasource.sqlScriptEncoding:UTF-8"
,
"spring.datasource.schema:"
"spring.datasource.schema:"
+
getRelativeLocationFor
(
"encoding-schema.sql"
),
+
getRelativeLocationFor
(
"encoding-schema.sql"
),
"spring.datasource.data:"
+
getRelativeLocationFor
(
"encoding-data.sql"
),
"spring.datasource.data:"
"spring.datasource.data-username:admin"
,
+
getRelativeLocationFor
(
"encoding-data.sql"
),
"spring.datasource.data-password:admin"
).
run
((
context
)
->
{
"spring.datasource.data-username:admin"
,
"spring.datasource.data-password:admin"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasFailed
();
assertThat
(
context
).
hasFailed
();
assertThat
(
context
.
getStartupFailure
())
assertThat
(
context
.
getStartupFailure
())
.
isInstanceOf
(
BeanCreationException
.
class
);
.
isInstanceOf
(
BeanCreationException
.
class
);
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java
View file @
9192444c
This diff is collapsed.
Click to expand it.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java
View file @
9192444c
...
@@ -113,13 +113,13 @@ public abstract class AbstractJpaAutoConfigurationTests {
...
@@ -113,13 +113,13 @@ public abstract class AbstractJpaAutoConfigurationTests {
@Test
@Test
public
void
configuredWithSingleCandidateDataSource
()
{
public
void
configuredWithSingleCandidateDataSource
()
{
this
.
contextRunner
.
withUserConfiguration
(
this
.
contextRunner
TestTwoDataSourcesAndPrimaryConfiguration
.
class
).
run
((
context
)
->
{
.
withUserConfiguration
(
TestTwoDataSourcesAndPrimaryConfiguration
.
class
)
assertThat
(
context
).
getBeans
(
DataSource
.
class
).
hasSize
(
2
);
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
JpaTransactionManager
.
class
);
assertThat
(
context
).
getBeans
(
DataSource
.
class
).
hasSize
(
2
);
assertThat
(
context
).
hasSingleBean
(
EntityManagerFactory
.
class
);
assertThat
(
context
).
hasSingleBean
(
JpaTransactionManager
.
class
);
}
);
assertThat
(
context
).
hasSingleBean
(
EntityManagerFactory
.
class
);
});
}
}
@Test
@Test
...
@@ -240,18 +240,16 @@ public abstract class AbstractJpaAutoConfigurationTests {
...
@@ -240,18 +240,16 @@ public abstract class AbstractJpaAutoConfigurationTests {
});
});
}
}
@Configuration
@Configuration
protected
static
class
TestTwoDataSourcesConfiguration
{
protected
static
class
TestTwoDataSourcesConfiguration
{
@Bean
@Bean
public
DataSource
firstDataSource
()
{
public
DataSource
firstDataSource
()
{
return
createRandomDataSource
();
return
createRandomDataSource
();
}
}
@Bean
@Bean
public
DataSource
secondDataSource
()
{
public
DataSource
secondDataSource
()
{
return
createRandomDataSource
();
return
createRandomDataSource
();
}
}
...
@@ -267,12 +265,12 @@ public abstract class AbstractJpaAutoConfigurationTests {
...
@@ -267,12 +265,12 @@ public abstract class AbstractJpaAutoConfigurationTests {
@Bean
@Bean
@Primary
@Primary
public
DataSource
firstDataSource
()
{
public
DataSource
firstDataSource
()
{
return
createRandomDataSource
();
return
createRandomDataSource
();
}
}
@Bean
@Bean
public
DataSource
secondDataSource
()
{
public
DataSource
secondDataSource
()
{
return
createRandomDataSource
();
return
createRandomDataSource
();
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java
View file @
9192444c
...
@@ -75,12 +75,12 @@ public class HibernateJpaAutoConfigurationTests
...
@@ -75,12 +75,12 @@ public class HibernateJpaAutoConfigurationTests
contextRunner
().
withPropertyValues
(
"spring.datasource.data:classpath:/city.sql"
,
contextRunner
().
withPropertyValues
(
"spring.datasource.data:classpath:/city.sql"
,
// Missing:
// Missing:
"spring.datasource.schema:classpath:/ddl.sql"
).
run
((
context
)
->
{
"spring.datasource.schema:classpath:/ddl.sql"
).
run
((
context
)
->
{
assertThat
(
context
).
hasFailed
();
assertThat
(
context
).
hasFailed
();
assertThat
(
context
.
getStartupFailure
())
assertThat
(
context
.
getStartupFailure
())
.
hasMessageContaining
(
"ddl.sql"
);
.
hasMessageContaining
(
"ddl.sql"
);
assertThat
(
context
.
getStartupFailure
())
assertThat
(
context
.
getStartupFailure
())
.
hasMessageContaining
(
"spring.datasource.schema"
);
.
hasMessageContaining
(
"spring.datasource.schema"
);
});
});
}
}
@Test
@Test
...
@@ -105,7 +105,7 @@ public class HibernateJpaAutoConfigurationTests
...
@@ -105,7 +105,7 @@ public class HibernateJpaAutoConfigurationTests
"spring.datasource.data:classpath:/city.sql"
)
"spring.datasource.data:classpath:/city.sql"
)
.
run
((
context
)
->
assertThat
(
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
TestInitializedJpaConfiguration
.
class
).
called
)
context
.
getBean
(
TestInitializedJpaConfiguration
.
class
).
called
)
.
isTrue
());
.
isTrue
());
}
}
@Test
@Test
...
@@ -164,7 +164,7 @@ public class HibernateJpaAutoConfigurationTests
...
@@ -164,7 +164,7 @@ public class HibernateJpaAutoConfigurationTests
.
getJpaPropertyMap
();
.
getJpaPropertyMap
();
assertThat
((
String
)
jpaPropertyMap
assertThat
((
String
)
jpaPropertyMap
.
get
(
"hibernate.transaction.jta.platform"
))
.
get
(
"hibernate.transaction.jta.platform"
))
.
isEqualTo
(
TestJtaPlatform
.
class
.
getName
());
.
isEqualTo
(
TestJtaPlatform
.
class
.
getName
());
});
});
}
}
...
@@ -183,13 +183,15 @@ public class HibernateJpaAutoConfigurationTests
...
@@ -183,13 +183,15 @@ public class HibernateJpaAutoConfigurationTests
@Test
@Test
public
void
autoConfigurationBacksOffWithSeveralDataSources
()
{
public
void
autoConfigurationBacksOffWithSeveralDataSources
()
{
contextRunner
().
withConfiguration
(
contextRunner
()
AutoConfigurations
.
of
(
DataSourceTransactionManagerAutoConfiguration
.
class
,
.
withConfiguration
(
AutoConfigurations
.
of
(
XADataSourceAutoConfiguration
.
class
,
JtaAutoConfiguration
.
class
)
DataSourceTransactionManagerAutoConfiguration
.
class
,
).
withUserConfiguration
(
TestTwoDataSourcesConfiguration
.
class
).
run
((
context
)
->
{
XADataSourceAutoConfiguration
.
class
,
JtaAutoConfiguration
.
class
))
assertThat
(
context
).
hasNotFailed
();
.
withUserConfiguration
(
TestTwoDataSourcesConfiguration
.
class
)
assertThat
(
context
).
doesNotHaveBean
(
EntityManagerFactory
.
class
);
.
run
((
context
)
->
{
});
assertThat
(
context
).
hasNotFailed
();
assertThat
(
context
).
doesNotHaveBean
(
EntityManagerFactory
.
class
);
});
}
}
@Configuration
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/CommonOAuth2ProviderTests.java
View file @
9192444c
...
@@ -116,7 +116,8 @@ public class CommonOAuth2ProviderTests {
...
@@ -116,7 +116,8 @@ public class CommonOAuth2ProviderTests {
assertThat
(
providerDetails
.
getAuthorizationUri
())
assertThat
(
providerDetails
.
getAuthorizationUri
())
.
isEqualTo
(
"http://example.com/auth"
);
.
isEqualTo
(
"http://example.com/auth"
);
assertThat
(
providerDetails
.
getTokenUri
()).
isEqualTo
(
"http://example.com/token"
);
assertThat
(
providerDetails
.
getTokenUri
()).
isEqualTo
(
"http://example.com/token"
);
assertThat
(
providerDetails
.
getUserInfoEndpoint
().
getUri
()).
isEqualTo
(
"http://example.com/info"
);
assertThat
(
providerDetails
.
getUserInfoEndpoint
().
getUri
())
.
isEqualTo
(
"http://example.com/info"
);
assertThat
(
providerDetails
.
getUserInfoEndpoint
().
getUserNameAttributeName
())
assertThat
(
providerDetails
.
getUserInfoEndpoint
().
getUserNameAttributeName
())
.
isEqualTo
(
null
);
.
isEqualTo
(
null
);
assertThat
(
providerDetails
.
getJwkSetUri
()).
isNull
();
assertThat
(
providerDetails
.
getJwkSetUri
()).
isNull
();
...
@@ -136,9 +137,7 @@ public class CommonOAuth2ProviderTests {
...
@@ -136,9 +137,7 @@ public class CommonOAuth2ProviderTests {
}
}
private
Builder
builder
(
CommonOAuth2Provider
provider
)
{
private
Builder
builder
(
CommonOAuth2Provider
provider
)
{
return
provider
.
getBuilder
(
"123"
)
return
provider
.
getBuilder
(
"123"
).
clientId
(
"abcd"
).
clientSecret
(
"secret"
);
.
clientId
(
"abcd"
)
.
clientSecret
(
"secret"
);
}
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapterTests.java
View file @
9192444c
...
@@ -67,7 +67,8 @@ public class OAuth2ClientPropertiesRegistrationAdapterTests {
...
@@ -67,7 +67,8 @@ public class OAuth2ClientPropertiesRegistrationAdapterTests {
assertThat
(
adaptedProvider
.
getAuthorizationUri
())
assertThat
(
adaptedProvider
.
getAuthorizationUri
())
.
isEqualTo
(
"http://example.com/auth"
);
.
isEqualTo
(
"http://example.com/auth"
);
assertThat
(
adaptedProvider
.
getTokenUri
()).
isEqualTo
(
"http://example.com/token"
);
assertThat
(
adaptedProvider
.
getTokenUri
()).
isEqualTo
(
"http://example.com/token"
);
assertThat
(
adaptedProvider
.
getUserInfoEndpoint
().
getUri
()).
isEqualTo
(
"http://example.com/info"
);
assertThat
(
adaptedProvider
.
getUserInfoEndpoint
().
getUri
())
.
isEqualTo
(
"http://example.com/info"
);
assertThat
(
adaptedProvider
.
getJwkSetUri
()).
isEqualTo
(
"http://example.com/jkw"
);
assertThat
(
adaptedProvider
.
getJwkSetUri
()).
isEqualTo
(
"http://example.com/jkw"
);
assertThat
(
adapted
.
getRegistrationId
()).
isEqualTo
(
"registration"
);
assertThat
(
adapted
.
getRegistrationId
()).
isEqualTo
(
"registration"
);
assertThat
(
adapted
.
getClientId
()).
isEqualTo
(
"clientId"
);
assertThat
(
adapted
.
getClientId
()).
isEqualTo
(
"clientId"
);
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesTests.java
View file @
9192444c
...
@@ -64,4 +64,5 @@ public class OAuth2ClientPropertiesTests {
...
@@ -64,4 +64,5 @@ public class OAuth2ClientPropertiesTests {
this
.
thrown
.
expectMessage
(
"Provider must not be empty."
);
this
.
thrown
.
expectMessage
(
"Provider must not be empty."
);
this
.
properties
.
validate
();
this
.
properties
.
validate
();
}
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientRegistrationRepositoryConfigurationTests.java
View file @
9192444c
...
@@ -36,20 +36,29 @@ public class OAuth2ClientRegistrationRepositoryConfigurationTests {
...
@@ -36,20 +36,29 @@ public class OAuth2ClientRegistrationRepositoryConfigurationTests {
private
static
final
String
REGISTRATION_PREFIX
=
"spring.security.oauth2.client.registration"
;
private
static
final
String
REGISTRATION_PREFIX
=
"spring.security.oauth2.client.registration"
;
@Test
@Test
public
void
clientRegistrationRepositoryBeanShouldNotBeCreatedWhenPropertiesAbsent
()
throws
Exception
{
public
void
clientRegistrationRepositoryBeanShouldNotBeCreatedWhenPropertiesAbsent
()
this
.
contextRunner
.
withUserConfiguration
(
OAuth2ClientRegistrationRepositoryConfiguration
.
class
)
throws
Exception
{
.
run
(
context
->
assertThat
(
context
).
doesNotHaveBean
(
ClientRegistrationRepository
.
class
));
this
.
contextRunner
.
withUserConfiguration
(
OAuth2ClientRegistrationRepositoryConfiguration
.
class
)
.
run
(
context
->
assertThat
(
context
)
.
doesNotHaveBean
(
ClientRegistrationRepository
.
class
));
}
}
@Test
@Test
public
void
clientRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent
()
throws
Exception
{
public
void
clientRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent
()
this
.
contextRunner
.
withUserConfiguration
(
OAuth2ClientRegistrationRepositoryConfiguration
.
class
)
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
OAuth2ClientRegistrationRepositoryConfiguration
.
class
)
.
withPropertyValues
(
REGISTRATION_PREFIX
+
".foo.client-id=abcd"
,
.
withPropertyValues
(
REGISTRATION_PREFIX
+
".foo.client-id=abcd"
,
REGISTRATION_PREFIX
+
".foo.client-secret=secret"
,
REGISTRATION_PREFIX
+
".foo.client-secret=secret"
,
REGISTRATION_PREFIX
+
".foo.provider=github"
)
REGISTRATION_PREFIX
+
".foo.provider=github"
)
.
run
(
context
->
{
.
run
(
context
->
{
ClientRegistrationRepository
repository
=
context
.
getBean
(
ClientRegistrationRepository
.
class
);
ClientRegistrationRepository
repository
=
context
ClientRegistration
registration
=
repository
.
findByRegistrationId
(
"foo"
);
.
getBean
(
ClientRegistrationRepository
.
class
);
ClientRegistration
registration
=
repository
.
findByRegistrationId
(
"foo"
);
assertThat
(
registration
).
isNotNull
();
assertThat
(
registration
).
isNotNull
();
assertThat
(
registration
.
getClientSecret
()).
isEqualTo
(
"secret"
);
assertThat
(
registration
.
getClientSecret
()).
isEqualTo
(
"secret"
);
});
});
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfigurationTests.java
View file @
9192444c
...
@@ -55,59 +55,80 @@ public class OAuth2WebSecurityConfigurationTests {
...
@@ -55,59 +55,80 @@ public class OAuth2WebSecurityConfigurationTests {
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
();
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
();
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
securityConfigurerRegistersClientRegistrations
()
throws
Exception
{
public
void
securityConfigurerRegistersClientRegistrations
()
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
this
.
contextRunner
.
withUserConfiguration
(
ClientRepositoryConfiguration
.
class
,
ClientRepositoryConfiguration
.
class
,
OAuth2WebSecurityConfiguration
.
class
)
OAuth2WebSecurityConfiguration
.
class
).
run
((
context
)
->
{
.
run
(
context
->
{
ClientRegistrationRepository
expected
=
context
ClientRegistrationRepository
expected
=
context
.
getBean
(
ClientRegistrationRepository
.
class
);
.
getBean
(
ClientRegistrationRepository
.
class
);
ClientRegistrationRepository
actual
=
(
ClientRegistrationRepository
)
ReflectionTestUtils
.
getField
(
ClientRegistrationRepository
actual
=
(
ClientRegistrationRepository
)
ReflectionTestUtils
getAuthCodeFilters
(
context
).
get
(
0
),
"clientRegistrationRepository"
);
.
getField
(
getAuthCodeFilters
(
context
).
get
(
0
),
assertThat
(
isEqual
(
expected
.
findByRegistrationId
(
"first"
),
"clientRegistrationRepository"
);
actual
.
findByRegistrationId
(
"first"
))).
isTrue
();
assertThat
(
isEqual
(
expected
.
findByRegistrationId
(
"first"
),
assertThat
(
isEqual
(
expected
.
findByRegistrationId
(
"second"
),
actual
.
findByRegistrationId
(
"first"
))).
isTrue
();
actual
.
findByRegistrationId
(
"second"
))).
isTrue
();
assertThat
(
isEqual
(
expected
.
findByRegistrationId
(
"second"
),
});
actual
.
findByRegistrationId
(
"second"
))).
isTrue
();
});
}
}
@Test
@Test
public
void
securityConfigurerBacksOffWhenClientRegistrationBeanAbsent
()
throws
Exception
{
public
void
securityConfigurerBacksOffWhenClientRegistrationBeanAbsent
()
this
.
contextRunner
.
withUserConfiguration
(
TestConfig
.
class
,
OAuth2WebSecurityConfiguration
.
class
)
throws
Exception
{
.
run
(
context
->
assertThat
(
getAuthCodeFilters
(
context
)).
isEmpty
());
this
.
contextRunner
.
withUserConfiguration
(
TestConfig
.
class
,
OAuth2WebSecurityConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
getAuthCodeFilters
(
context
)).
isEmpty
());
}
}
@Test
@Test
public
void
securityConfigurerBacksOffWhenOtherWebSecurityAdapterPresent
()
throws
Exception
{
public
void
securityConfigurerBacksOffWhenOtherWebSecurityAdapterPresent
()
this
.
contextRunner
.
withUserConfiguration
(
TestWebSecurityConfigurerConfig
.
class
,
OAuth2WebSecurityConfiguration
.
class
)
throws
Exception
{
.
run
(
context
->
assertThat
(
getAuthCodeFilters
(
context
)).
isEmpty
());
this
.
contextRunner
.
withUserConfiguration
(
TestWebSecurityConfigurerConfig
.
class
,
OAuth2WebSecurityConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
getAuthCodeFilters
(
context
)).
isEmpty
());
}
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
{
"unchecked"
,
"cast"
}
)
private
List
<
Filter
>
getAuthCodeFilters
(
AssertableApplicationContext
context
)
{
private
List
<
Filter
>
getAuthCodeFilters
(
AssertableApplicationContext
context
)
{
FilterChainProxy
filterChain
=
(
FilterChainProxy
)
context
.
getBean
(
"springSecurityFilterChain"
);
FilterChainProxy
filterChain
=
(
FilterChainProxy
)
context
.
getBean
(
"springSecurityFilterChain"
);
List
<
SecurityFilterChain
>
filterChains
=
filterChain
.
getFilterChains
();
List
<
SecurityFilterChain
>
filterChains
=
filterChain
.
getFilterChains
();
List
<
Filter
>
filters
=
(
List
<
Filter
>)
ReflectionTestUtils
.
getField
(((
List
)
filterChains
).
get
(
0
),
"filters"
);
List
<
Filter
>
filters
=
(
List
<
Filter
>)
ReflectionTestUtils
List
<
Filter
>
oauth2Filters
=
filters
.
stream
().
filter
(
.
getField
(
filterChains
.
get
(
0
),
"filters"
);
f
->
f
instanceof
AuthorizationCodeAuthenticationProcessingFilter
||
List
<
Filter
>
oauth2Filters
=
filters
.
stream
()
f
instanceof
AuthorizationCodeRequestRedirectFilter
).
collect
(
Collectors
.
toList
());
.
filter
((
return
oauth2Filters
.
stream
().
filter
(
f
->
f
instanceof
AuthorizationCodeAuthenticationProcessingFilter
)
f
)
->
f
instanceof
AuthorizationCodeAuthenticationProcessingFilter
||
f
instanceof
AuthorizationCodeRequestRedirectFilter
)
.
collect
(
Collectors
.
toList
());
return
oauth2Filters
.
stream
()
.
filter
((
f
)
->
f
instanceof
AuthorizationCodeAuthenticationProcessingFilter
)
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
}
}
private
boolean
isEqual
(
ClientRegistration
reg1
,
ClientRegistration
reg2
)
{
private
boolean
isEqual
(
ClientRegistration
reg1
,
ClientRegistration
reg2
)
{
boolean
result
=
ObjectUtils
.
nullSafeEquals
(
reg1
.
getClientId
(),
reg2
.
getClientId
());
boolean
result
=
ObjectUtils
.
nullSafeEquals
(
reg1
.
getClientId
(),
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getClientName
(),
reg2
.
getClientName
());
reg2
.
getClientId
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getClientSecret
(),
reg2
.
getClientSecret
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getClientName
(),
reg2
.
getClientName
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getClientSecret
(),
reg2
.
getClientSecret
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getScope
(),
reg2
.
getScope
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getScope
(),
reg2
.
getScope
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getRedirectUri
(),
reg2
.
getRedirectUri
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getRedirectUri
(),
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getRegistrationId
(),
reg2
.
getRegistrationId
());
reg2
.
getRedirectUri
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getAuthorizationGrantType
(),
reg2
.
getAuthorizationGrantType
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getRegistrationId
(),
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getProviderDetails
().
getAuthorizationUri
(),
reg2
.
getRegistrationId
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getAuthorizationGrantType
(),
reg2
.
getAuthorizationGrantType
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getProviderDetails
().
getAuthorizationUri
(),
reg2
.
getProviderDetails
().
getAuthorizationUri
());
reg2
.
getProviderDetails
().
getAuthorizationUri
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getProviderDetails
().
getUserInfoEndpoint
(),
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getProviderDetails
().
getUserInfoEndpoint
(),
reg2
.
getProviderDetails
().
getUserInfoEndpoint
());
reg2
.
getProviderDetails
().
getUserInfoEndpoint
());
result
=
result
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getProviderDetails
().
getTokenUri
(),
result
=
result
reg2
.
getProviderDetails
().
getTokenUri
());
&&
ObjectUtils
.
nullSafeEquals
(
reg1
.
getProviderDetails
().
getTokenUri
(),
reg2
.
getProviderDetails
().
getTokenUri
());
return
result
;
return
result
;
}
}
...
@@ -136,16 +157,14 @@ public class OAuth2WebSecurityConfigurationTests {
...
@@ -136,16 +157,14 @@ public class OAuth2WebSecurityConfigurationTests {
private
ClientRegistration
getClientRegistration
(
String
id
,
String
userInfoUri
)
{
private
ClientRegistration
getClientRegistration
(
String
id
,
String
userInfoUri
)
{
ClientRegistration
.
Builder
builder
=
new
ClientRegistration
.
Builder
(
id
);
ClientRegistration
.
Builder
builder
=
new
ClientRegistration
.
Builder
(
id
);
builder
.
clientName
(
"foo"
)
builder
.
clientName
(
"foo"
)
.
clientId
(
"foo"
)
.
client
Id
(
"foo"
)
.
client
AuthenticationMethod
(
.
clientAuthenticationMethod
(
org
.
springframework
.
security
.
oauth2
.
core
.
ClientAuthenticationMethod
.
BASIC
)
org
.
springframework
.
security
.
oauth2
.
core
.
ClientAuthenticationMethod
.
BASIC
)
.
authorizationGrantType
(
AuthorizationGrantType
.
AUTHORIZATION_CODE
)
.
authorizationGrantType
(
AuthorizationGrantType
.
AUTHORIZATION_CODE
)
.
scope
(
"read"
)
.
scope
(
"read"
).
clientSecret
(
"secret"
)
.
clientSecret
(
"secret"
)
.
redirectUri
(
"http://redirect-uri.com"
)
.
redirectUri
(
"http://redirect-uri.com"
)
.
authorizationUri
(
"http://authorization-uri.com"
)
.
authorizationUri
(
"http://authorization-uri.com"
)
.
tokenUri
(
"http://token-uri.com"
)
.
tokenUri
(
"http://token-uri.com"
).
userInfoUri
(
userInfoUri
)
.
userInfoUri
(
userInfoUri
)
.
userNameAttributeName
(
"login"
);
.
userNameAttributeName
(
"login"
);
return
builder
.
build
();
return
builder
.
build
();
}
}
...
...
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
9192444c
...
@@ -2754,54 +2754,52 @@ explicitly configure the paths that you do want to override.
...
@@ -2754,54 +2754,52 @@ explicitly configure the paths that you do want to override.
=== OAuth2
=== OAuth2
=== Client
=== Client
If you have `spring-security-oauth2-client` on your classpath you can take advantage of
some auto-configuration to make it easy to set up an OAuth2 Client. This configuration
makes use of the properties under `OAuth2ClientProperties`.
If you have `spring-security-oauth2-client` on your classpath you can take advantage of some
You can register multiple OAuth2 clients and providers under the
auto-configuration to make it easy to set up an OAuth2 Client. This configuration makes use of
`spring.security.oauth2.client` prefix. For example:
the properties under `OAuth2ClientProperties`.
You can register multiple OAuth2 clients and providers under the `spring.security.oauth2.client` prefix.
For example,
[source,yaml,indent=0]
[source,yaml,indent=0]
----
----
# application.yml
spring:
security:
spring:
oauth2:
security:
client:
oauth2:
registration:
client:
my-client-1:
registration:
client-id: abcd
my-client-1:
client-secret: password
client-id: abcd
client-name: Client for user scope
client-secret: password
provider: my-oauth-provider
client-name: Client for user scope
scope: user
provider: my-oauth-provider
redirect-uri: http://my-redirect-uri.com
scope: user
authentication-method: basic
redirect-uri: http://my-redirect-uri.com
authorization-grant-type: authorization_code
authentication-method: basic
my-client2:
authorization-grant-type: authorization_code
client-id: abcd
my-client2:
client-secret: password
client-id: abcd
client-name: Client for email scope
client-secret: password
provider: my-oauth-provider
client-name: Client for email scope
scope: email
provider: my-oauth-provider
redirect-uri: http://my-redirect-uri.com
scope: email
authentication-method: basic
redirect-uri: http://my-redirect-uri.com
authorization-grant-type: authorization_code
authentication-method: basic
provider:
authorization-grant-type: authorization_code
my-oauth-provider:
provider:
authorization-uri: http://my-auth-server/oauth/authorize
my-oauth-provider:
token-uri: http://my-auth-server/oauth/token
authorization-uri: http://my-auth-server/oauth/authorize
user-info-uri: http://my-auth-server/userinfo
token-uri: http://my-auth-server/oauth/token
jwk-set-uri: http://my-auth-server/token_keys
user-info-uri: http://my-auth-server/userinfo
user-name-attribute: name
jwk-set-uri: http://my-auth-server/token_keys
----
user-name-attribute: name
NOTE: For common OAuth2 and OpenID providers such as Google, Github, Facebook and Okta,
# additional configuration as required
we provide a set of provider defaults. If you don't need to customize these providers, you
----
do not need to provide the `provider` configuration. The client registration `provider`
key should reference one these providers.
NOTE: For common OAuth2 and OpenID providers such as Google, Github, Facebook and Okta, we provide a set of
provider defaults. If you don't need to customize these providers, you do not need to provide the `provider`
configuration. The client registration `provider` key should reference one these providers.
[[boot-features-security-actuator]]
[[boot-features-security-actuator]]
...
...
spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/DevToolsIntegrationTests.java
View file @
9192444c
...
@@ -73,6 +73,7 @@ public class DevToolsIntegrationTests {
...
@@ -73,6 +73,7 @@ public class DevToolsIntegrationTests {
@Before
@Before
public
void
launchApplication
()
throws
Exception
{
public
void
launchApplication
()
throws
Exception
{
this
.
serverPortFile
.
delete
();
this
.
serverPortFile
.
delete
();
System
.
out
.
println
(
"Launching "
+
this
.
javaLauncher
.
getClass
());
this
.
launchedApplication
=
this
.
applicationLauncher
this
.
launchedApplication
=
this
.
applicationLauncher
.
launchApplication
(
this
.
javaLauncher
);
.
launchApplication
(
this
.
javaLauncher
);
}
}
...
@@ -139,6 +140,7 @@ public class DevToolsIntegrationTests {
...
@@ -139,6 +140,7 @@ public class DevToolsIntegrationTests {
private
int
awaitServerPort
()
throws
Exception
{
private
int
awaitServerPort
()
throws
Exception
{
long
end
=
System
.
currentTimeMillis
()
+
30000
;
long
end
=
System
.
currentTimeMillis
()
+
30000
;
while
(
this
.
serverPortFile
.
length
()
==
0
)
{
while
(
this
.
serverPortFile
.
length
()
==
0
)
{
System
.
out
.
println
(
"Getting server port "
+
this
.
serverPortFile
.
length
());
if
(
System
.
currentTimeMillis
()
>
end
)
{
if
(
System
.
currentTimeMillis
()
>
end
)
{
throw
new
IllegalStateException
(
String
.
format
(
throw
new
IllegalStateException
(
String
.
format
(
"server.port file was not written within 30 seconds. "
"server.port file was not written within 30 seconds. "
...
@@ -153,6 +155,7 @@ public class DevToolsIntegrationTests {
...
@@ -153,6 +155,7 @@ public class DevToolsIntegrationTests {
FileReader
portReader
=
new
FileReader
(
this
.
serverPortFile
);
FileReader
portReader
=
new
FileReader
(
this
.
serverPortFile
);
int
port
=
Integer
.
valueOf
(
FileCopyUtils
.
copyToString
(
portReader
));
int
port
=
Integer
.
valueOf
(
FileCopyUtils
.
copyToString
(
portReader
));
this
.
serverPortFile
.
delete
();
this
.
serverPortFile
.
delete
();
System
.
out
.
println
(
"Got port "
+
port
);
return
port
;
return
port
;
}
}
...
...
spring-boot-samples/spring-boot-sample-oauth2-client/pom.xml
View file @
9192444c
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<!-- Your own application should inherit from spring-boot-starter-parent -->
...
...
spring-boot-samples/spring-boot-sample-oauth2-client/src/main/java/sample/oauth2/client/ExampleController.java
View file @
9192444c
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
oauth2
.
client
;
package
sample
.
oauth2
.
client
;
import
java.security.Principal
;
import
java.security.Principal
;
...
@@ -5,9 +21,6 @@ import java.security.Principal;
...
@@ -5,9 +21,6 @@ import java.security.Principal;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @author Madhura Bhave
*/
@RestController
@RestController
public
class
ExampleController
{
public
class
ExampleController
{
...
...
spring-boot-samples/spring-boot-sample-oauth2-client/src/main/java/sample/oauth2/client/SampleOAuth2ClientApplication.java
View file @
9192444c
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
oauth2
.
client
;
package
sample
.
oauth2
.
client
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* @author Madhura Bhave
*/
@SpringBootApplication
@SpringBootApplication
public
class
SampleOAuth2ClientApplication
{
public
class
SampleOAuth2ClientApplication
{
...
...
spring-boot-samples/spring-boot-sample-oauth2-client/src/test/
main/
java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java
→
spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java
View file @
9192444c
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
oauth2
.
client
;
package
sample
.
oauth2
.
client
;
import
java.net.URI
;
import
java.net.URI
;
...
@@ -16,11 +32,6 @@ import org.springframework.test.context.junit4.SpringRunner;
...
@@ -16,11 +32,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for an OAuth2 client application.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"APP-CLIENT-ID=my-client-id"
,
"APP-CLIENT-SECRET=my-client-secret"
})
"APP-CLIENT-ID=my-client-id"
,
"APP-CLIENT-SECRET=my-client-secret"
})
...
@@ -43,10 +54,13 @@ public class SampleOAuth2ClientApplicationTests {
...
@@ -43,10 +54,13 @@ public class SampleOAuth2ClientApplicationTests {
@Test
@Test
public
void
loginShouldHaveBothOAuthClientsToChooseFrom
()
throws
Exception
{
public
void
loginShouldHaveBothOAuthClientsToChooseFrom
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/login"
,
String
.
class
);
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/login"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"/oauth2/authorization/code/github-client-1"
);
assertThat
(
entity
.
getBody
())
assertThat
(
entity
.
getBody
()).
contains
(
"/oauth2/authorization/code/github-client-2"
);
.
contains
(
"/oauth2/authorization/code/github-client-1"
);
assertThat
(
entity
.
getBody
())
.
contains
(
"/oauth2/authorization/code/github-client-2"
);
}
}
}
}
\ No newline at end of file
spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java
View file @
9192444c
...
@@ -148,8 +148,7 @@ public class TestRestTemplate {
...
@@ -148,8 +148,7 @@ public class TestRestTemplate {
interceptors
=
Collections
.
emptyList
();
interceptors
=
Collections
.
emptyList
();
}
}
interceptors
=
new
ArrayList
<>(
interceptors
);
interceptors
=
new
ArrayList
<>(
interceptors
);
interceptors
.
removeIf
(
interceptors
.
removeIf
(
BasicAuthorizationInterceptor
.
class
::
isInstance
);
(
interceptor
)
->
interceptor
instanceof
BasicAuthorizationInterceptor
);
interceptors
.
add
(
new
BasicAuthorizationInterceptor
(
username
,
password
));
interceptors
.
add
(
new
BasicAuthorizationInterceptor
(
username
,
password
));
restTemplate
.
setInterceptors
(
interceptors
);
restTemplate
.
setInterceptors
(
interceptors
);
}
}
...
...
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