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;

}


mongodb spring

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

MongoDB Database and java applications

Enroll for free demo to acquire the best knowledge on the schema-less database from live industry experts through MongoDB training

Spring Boot, Security, MVC, Data and MongoDB Login Example

Creating the authentication (login) using Spring Boot, Spring Security, Spring Data and MongoDB for Java web application with custom User Details Service. Spring Security is one of the most used Security frameworks for Java Web Application.

Building and deploying Spring Cloud application with Mongodb on Kubernetes cluster

You will learn how to develop , build and deploy Spring cloud application with Mongo database on a Kubernetes cluster and also you can learn how to create co...

Which is the Best MongoDB GUI?

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much

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