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
4a1bea1f
Commit
4a1bea1f
authored
Feb 01, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
84438183
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
55 deletions
+42
-55
SecurityAutoConfigurationTests.java
...gure/security/servlet/SecurityAutoConfigurationTests.java
+29
-36
LambdaSafeTests.java
...t/java/org/springframework/boot/util/LambdaSafeTests.java
+10
-15
SampleSecureWebFluxCustomSecurityTests.java
...ecure/webflux/SampleSecureWebFluxCustomSecurityTests.java
+3
-4
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/SecurityAutoConfigurationTests.java
View file @
4a1bea1f
...
@@ -78,7 +78,7 @@ public class SecurityAutoConfigurationTests {
...
@@ -78,7 +78,7 @@ public class SecurityAutoConfigurationTests {
@Test
@Test
public
void
testWebConfiguration
()
{
public
void
testWebConfiguration
()
{
this
.
contextRunner
.
run
(
context
->
{
this
.
contextRunner
.
run
(
(
context
)
->
{
assertThat
(
context
.
getBean
(
AuthenticationManagerBuilder
.
class
)).
isNotNull
();
assertThat
(
context
.
getBean
(
AuthenticationManagerBuilder
.
class
)).
isNotNull
();
assertThat
(
context
.
getBean
(
FilterChainProxy
.
class
).
getFilterChains
())
assertThat
(
context
.
getBean
(
FilterChainProxy
.
class
).
getFilterChains
())
.
hasSize
(
1
);
.
hasSize
(
1
);
...
@@ -89,7 +89,7 @@ public class SecurityAutoConfigurationTests {
...
@@ -89,7 +89,7 @@ public class SecurityAutoConfigurationTests {
public
void
testDefaultFilterOrderWithSecurityAdapter
()
{
public
void
testDefaultFilterOrderWithSecurityAdapter
()
{
this
.
contextRunner
.
withConfiguration
(
AutoConfigurations
.
of
(
WebSecurity
.
class
,
this
.
contextRunner
.
withConfiguration
(
AutoConfigurations
.
of
(
WebSecurity
.
class
,
SecurityFilterAutoConfiguration
.
class
)).
run
(
SecurityFilterAutoConfiguration
.
class
)).
run
(
context
->
assertThat
(
context
(
context
)
->
assertThat
(
context
.
getBean
(
"securityFilterChainRegistration"
,
.
getBean
(
"securityFilterChainRegistration"
,
DelegatingFilterProxyRegistrationBean
.
class
)
DelegatingFilterProxyRegistrationBean
.
class
)
.
getOrder
()).
isEqualTo
(
.
getOrder
()).
isEqualTo
(
...
@@ -111,36 +111,30 @@ public class SecurityAutoConfigurationTests {
...
@@ -111,36 +111,30 @@ public class SecurityAutoConfigurationTests {
@Test
@Test
public
void
defaultAuthenticationEventPublisherRegistered
()
{
public
void
defaultAuthenticationEventPublisherRegistered
()
{
this
.
contextRunner
.
run
(
context
->
{
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
assertThat
(
context
.
getBean
(
AuthenticationEventPublisher
.
class
))
context
.
getBean
(
AuthenticationEventPublisher
.
class
))
.
isInstanceOf
(
DefaultAuthenticationEventPublisher
.
class
);
.
isInstanceOf
(
DefaultAuthenticationEventPublisher
.
class
));
});
}
}
@Test
@Test
public
void
defaultAuthenticationEventPublisherIsConditionalOnMissingBean
()
{
public
void
defaultAuthenticationEventPublisherIsConditionalOnMissingBean
()
{
this
.
contextRunner
this
.
contextRunner
.
withUserConfiguration
(
AuthenticationEventPublisherConfiguration
.
class
)
.
withUserConfiguration
(
AuthenticationEventPublisherConfiguration
.
class
)
.
run
(
context
->
{
.
run
((
context
)
->
assertThat
(
assertThat
(
context
.
getBean
(
AuthenticationEventPublisher
.
class
))
context
.
getBean
(
AuthenticationEventPublisher
.
class
)).
isInstanceOf
(
.
isInstanceOf
(
AuthenticationEventPublisherConfiguration
.
TestAuthenticationEventPublisher
.
class
));
AuthenticationEventPublisherConfiguration
.
TestAuthenticationEventPublisher
.
class
);
});
}
}
@Test
@Test
public
void
testDefaultFilterOrder
()
{
public
void
testDefaultFilterOrder
()
{
this
.
contextRunner
this
.
contextRunner
.
withConfiguration
(
.
withConfiguration
(
AutoConfigurations
.
of
(
SecurityFilterAutoConfiguration
.
class
)).
run
(
AutoConfigurations
.
of
(
SecurityFilterAutoConfiguration
.
class
))
(
context
)
->
assertThat
(
context
.
run
(
context
->
{
.
getBean
(
"securityFilterChainRegistration"
,
assertThat
(
context
DelegatingFilterProxyRegistrationBean
.
class
)
.
getBean
(
"securityFilterChainRegistration"
,
.
getOrder
()).
isEqualTo
(
DelegatingFilterProxyRegistrationBean
.
class
)
FilterRegistrationBean
.
REQUEST_WRAPPER_FILTER_MAX_ORDER
.
getOrder
()).
isEqualTo
(
-
100
));
FilterRegistrationBean
.
REQUEST_WRAPPER_FILTER_MAX_ORDER
-
100
);
});
}
}
@Test
@Test
...
@@ -148,17 +142,16 @@ public class SecurityAutoConfigurationTests {
...
@@ -148,17 +142,16 @@ public class SecurityAutoConfigurationTests {
this
.
contextRunner
this
.
contextRunner
.
withConfiguration
(
.
withConfiguration
(
AutoConfigurations
.
of
(
SecurityFilterAutoConfiguration
.
class
))
AutoConfigurations
.
of
(
SecurityFilterAutoConfiguration
.
class
))
.
withPropertyValues
(
"spring.security.filter.order:12345"
).
run
(
context
->
{
.
withPropertyValues
(
"spring.security.filter.order:12345"
).
run
(
assertThat
(
context
(
context
)
->
assertThat
(
context
.
getBean
(
"securityFilterChainRegistration"
,
.
getBean
(
"securityFilterChainRegistration"
,
DelegatingFilterProxyRegistrationBean
.
class
)
DelegatingFilterProxyRegistrationBean
.
class
)
.
getOrder
()).
isEqualTo
(
12345
);
.
getOrder
()).
isEqualTo
(
12345
));
});
}
}
@Test
@Test
public
void
testDefaultUsernamePassword
()
{
public
void
testDefaultUsernamePassword
()
{
this
.
contextRunner
.
run
(
context
->
{
this
.
contextRunner
.
run
(
(
context
)
->
{
UserDetailsService
manager
=
context
.
getBean
(
UserDetailsService
.
class
);
UserDetailsService
manager
=
context
.
getBean
(
UserDetailsService
.
class
);
assertThat
(
this
.
outputCapture
.
toString
())
assertThat
(
this
.
outputCapture
.
toString
())
.
contains
(
"Using generated security password:"
);
.
contains
(
"Using generated security password:"
);
...
@@ -170,7 +163,7 @@ public class SecurityAutoConfigurationTests {
...
@@ -170,7 +163,7 @@ public class SecurityAutoConfigurationTests {
public
void
defaultUserNotCreatedIfAuthenticationManagerBeanPresent
()
{
public
void
defaultUserNotCreatedIfAuthenticationManagerBeanPresent
()
{
this
.
contextRunner
this
.
contextRunner
.
withUserConfiguration
(
TestAuthenticationManagerConfiguration
.
class
)
.
withUserConfiguration
(
TestAuthenticationManagerConfiguration
.
class
)
.
run
(
context
->
{
.
run
(
(
context
)
->
{
AuthenticationManager
manager
=
context
AuthenticationManager
manager
=
context
.
getBean
(
AuthenticationManager
.
class
);
.
getBean
(
AuthenticationManager
.
class
);
assertThat
(
manager
).
isEqualTo
(
context
.
getBean
(
assertThat
(
manager
).
isEqualTo
(
context
.
getBean
(
...
@@ -187,7 +180,7 @@ public class SecurityAutoConfigurationTests {
...
@@ -187,7 +180,7 @@ public class SecurityAutoConfigurationTests {
public
void
defaultUserNotCreatedIfUserDetailsServiceBeanPresent
()
{
public
void
defaultUserNotCreatedIfUserDetailsServiceBeanPresent
()
{
this
.
contextRunner
this
.
contextRunner
.
withUserConfiguration
(
TestUserDetailsServiceConfiguration
.
class
)
.
withUserConfiguration
(
TestUserDetailsServiceConfiguration
.
class
)
.
run
(
context
->
{
.
run
(
(
context
)
->
{
UserDetailsService
userDetailsService
=
context
UserDetailsService
userDetailsService
=
context
.
getBean
(
UserDetailsService
.
class
);
.
getBean
(
UserDetailsService
.
class
);
assertThat
(
this
.
outputCapture
.
toString
())
assertThat
(
this
.
outputCapture
.
toString
())
...
@@ -200,7 +193,7 @@ public class SecurityAutoConfigurationTests {
...
@@ -200,7 +193,7 @@ public class SecurityAutoConfigurationTests {
public
void
defaultUserNotCreatedIfAuthenticationProviderBeanPresent
()
{
public
void
defaultUserNotCreatedIfAuthenticationProviderBeanPresent
()
{
this
.
contextRunner
this
.
contextRunner
.
withUserConfiguration
(
TestAuthenticationProviderConfiguration
.
class
)
.
withUserConfiguration
(
TestAuthenticationProviderConfiguration
.
class
)
.
run
(
context
->
{
.
run
(
(
context
)
->
{
AuthenticationProvider
provider
=
context
AuthenticationProvider
provider
=
context
.
getBean
(
AuthenticationProvider
.
class
);
.
getBean
(
AuthenticationProvider
.
class
);
assertThat
(
this
.
outputCapture
.
toString
())
assertThat
(
this
.
outputCapture
.
toString
())
...
@@ -220,7 +213,7 @@ public class SecurityAutoConfigurationTests {
...
@@ -220,7 +213,7 @@ public class SecurityAutoConfigurationTests {
.
withConfiguration
(
.
withConfiguration
(
AutoConfigurations
.
of
(
HibernateJpaAutoConfiguration
.
class
,
AutoConfigurations
.
of
(
HibernateJpaAutoConfiguration
.
class
,
DataSourceAutoConfiguration
.
class
))
DataSourceAutoConfiguration
.
class
))
.
run
(
context
->
assertThat
(
context
.
getBean
(
JpaTransactionManager
.
class
))
.
run
(
(
context
)
->
assertThat
(
context
.
getBean
(
JpaTransactionManager
.
class
))
.
isNotNull
());
.
isNotNull
());
// This can fail if security @Conditionals force early instantiation of the
// This can fail if security @Conditionals force early instantiation of the
// HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
// HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
...
@@ -228,7 +221,7 @@ public class SecurityAutoConfigurationTests {
...
@@ -228,7 +221,7 @@ public class SecurityAutoConfigurationTests {
@Test
@Test
public
void
testSecurityEvaluationContextExtensionSupport
()
{
public
void
testSecurityEvaluationContextExtensionSupport
()
{
this
.
contextRunner
.
run
(
context
->
assertThat
(
context
)
this
.
contextRunner
.
run
(
(
context
)
->
assertThat
(
context
)
.
getBean
(
SecurityEvaluationContextExtension
.
class
).
isNotNull
());
.
getBean
(
SecurityEvaluationContextExtension
.
class
).
isNotNull
());
}
}
...
@@ -237,7 +230,7 @@ public class SecurityAutoConfigurationTests {
...
@@ -237,7 +230,7 @@ public class SecurityAutoConfigurationTests {
this
.
contextRunner
this
.
contextRunner
.
withConfiguration
(
.
withConfiguration
(
AutoConfigurations
.
of
(
SecurityFilterAutoConfiguration
.
class
))
AutoConfigurations
.
of
(
SecurityFilterAutoConfiguration
.
class
))
.
run
(
context
->
{
.
run
(
(
context
)
->
{
DelegatingFilterProxyRegistrationBean
bean
=
context
.
getBean
(
DelegatingFilterProxyRegistrationBean
bean
=
context
.
getBean
(
"securityFilterChainRegistration"
,
"securityFilterChainRegistration"
,
DelegatingFilterProxyRegistrationBean
.
class
);
DelegatingFilterProxyRegistrationBean
.
class
);
...
@@ -256,7 +249,7 @@ public class SecurityAutoConfigurationTests {
...
@@ -256,7 +249,7 @@ public class SecurityAutoConfigurationTests {
"spring.security.filter.dispatcher-types:INCLUDE,ERROR"
)
"spring.security.filter.dispatcher-types:INCLUDE,ERROR"
)
.
withConfiguration
(
.
withConfiguration
(
AutoConfigurations
.
of
(
SecurityFilterAutoConfiguration
.
class
))
AutoConfigurations
.
of
(
SecurityFilterAutoConfiguration
.
class
))
.
run
(
context
->
{
.
run
(
(
context
)
->
{
DelegatingFilterProxyRegistrationBean
bean
=
context
.
getBean
(
DelegatingFilterProxyRegistrationBean
bean
=
context
.
getBean
(
"securityFilterChainRegistration"
,
"securityFilterChainRegistration"
,
DelegatingFilterProxyRegistrationBean
.
class
);
DelegatingFilterProxyRegistrationBean
.
class
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java
View file @
4a1bea1f
...
@@ -104,9 +104,8 @@ public class LambdaSafeTests {
...
@@ -104,9 +104,8 @@ public class LambdaSafeTests {
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
void
callbackInvokeWhenLambdaMismatchShouldSwallowException
()
{
public
void
callbackInvokeWhenLambdaMismatchShouldSwallowException
()
{
GenericCallback
<
StringBuilder
>
callbackInstance
=
(
s
)
->
{
GenericCallback
<
StringBuilder
>
callbackInstance
=
(
s
)
->
fail
(
fail
(
"Should not get here"
);
"Should not get here"
);
};
String
argument
=
"foo"
;
String
argument
=
"foo"
;
LambdaSafe
.
callback
(
GenericCallback
.
class
,
callbackInstance
,
argument
)
LambdaSafe
.
callback
(
GenericCallback
.
class
,
callbackInstance
,
argument
)
.
invoke
((
c
)
->
c
.
handle
(
argument
));
.
invoke
((
c
)
->
c
.
handle
(
argument
));
...
@@ -115,9 +114,8 @@ public class LambdaSafeTests {
...
@@ -115,9 +114,8 @@ public class LambdaSafeTests {
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
void
callbackInvokeWhenLambdaMismatchOnDifferentArgumentShouldSwallowException
()
{
public
void
callbackInvokeWhenLambdaMismatchOnDifferentArgumentShouldSwallowException
()
{
GenericMultiArgCallback
<
StringBuilder
>
callbackInstance
=
(
n
,
s
,
b
)
->
{
GenericMultiArgCallback
<
StringBuilder
>
callbackInstance
=
(
n
,
s
,
fail
(
"Should not get here"
);
b
)
->
fail
(
"Should not get here"
);
};
String
argument
=
"foo"
;
String
argument
=
"foo"
;
LambdaSafe
.
callback
(
GenericMultiArgCallback
.
class
,
callbackInstance
,
argument
)
LambdaSafe
.
callback
(
GenericMultiArgCallback
.
class
,
callbackInstance
,
argument
)
.
invoke
((
c
)
->
c
.
handle
(
1
,
argument
,
false
));
.
invoke
((
c
)
->
c
.
handle
(
1
,
argument
,
false
));
...
@@ -262,9 +260,8 @@ public class LambdaSafeTests {
...
@@ -262,9 +260,8 @@ public class LambdaSafeTests {
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
void
callbacksInvokeWhenLambdaMismatchShouldSwallowException
()
{
public
void
callbacksInvokeWhenLambdaMismatchShouldSwallowException
()
{
GenericCallback
<
StringBuilder
>
callbackInstance
=
(
s
)
->
{
GenericCallback
<
StringBuilder
>
callbackInstance
=
(
s
)
->
fail
(
fail
(
"Should not get here"
);
"Should not get here"
);
};
String
argument
=
"foo"
;
String
argument
=
"foo"
;
LambdaSafe
.
callbacks
(
GenericCallback
.
class
,
LambdaSafe
.
callbacks
(
GenericCallback
.
class
,
Collections
.
singleton
(
callbackInstance
),
argument
)
Collections
.
singleton
(
callbackInstance
),
argument
)
...
@@ -274,9 +271,8 @@ public class LambdaSafeTests {
...
@@ -274,9 +271,8 @@ public class LambdaSafeTests {
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
void
callbacksInvokeWhenLambdaMismatchOnDifferentArgumentShouldSwallowException
()
{
public
void
callbacksInvokeWhenLambdaMismatchOnDifferentArgumentShouldSwallowException
()
{
GenericMultiArgCallback
<
StringBuilder
>
callbackInstance
=
(
n
,
s
,
b
)
->
{
GenericMultiArgCallback
<
StringBuilder
>
callbackInstance
=
(
n
,
s
,
fail
(
"Should not get here"
);
b
)
->
fail
(
"Should not get here"
);
};
String
argument
=
"foo"
;
String
argument
=
"foo"
;
LambdaSafe
LambdaSafe
.
callbacks
(
GenericMultiArgCallback
.
class
,
.
callbacks
(
GenericMultiArgCallback
.
class
,
...
@@ -410,9 +406,8 @@ public class LambdaSafeTests {
...
@@ -410,9 +406,8 @@ public class LambdaSafeTests {
public
void
callbackWithLoggerShouldUseLogger
()
{
public
void
callbackWithLoggerShouldUseLogger
()
{
Log
logger
=
mock
(
Log
.
class
);
Log
logger
=
mock
(
Log
.
class
);
given
(
logger
.
isDebugEnabled
()).
willReturn
(
true
);
given
(
logger
.
isDebugEnabled
()).
willReturn
(
true
);
GenericCallback
<
StringBuilder
>
callbackInstance
=
(
s
)
->
{
GenericCallback
<
StringBuilder
>
callbackInstance
=
(
s
)
->
fail
(
fail
(
"Should not get here"
);
"Should not get here"
);
};
String
argument
=
"foo"
;
String
argument
=
"foo"
;
LambdaSafe
.
callback
(
GenericCallback
.
class
,
callbackInstance
,
argument
)
LambdaSafe
.
callback
(
GenericCallback
.
class
,
callbackInstance
,
argument
)
.
withLogger
(
logger
).
invoke
((
c
)
->
c
.
handle
(
argument
));
.
withLogger
(
logger
).
invoke
((
c
)
->
c
.
handle
(
argument
));
...
...
spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java
View file @
4a1bea1f
...
@@ -24,7 +24,6 @@ import org.junit.runner.RunWith;
...
@@ -24,7 +24,6 @@ import org.junit.runner.RunWith;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest
;
import
org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest
;
import
org.springframework.boot.autoconfigure.security.reactive.PathRequest
;
import
org.springframework.boot.autoconfigure.security.reactive.PathRequest
;
import
org.springframework.boot.autoconfigure.security.reactive.StaticResourceRequest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -102,9 +101,9 @@ public class SampleSecureWebFluxCustomSecurityTests {
...
@@ -102,9 +101,9 @@ public class SampleSecureWebFluxCustomSecurityTests {
http
.
authorizeExchange
().
matchers
(
EndpointRequest
.
to
(
"health"
,
"info"
))
http
.
authorizeExchange
().
matchers
(
EndpointRequest
.
to
(
"health"
,
"info"
))
.
permitAll
().
matchers
(
EndpointRequest
.
toAnyEndpoint
())
.
permitAll
().
matchers
(
EndpointRequest
.
toAnyEndpoint
())
.
hasRole
(
"ACTUATOR"
)
.
hasRole
(
"ACTUATOR"
)
.
matchers
(
PathRequest
.
toStaticResources
().
atCommonLocations
())
.
permitAll
()
.
matchers
(
PathRequest
.
toStaticResources
().
atCommonLocations
())
.
p
athMatchers
(
"/login"
).
permitAll
().
anyExchange
().
authenticated
()
.
p
ermitAll
().
pathMatchers
(
"/login"
).
permitAll
().
anyExchange
()
.
and
().
httpBasic
();
.
a
uthenticated
().
a
nd
().
httpBasic
();
return
http
.
build
();
return
http
.
build
();
}
}
...
...
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