Rob Winch f01a13aa52 Antora
mkdir -p docs/modules/ROOT/
mkdir -p docs/modules/ROOT/pages/
git checkout antora-2.x docs/antora.yml
git checkout antora-2.x docs/modules/ROOT/nav.adoc
mv docs/manual/src/docs/asciidoc/images docs/modules/ROOT/
mv docs/manual/src/docs/asciidoc/_includes/* docs/modules/ROOT/pages/
cp ~/code/rwinch/spring-reference/*antora* ~/code/spring-projects/spring-security/
mv docs/modules/ROOT/pages/about docs/modules/ROOT/pages/overview
2021-09-23 15:45:22 -05:00

38 lines
1.3 KiB
Plaintext

[[servlet-authentication-userdetailsservice]]
= UserDetailsService
{security-api-url}org/springframework/security/core/userdetails/UserDetailsService.html[`UserDetailsService`] is used by <<servlet-authentication-daoauthenticationprovider,`DaoAuthenticationProvider`>> for retrieving a username, password, and other attributes for authenticating with a username and password.
Spring Security provides <<servlet-authentication-inmemory,in-memory>> and <<servlet-authentication-jdbc,JDBC>> implementations of `UserDetailsService`.
You can define custom authentication by exposing a custom `UserDetailsService` as a bean.
For example, the following will customize authentication assuming that `CustomUserDetailsService` implements `UserDetailsService`:
NOTE: This is only used if the `AuthenticationManagerBuilder` has not been populated and no `AuthenticationProviderBean` is defined.
.Custom UserDetailsService Bean
====
.Java
[source,java,role="primary"]
----
@Bean
CustomUserDetailsService customUserDetailsService() {
return new CustomUserDetailsService();
}
----
.XML
[source,java,role="secondary"]
----
<b:bean class="example.CustomUserDetailsService"/>
----
.Kotlin
[source,kotlin,role="secondary"]
----
@Bean
fun customUserDetailsService() = CustomUserDetailsService()
----
====
// FIXME: Add CustomUserDetails example with links to @AuthenticationPrincipal