Skip to content

Small bug with ApplicationConfiguration.java, UserRepository #1

@kRichard32

Description

@kRichard32

https://github.com/Erik-Cupsa/Spring-Security-Tutorial/blob/72ab4f1c582da4f5cb4b3d334d36f022a42df1d2/demo/src/main/java/com/example/demo/config/JwtAuthenticationFilter.java#L52C13-L64C57

this.userDetailsService.loadUserByUsername is called with a username (jwtService.extractUsername(jwt) extracts the username, not the email), and later UserDetails userDetails = this.userDetailsService.loadUserByUsername(userEmail); is called. This function comes from applicationConfiguration.java, where userDetailsService is implemented with userRepository.findByEmail(username). As emails aren't usernames, these functions cause a UsernameNotFoundException to be thrown when attempting to do any request to the server with valid authorization tokens.

If you change userRepository.findByEmail to userRepository.findByUsername in ApplicationConfiguration.java and add Optional<UserKoko> findByUsername(String username); in UserRepository.java, this problem is fixed, and the code works as intended.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions