1
0
mirror of synced 2026-08-04 17:27:13 +00:00

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:
Rob Winch
2016-03-22 16:17:25 -05:00
parent 533a5f0905
commit 4b650dc58d
5 changed files with 195 additions and 17 deletions
+21 -2
View File
@@ -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();
}
----