whyczh
2021-05-11 499930c8b34cbf05c163b2f62322ae93ff248038
登录筛查冻结用户
3个文件已修改
12 ■■■■ 已修改文件
src/main/java/com/whyc/realm/CustomRealm.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/LoginService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/UserBridgeService.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/realm/CustomRealm.java
@@ -33,11 +33,15 @@
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        String userName = (String) authenticationToken.getPrincipal();
        User user = userBridgeService.findPasswordAndSlatByUserName(userName);
        if(user.getId()==0){
            System.out.printf("账号不存在");
            throw new UnknownAccountException("账号不存在");
        }
        if (user.getState()==1){
            System.out.println("账号已冻结");
            throw new DisabledAccountException("冻结用户,不可使用");
        }
        return new SimpleAuthenticationInfo(user,user.getPassword(), ByteSource.Util.bytes(user.getSalt()),getName());
    }
src/main/java/com/whyc/service/LoginService.java
@@ -11,6 +11,7 @@
import com.whyc.util.DigestsUtil;
import com.whyc.util.ShiroUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.DisabledAccountException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
@@ -40,6 +41,8 @@
            return new Response<>().set(0,false,"账号不存在");
        }catch (IncorrectCredentialsException e) {
            return new Response<>().set(0,false,"密码错误");
        }catch (DisabledAccountException e){
            return new Response<>().set(0,false,"冻结用户");
        }catch (Exception e){
            e.printStackTrace();
            return new Response<>().set(0,false,"其他异常");
src/main/java/com/whyc/service/UserBridgeService.java
@@ -35,7 +35,8 @@
    public User findPasswordAndSlatByUserName(String userName) {
        QueryWrapper<User> queryWrapper = Wrappers.query();
        queryWrapper.select("id","name","password","salt").eq("name",userName);
        //queryWrapper.select("id","name","password","salt").eq("name",userName);
        queryWrapper.eq("name",userName);
        try{
            User user = userMapper.selectOne(queryWrapper);
            if(user==null){