提交 | 用户 | 时间
|
e57a89
|
1 |
package com.jcdm.framework.web.service; |
懒 |
2 |
|
|
3 |
import org.slf4j.Logger; |
|
4 |
import org.slf4j.LoggerFactory; |
|
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 |
import com.jcdm.common.core.domain.entity.SysUser; |
|
11 |
import com.jcdm.common.core.domain.model.LoginUser; |
|
12 |
import com.jcdm.common.enums.UserStatus; |
|
13 |
import com.jcdm.common.exception.ServiceException; |
|
14 |
import com.jcdm.common.utils.MessageUtils; |
|
15 |
import com.jcdm.common.utils.StringUtils; |
|
16 |
import com.jcdm.system.service.ISysUserService; |
|
17 |
|
|
18 |
/** |
|
19 |
* 用户验证处理 |
|
20 |
* |
|
21 |
* @author jc |
|
22 |
*/ |
|
23 |
@Service |
|
24 |
public class UserDetailsServiceImpl implements UserDetailsService |
|
25 |
{ |
|
26 |
private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class); |
|
27 |
|
|
28 |
@Autowired |
|
29 |
private ISysUserService userService; |
|
30 |
|
|
31 |
@Autowired |
|
32 |
private SysPasswordService passwordService; |
|
33 |
|
|
34 |
@Autowired |
|
35 |
private SysPermissionService permissionService; |
|
36 |
|
|
37 |
@Override |
|
38 |
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException |
|
39 |
{ |
|
40 |
SysUser user = userService.selectUserByUserName(username); |
|
41 |
if (StringUtils.isNull(user)) |
|
42 |
{ |
|
43 |
log.info("登录用户:{} 不存在.", username); |
|
44 |
throw new ServiceException(MessageUtils.message("user.not.exists")); |
|
45 |
} |
|
46 |
else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) |
|
47 |
{ |
|
48 |
log.info("登录用户:{} 已被删除.", username); |
|
49 |
throw new ServiceException(MessageUtils.message("user.password.delete")); |
|
50 |
} |
|
51 |
else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) |
|
52 |
{ |
|
53 |
log.info("登录用户:{} 已被停用.", username); |
|
54 |
throw new ServiceException(MessageUtils.message("user.blocked")); |
|
55 |
} |
|
56 |
|
|
57 |
passwordService.validate(user); |
|
58 |
|
|
59 |
return createLoginUser(user); |
|
60 |
} |
|
61 |
|
|
62 |
public UserDetails createLoginUser(SysUser user) |
|
63 |
{ |
|
64 |
return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user)); |
|
65 |
} |
|
66 |
} |