| | |
| | | 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()); |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | 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,"其他异常"); |
| | |
| | | |
| | | 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){ |