Created
March 2, 2014 05:27
-
-
Save sivaprasadreddy/9302345 to your computer and use it in GitHub Desktop.
CustomUserDetailsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
@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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment