Last change
on this file since 84d0fbb 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
|
Rev | Line | |
---|
[84d0fbb] | 1 | package finki.diplomska.tripplanner.service.impl;
|
---|
| 2 |
|
---|
| 3 | import finki.diplomska.tripplanner.models.User;
|
---|
| 4 | import finki.diplomska.tripplanner.repository.jpa.JpaUserRepository;
|
---|
| 5 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
| 6 | import org.springframework.security.core.userdetails.UserDetails;
|
---|
| 7 | import org.springframework.security.core.userdetails.UserDetailsService;
|
---|
| 8 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
---|
| 9 | import org.springframework.stereotype.Service;
|
---|
| 10 |
|
---|
| 11 | import javax.transaction.Transactional;
|
---|
| 12 |
|
---|
| 13 | @Service
|
---|
| 14 | public 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.