Spring Boot ‘Failed to find user’ with InMemoryUserDetailsManager

Using InMemoryUserDetailsManager, when I try to login logs show ‘failed to find user’.

My SecurityConfiguration.java

@Configurable
@EnableWebSecurity
public class SecurityConfiguration {


    @Autowired
    private BCryptPasswordEncoder passwordEncoder;

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
        return httpSecurity.authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> {
                    authorizationManagerRequestMatcherRegistry.requestMatchers("/home").permitAll();
                    authorizationManagerRequestMatcherRegistry.requestMatchers("/admin/**").hasRole("ADMIN");
                    authorizationManagerRequestMatcherRegistry.requestMatchers("/user/**").hasRole("USER");
                    authorizationManagerRequestMatcherRegistry.anyRequest().authenticated();
                })
                .formLogin(AbstractAuthenticationFilterConfigurer::permitAll)
                .build();

    }

    @Bean
    public UserDetailsService userDetailsService() {


        UserDetails normalUser = User.builder()
                .username("gc")
                .password(passwordEncoder.encode("1234"))
                .roles("USER")
                .build();

        UserDetails adminUser = User.builder()
                .username("admin")
                .password(passwordEncoder.encode("9876"))
                .roles("ADMIN", "USER")
                .build();

        return new InMemoryUserDetailsManager(normalUser, adminUser);
    }
}

I get the error for either user.
“Failed to find user”

gc:

**> 2024-07-19T20:36:15.828-04:00 INFO 5674 — [MyREST] [

main] r$InitializeUserDetailsManagerConfigurer : Global
AuthenticationManager configured with UserDetailsService bean with
name inMemoryUserDetailsManager 2024-07-19T20:36:15.932-04:00 DEBUG
5674 — [MyREST] [ main]
o.s.s.web.DefaultSecurityFilterChain : Will secure any request
with filters: DisableEncodeUrlFilter,
WebAsyncManagerIntegrationFilter, SecurityContextHolderFilter,
HeaderWriterFilter, CorsFilter, CsrfFilter, LogoutFilter,
UsernamePasswordAuthenticationFilter,
DefaultLoginPageGeneratingFilter, DefaultLogoutPageGeneratingFilter,
BasicAuthenticationFilter, RequestCacheAwareFilter,
SecurityContextHolderAwareRequestFilter,
AnonymousAuthenticationFilter, ExceptionTranslationFilter,
AuthorizationFilter 2024-07-19T20:36:15.987-04:00 INFO 5674 —
[MyREST] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer :
Tomcat started on port 8080 (http) with context path ‘/’
2024-07-19T20:36:15.996-04:00 INFO 5674 — [MyREST] [
main] com.example.myrest.MyRestApplication : Started
MyRestApplication in 2.645 seconds (process running for 4.114)
2024-07-19T20:37:11.005-04:00 INFO 5674 — [MyREST]
[nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] :
Initializing Spring DispatcherServlet ‘dispatcherServlet’
2024-07-19T20:37:11.005-04:00 INFO 5674 — [MyREST]
[nio-8080-exec-1] o.s.web.servlet.DispatcherServlet :
Initializing Servlet ‘dispatcherServlet’ 2024-07-19T20:37:11.007-04:00
INFO 5674 — [MyREST] [nio-8080-exec-1]
o.s.web.servlet.DispatcherServlet : Completed initialization in
2 ms 2024-07-19T20:37:11.032-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-1] o.s.security.web.FilterChainProxy : Securing
GET /login?error 2024-07-19T20:37:12.120-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-2] o.s.security.web.FilterChainProxy : Securing
GET /hello?myName=ike 2024-07-19T20:37:12.139-04:00 DEBUG 5674 —
[MyREST] [nio-8080-exec-2] o.s.s.w.a.AnonymousAuthenticationFilter :
Set SecurityContextHolder to anonymous SecurityContext
2024-07-19T20:37:12.156-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-2] o.s.s.w.s.HttpSessionRequestCache : Saved
request http://localhost:8080/hello?myName=ike&continue to session
2024-07-19T20:37:12.162-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-2] s.w.a.DelegatingAuthenticationEntryPoint : Trying to
match using And [Not [RequestHeaderRequestMatcher
[expectedHeaderName=X-Requested-With,
expectedHeaderValue=XMLHttpRequest]], MediaTypeRequestMatcher
[contentNegotiationStrategy=org.springframework.web.accept.ContentNegotiationManager@775d5923,
matchingMediaTypes=[application/xhtml+xml, image/, text/html,
text/plain], useEquals=false, ignoredMediaTypes=[
/]]]
2024-07-19T20:37:12.162-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-2] s.w.a.DelegatingAuthenticationEntryPoint : Match
found! Executing
org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint@70d77826
2024-07-19T20:37:12.163-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-2] o.s.s.web.DefaultRedirectStrategy :
Redirecting to http://localhost:8080/login
2024-07-19T20:37:12.174-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-3] o.s.security.web.FilterChainProxy : Securing
GET /login 2024-07-19T20:37:14.905-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-4] o.s.security.web.FilterChainProxy : Securing
GET /user/home 2024-07-19T20:37:14.906-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-4] o.s.s.w.a.AnonymousAuthenticationFilter : Set
SecurityContextHolder to anonymous SecurityContext
2024-07-19T20:37:14.907-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-4] o.s.s.w.s.HttpSessionRequestCache : Saved
request http://localhost:8080/user/home?continue to session
2024-07-19T20:37:14.908-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-4] s.w.a.DelegatingAuthenticationEntryPoint : Trying to
match using And [Not [RequestHeaderRequestMatcher
[expectedHeaderName=X-Requested-With,
expectedHeaderValue=XMLHttpRequest]], MediaTypeRequestMatcher
[contentNegotiationStrategy=org.springframework.web.accept.ContentNegotiationManager@775d5923,
matchingMediaTypes=[application/xhtml+xml, image/
, text/html,
text/plain], useEquals=false, ignoredMediaTypes=[/]]]
2024-07-19T20:37:14.908-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-4] s.w.a.DelegatingAuthenticationEntryPoint : Match
found! Executing
org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint@70d77826
2024-07-19T20:37:14.908-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-4] o.s.s.web.DefaultRedirectStrategy :
Redirecting to http://localhost:8080/login
2024-07-19T20:37:14.923-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-5] o.s.security.web.FilterChainProxy : Securing
GET /login 2024-07-19T20:37:21.526-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-6] o.s.security.web.FilterChainProxy : Securing
POST /login 2024-07-19T20:37:21.739-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-6] o.s.s.a.dao.DaoAuthenticationProvider : Failed to
find user ‘gc’ 2024-07-19T20:37:21.743-04:00 DEBUG 5674 — [MyREST]
[nio-8080-exec-6] o.s.s.web.DefaultRedirectStrategy :
Redirecting to /login?error 2024-07-19T20:37:21.754-04:00 DEBUG 5674
— [MyREST] [nio-8080-exec-7] o.s.security.web.FilterChainProxy : Securing GET /login?error**

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật