Package com.sivalabs.springapp.config

Source Code of com.sivalabs.springapp.config.CustomUserDetailsService

/**
*
*/
package com.sivalabs.springapp.config;

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.Component;

import com.sivalabs.springapp.entities.User;
import com.sivalabs.springapp.services.UserService;
import com.sivalabs.springapp.web.config.SecurityUser;

/**
* @author Siva
*
*/
@Component
public class CustomUserDetailsService implements UserDetailsService{

  @Autowired
  private UserService userService;
 
  @Override
  public UserDetails loadUserByUsername(String userName)
      throws UsernameNotFoundException {
    User user = userService.findUserByEmail(userName);
    if(user == null){
      throw new UsernameNotFoundException("UserName "+userName+" not found");
    }
    return new SecurityUser(user);
  }

}
TOP

Related Classes of com.sivalabs.springapp.config.CustomUserDetailsService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.