org.obozek.minermonitor.config.MonitorUserDetailsService.java Source code

Java tutorial

Introduction

Here is the source code for org.obozek.minermonitor.config.MonitorUserDetailsService.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.obozek.minermonitor.config;

import org.obozek.minermonitor.entities.User;
import org.obozek.minermonitor.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 *
 * @author infragile
 */
@Service
public class MonitorUserDetailsService implements UserDetailsService {

    @Autowired
    private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userService.getUser(username);
        if (user == null) {
            throw new UsernameNotFoundException("User with username " + username + " wasn't found");
        }
        return new MinerUserDetails(user);
    }

}