From d73dc1416bfe29c031c2094db057f6da09ab6b0a Mon Sep 17 00:00:00 2001 From: Mario Petrovski Date: Thu, 20 Jul 2023 22:06:42 +0200 Subject: [PATCH] Closes #11450 Add Java beans configuration for Remmember Me Docs --- .../servlet/authentication/rememberme.adoc | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/modules/ROOT/pages/servlet/authentication/rememberme.adoc b/docs/modules/ROOT/pages/servlet/authentication/rememberme.adoc index 552efda2608..e774d66b120 100644 --- a/docs/modules/ROOT/pages/servlet/authentication/rememberme.adoc +++ b/docs/modules/ROOT/pages/servlet/authentication/rememberme.adoc @@ -159,7 +159,39 @@ XML:: The following beans are required in an application context to enable remember-me services: -[source,xml] +[tabs] +====== +Java:: ++ +[source,java,role="primary"] +---- +@Bean +RememberMeAuthenticationFilter rememberMeFilter() { + RememberMeAuthenticationFilter rememberMeFilter = new RememberMeAuthenticationFilter(); + rememberMeFilter.setRememberMeServices(rememberMeServices()); + rememberMeFilter.setAuthenticationManager(theAuthenticationManager); + return rememberMeFilter; +} + +@Bean +TokenBasedRememberMeServices rememberMeServices() { + TokenBasedRememberMeServices rememberMeServices = new TokenBasedRememberMeServices(); + rememberMeServices.setUserDetailsService(myUserDetailsService); + rememberMeServices.setKey("springRocks"); + return rememberMeServices; +} + +@Bean +RememberMeAuthenticationProvider rememberMeAuthenticationProvider() { + RememberMeAuthenticationProvider rememberMeAuthenticationProvider = new RememberMeAuthenticationProvider(); + rememberMeAuthenticationProvider.setKey("springRocks"); + return rememberMeAuthenticationProvider; +} +---- + +XML:: ++ +[source,xml,role="secondary"] ---- @@ -178,6 +210,7 @@ The following beans are required in an application context to enable remember-me ---- +====== Don't forget to add your `RememberMeServices` implementation to your `UsernamePasswordAuthenticationFilter.setRememberMeServices()` property, include the `RememberMeAuthenticationProvider` in your `AuthenticationManager.setProviders()` list, and add `RememberMeAuthenticationFilter` into your `FilterChainProxy` (typically immediately after your `UsernamePasswordAuthenticationFilter`).