Configuring AuthenticationManagerBuilder to use User Repository

Configuring AuthenticationManagerBuilder to use User Repository

I am trying to secure Rest APIs using spring boot and JWT. Right now I have been able to piece together pieces of the configuration to get a token generated with a hard coded username and password. I would like my User class and repository to be used instead.

I am trying to secure Rest APIs using spring boot and JWT. Right now I have been able to piece together pieces of the configuration to get a token generated with a hard coded username and password. I would like my User class and repository to be used instead.

I have been able to hardcode a user here

  @Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication()
        .withUser("user")
        .password(passwordEncoder().encode("password"))
        .authorities("ROLE_USER");
}

Should I be pointing this to my UserDetailsService? How would I do that?

@Service
public class UserSecurityService implements UserDetailsService {

private static final Logger LOG = LoggerFactory.getLogger(UserSecurityService.class);

@Autowired private UserRepository userRepository;

@Override public UserDetails loadUserByUsername (String username) throws UsernameNotFoundException { User user = userRepository.findByUsername(username);

if (null == user) {
    LOG.warn("username not found");
    throw new UsernameNotFoundException("Username" + username + "not found");
}

return user;

}


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Build Web App Authentication using Spring Boot, Spring Security, MongoDB and Angular 8

In this article, you'll learn how to build web application authentication using Spring Boot, Spring Security, MongoDB, and Angular 8

Can we use spring data repository to update embedded documents in mongodb

Can we use spring data repository to update embedded documents in mongodb

Build a Reactive App with Spring Boot and MongoDB

This tutorial shows how to build a non-blocking, reactive app with Spring Boot, Spring WebFlux, and MongoDB