mirror of https://github.com/elunez/eladmin
fix: 修复缓存导致的用户登录提示密码错误问题
parent
10b43563aa
commit
7b2fa3c679
|
@ -19,10 +19,11 @@ import lombok.RequiredArgsConstructor;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.security.service.dto.JwtUserDto;
|
||||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.modules.system.service.DataService;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.UserService;
|
||||
import me.zhengjie.modules.system.service.dto.UserLoginDto;
|
||||
import me.zhengjie.modules.system.service.dto.UserDto;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -43,7 +44,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
|||
public JwtUserDto loadUserByUsername(String username) {
|
||||
JwtUserDto jwtUserDto = userCacheManager.getUserCache(username);
|
||||
if(jwtUserDto == null){
|
||||
UserLoginDto user = userService.getLoginData(username);
|
||||
UserDto user = userService.getLoginData(username);
|
||||
if (user == null) {
|
||||
throw new BadRequestException("用户不存在");
|
||||
} else {
|
||||
|
|
|
@ -20,7 +20,7 @@ import io.swagger.annotations.ApiModelProperty;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.zhengjie.modules.system.service.dto.UserLoginDto;
|
||||
import me.zhengjie.modules.system.service.dto.UserDto;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -35,7 +35,7 @@ import java.util.stream.Collectors;
|
|||
public class JwtUserDto implements UserDetails {
|
||||
|
||||
@ApiModelProperty(value = "用户")
|
||||
private final UserLoginDto user;
|
||||
private final UserDto user;
|
||||
|
||||
@ApiModelProperty(value = "数据权限")
|
||||
private final List<Long> dataScopes;
|
||||
|
@ -51,12 +51,6 @@ public class JwtUserDto implements UserDetails {
|
|||
return authorities.stream().map(AuthorityDto::getAuthority).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@JSONField(serialize = false)
|
||||
public String getPassword() {
|
||||
return user.getPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
@JSONField(serialize = false)
|
||||
public String getUsername() {
|
||||
|
|
|
@ -18,7 +18,6 @@ package me.zhengjie.modules.system.service;
|
|||
import me.zhengjie.utils.PageResult;
|
||||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.modules.system.service.dto.UserDto;
|
||||
import me.zhengjie.modules.system.service.dto.UserLoginDto;
|
||||
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
@ -72,7 +71,7 @@ public interface UserService {
|
|||
* @param userName /
|
||||
* @return /
|
||||
*/
|
||||
UserLoginDto getLoginData(String userName);
|
||||
UserDto getLoginData(String userName);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
|
|
|
@ -68,8 +68,8 @@ public class UserDto extends BaseDTO implements Serializable {
|
|||
@ApiModelProperty(value = "头像路径")
|
||||
private String avatarPath;
|
||||
|
||||
@ApiModelProperty(value = "密码")
|
||||
@JSONField(serialize = false)
|
||||
@ApiModelProperty(value = "密码")
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty(value = "是否启用")
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019-2025 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @description 用户缓存时使用
|
||||
* @date 2022-05-26
|
||||
**/
|
||||
public class UserLoginDto extends UserDto {
|
||||
|
||||
@ApiModelProperty(value = "密码")
|
||||
@JSONField(serialize = false)
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty(value = "是否为管理员")
|
||||
private Boolean isAdmin;
|
||||
}
|
|
@ -27,7 +27,6 @@ import me.zhengjie.exception.EntityNotFoundException;
|
|||
import me.zhengjie.modules.system.repository.UserRepository;
|
||||
import me.zhengjie.modules.system.service.UserService;
|
||||
import me.zhengjie.modules.system.service.dto.*;
|
||||
import me.zhengjie.modules.system.service.mapstruct.UserLoginMapper;
|
||||
import me.zhengjie.modules.system.service.mapstruct.UserMapper;
|
||||
import me.zhengjie.utils.*;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
@ -57,7 +56,6 @@ public class UserServiceImpl implements UserService {
|
|||
private final RedisUtils redisUtils;
|
||||
private final UserCacheManager userCacheManager;
|
||||
private final OnlineUserService onlineUserService;
|
||||
private final UserLoginMapper userLoginMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<UserDto> queryAll(UserQueryCriteria criteria, Pageable pageable) {
|
||||
|
@ -182,12 +180,12 @@ public class UserServiceImpl implements UserService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public UserLoginDto getLoginData(String userName) {
|
||||
public UserDto getLoginData(String userName) {
|
||||
User user = userRepository.findByUsername(userName);
|
||||
if (user == null) {
|
||||
return null;
|
||||
} else {
|
||||
return userLoginMapper.toDto(user);
|
||||
return userMapper.toDto(user);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019-2025 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.system.service.mapstruct;
|
||||
|
||||
import me.zhengjie.base.BaseMapper;
|
||||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.modules.system.service.dto.UserLoginDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-23
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {RoleMapper.class, DeptMapper.class, JobMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface UserLoginMapper extends BaseMapper<UserLoginDto, User> {
|
||||
}
|
Loading…
Reference in New Issue