Allow AuthenticationProvider Bean in Java Config
This commit adds support for defaulting java configuration's authentication by providing an AuthenticationProvider Bean. Fixes gh-3091
This commit is contained in:
@@ -378,6 +378,7 @@ This will give you access to the entire project history (including all releases
|
||||
* <<el-access-web-path-variables,Path Variables in Web Security Expressions>>
|
||||
* <<test-method-withanonymoususer,@WithAnonymousUser>>
|
||||
* <<jc-authentication-userdetailsservice,Simplified UserDetailsService Java Configuration>>
|
||||
* <<jc-authentication-authenticationprovider,Simplified AuthenticationProvider Java Configuration>>
|
||||
|
||||
=== What's new in Spring Security 4.0
|
||||
|
||||
@@ -916,17 +917,35 @@ cn: admin
|
||||
uniqueMember: uid=admin,ou=people,dc=springframework,dc=org
|
||||
----
|
||||
|
||||
[[jc-authentication-authenticationprovider]]
|
||||
==== AuthenticationProvider
|
||||
|
||||
You can define custom authentication by exposing a custom `AuthenticationProvider` as a bean.
|
||||
For example, the following will customize authentication assuming that `SpringAuthenticationProvider` implements `AuthenticationProvider`:
|
||||
|
||||
NOTE: This is only used if the `AuthenticationManagerBuilder` has not been populated
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@Bean
|
||||
public SpringAuthenticationProvider springAuthenticationProvider() {
|
||||
return new SpringAuthenticationProvider();
|
||||
}
|
||||
----
|
||||
|
||||
[[jc-authentication-userdetailsservice]]
|
||||
==== UserDetailsService
|
||||
|
||||
You can define custom authentication by exposing a custom `UserDetailsService` as a bean.
|
||||
For example, the following will customize authentication assuming that `SpringDataUserDetailsService` implements `UserDetailsService`:
|
||||
|
||||
NOTE: This is only used if the `AuthenticationManagerBuilder` has not been populated and no `AuthenticationProviderBean` is defined.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@Bean
|
||||
public SpringDataUserDetailsService springDataUserDetailsService() {
|
||||
return new SpringDataUserDetailsService();
|
||||
return new SpringDataUserDetailsService();
|
||||
}
|
||||
----
|
||||
|
||||
@@ -937,7 +956,7 @@ For example, if you use bcrypt you can add a bean definition as shown below:
|
||||
----
|
||||
@Bean
|
||||
public BCryptPasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user