|
@@ -3,6 +3,7 @@ package com.macro.mall.service.impl;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
+import com.macro.mall.bo.AdminUserDetails;
|
|
import com.macro.mall.dao.UmsAdminPermissionRelationDao;
|
|
import com.macro.mall.dao.UmsAdminPermissionRelationDao;
|
|
import com.macro.mall.dao.UmsAdminRoleRelationDao;
|
|
import com.macro.mall.dao.UmsAdminRoleRelationDao;
|
|
import com.macro.mall.dto.UmsAdminParam;
|
|
import com.macro.mall.dto.UmsAdminParam;
|
|
@@ -12,20 +13,18 @@ import com.macro.mall.mapper.UmsAdminMapper;
|
|
import com.macro.mall.mapper.UmsAdminPermissionRelationMapper;
|
|
import com.macro.mall.mapper.UmsAdminPermissionRelationMapper;
|
|
import com.macro.mall.mapper.UmsAdminRoleRelationMapper;
|
|
import com.macro.mall.mapper.UmsAdminRoleRelationMapper;
|
|
import com.macro.mall.model.*;
|
|
import com.macro.mall.model.*;
|
|
|
|
+import com.macro.mall.security.util.JwtTokenUtil;
|
|
import com.macro.mall.service.UmsAdminService;
|
|
import com.macro.mall.service.UmsAdminService;
|
|
-import com.macro.mall.util.JwtTokenUtil;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
|
-import org.springframework.security.authentication.AuthenticationManager;
|
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.core.AuthenticationException;
|
|
import org.springframework.security.core.AuthenticationException;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
-import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
|
|
|
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -47,15 +46,9 @@ import java.util.stream.Collectors;
|
|
public class UmsAdminServiceImpl implements UmsAdminService {
|
|
public class UmsAdminServiceImpl implements UmsAdminService {
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(UmsAdminServiceImpl.class);
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(UmsAdminServiceImpl.class);
|
|
@Autowired
|
|
@Autowired
|
|
- private AuthenticationManager authenticationManager;
|
|
|
|
- @Autowired
|
|
|
|
- private UserDetailsService userDetailsService;
|
|
|
|
- @Autowired
|
|
|
|
private JwtTokenUtil jwtTokenUtil;
|
|
private JwtTokenUtil jwtTokenUtil;
|
|
@Autowired
|
|
@Autowired
|
|
private PasswordEncoder passwordEncoder;
|
|
private PasswordEncoder passwordEncoder;
|
|
- @Value("${jwt.tokenHead}")
|
|
|
|
- private String tokenHead;
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private UmsAdminMapper adminMapper;
|
|
private UmsAdminMapper adminMapper;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -105,7 +98,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
|
String token = null;
|
|
String token = null;
|
|
//密码需要客户端加密后传递
|
|
//密码需要客户端加密后传递
|
|
try {
|
|
try {
|
|
- UserDetails userDetails = userDetailsService.loadUserByUsername(username);
|
|
|
|
|
|
+ UserDetails userDetails = loadUserByUsername(username);
|
|
if(!passwordEncoder.matches(password,userDetails.getPassword())){
|
|
if(!passwordEncoder.matches(password,userDetails.getPassword())){
|
|
throw new BadCredentialsException("密码不正确");
|
|
throw new BadCredentialsException("密码不正确");
|
|
}
|
|
}
|
|
@@ -148,11 +141,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public String refreshToken(String oldToken) {
|
|
public String refreshToken(String oldToken) {
|
|
- String token = oldToken.substring(tokenHead.length());
|
|
|
|
- if (jwtTokenUtil.canRefresh(token)) {
|
|
|
|
- return jwtTokenUtil.refreshToken(token);
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
|
|
+ return jwtTokenUtil.refreshHeadToken(oldToken);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -274,4 +263,15 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
|
adminMapper.updateByPrimaryKey(umsAdmin);
|
|
adminMapper.updateByPrimaryKey(umsAdmin);
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public UserDetails loadUserByUsername(String username){
|
|
|
|
+ //获取用户信息
|
|
|
|
+ UmsAdmin admin = getAdminByUsername(username);
|
|
|
|
+ if (admin != null) {
|
|
|
|
+ List<UmsPermission> permissionList = getPermissionList(admin.getId());
|
|
|
|
+ return new AdminUserDetails(admin,permissionList);
|
|
|
|
+ }
|
|
|
|
+ throw new UsernameNotFoundException("用户名或密码错误");
|
|
|
|
+ }
|
|
}
|
|
}
|