source: trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/CustomUserDetailsServiceImpl.java

Last change on this file was 84d0fbb, checked in by Ema <ema_spirova@…>, 3 years ago

spring security 2.0

  • Property mode set to 100644
File size: 1.1 KB
Line 
1package finki.diplomska.tripplanner.service.impl;
2
3import finki.diplomska.tripplanner.models.User;
4import finki.diplomska.tripplanner.repository.jpa.JpaUserRepository;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.security.core.userdetails.UserDetails;
7import org.springframework.security.core.userdetails.UserDetailsService;
8import org.springframework.security.core.userdetails.UsernameNotFoundException;
9import org.springframework.stereotype.Service;
10
11import javax.transaction.Transactional;
12
13@Service
14public class CustomUserDetailsServiceImpl implements UserDetailsService {
15
16 @Autowired
17 private JpaUserRepository userRepository;
18
19 @Override
20 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
21 User user = userRepository.findByUsername(username);
22 if(user==null) new UsernameNotFoundException("User not found");
23 return user;
24 }
25
26
27 @Transactional
28 public User loadUserById(Long id){
29 User user = userRepository.getById(id);
30 if(user==null) new UsernameNotFoundException("User not found");
31 return user;
32
33 }
34}
Note: See TracBrowser for help on using the repository browser.