1 package fr.ifremer.quadrige2.synchro.server.security;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import javax.annotation.Resource;
29
30 import fr.ifremer.quadrige2.core.dao.administration.user.QuserJdbcDao;
31 import fr.ifremer.quadrige2.core.vo.administration.user.PrivilegeVO;
32 import org.springframework.context.annotation.Lazy;
33 import org.springframework.security.core.userdetails.UserDetails;
34 import org.springframework.security.core.userdetails.UserDetailsService;
35 import org.springframework.security.core.userdetails.UsernameNotFoundException;
36 import org.springframework.stereotype.Service;
37 import org.springframework.transaction.annotation.Transactional;
38
39 import java.util.List;
40
41
42
43
44
45
46 @Service("quadrige2UserDetailsService")
47 @Lazy
48 @Transactional
49 public class Quadrige2UserDetailsServiceImpl implements UserDetailsService {
50
51 @Resource(name = "quserJdbcDao")
52 QuserJdbcDao quserJdbcDao;
53
54 @Override
55 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
56 Integer userId = null;
57
58 if (username == null) {
59 throw new UsernameNotFoundException("Provided username is null");
60 }
61
62 try {
63 userId = quserJdbcDao.getUserIdByUsername(username);
64 } catch (Exception ex) {
65 throw new UsernameNotFoundException("User not found from username: " + username, ex);
66 }
67
68 if (userId == null) {
69 throw new UsernameNotFoundException("User not found from username: " + username);
70 }
71
72
73 List<PrivilegeVO> privileges = quserJdbcDao.getPrivilegesByUserId(userId);
74
75
76
77 return new Quadrige2UserDetailsImpl(userId, privileges);
78 }
79
80 }