To customize security, you could have to define your own UserDetails and UserDetailsService.
@Entity
@Table(name = "users")
public class User implements UserDetails, Serializable {
}
Create a JPA entity to implement the UserDetails interface.
@Component
public class SimpleUserDetailsServiceImpl implements UserDetailsService {
private static final Logger log = LoggerFactory.getLogger(SimpleUserDetailsServiceImpl.class);
private UserRepository userRepository;
public SimpleUserDetailsServiceImpl(UserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = userRepository.findByUsername(username);
if (user == null) {
throw new UsernameNotFoundException("username not found:" + username);
}
log.debug("found by username @" + username);
return user;
}
}
Define a UserDetailsService, which can be detected by the newest Spring Security, there is no need to wire the UserDetailsService with AuthenticationManager in configuration file. Check the Upgrade to Spring Boot 1.4 for more details.