Skip to content

Commit

Permalink
Merge branch '2.5dev' of https://github.com/jhpx/eladmin
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Apr 23, 2020
2 parents 2380ed7 + c4ddacc commit d35ffc9
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package me.zhengjie.modules.security.service;

import me.zhengjie.exception.BadRequestException;
import me.zhengjie.exception.EntityNotFoundException;
import me.zhengjie.modules.security.service.dto.JwtUserDto;
import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.*;
import me.zhengjie.modules.system.service.dto.UserDto;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -28,10 +30,16 @@ public UserDetailsServiceImpl(UserService userService, RoleService roleService)
}

@Override
public JwtUserDto loadUserByUsername(String username){
UserDto user = userService.findByName(username);
public JwtUserDto loadUserByUsername(String username) {
UserDto user;
try {
user = userService.findByName(username);
} catch (EntityNotFoundException e) {
// SpringSecurity会自动转换UsernameNotFoundException为BadCredentialsException
throw new UsernameNotFoundException("", e);
}
if (user == null) {
throw new BadRequestException("账号不存在");
throw new UsernameNotFoundException("");
} else {
if (!user.getEnabled()) {
throw new BadRequestException("账号未激活");
Expand Down

0 comments on commit d35ffc9

Please sign in to comment.