| @@ -21,6 +21,8 @@ import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.io.IOUtils; | import org.apache.commons.io.IOUtils; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.apache.shiro.SecurityUtils; | import org.apache.shiro.SecurityUtils; | ||||
| import org.apache.shiro.authc.DisabledAccountException; | |||||
| import org.apache.shiro.authc.UnknownAccountException; | |||||
| import org.apache.shiro.authc.UsernamePasswordToken; | import org.apache.shiro.authc.UsernamePasswordToken; | ||||
| import org.apache.shiro.subject.Subject; | import org.apache.shiro.subject.Subject; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -102,15 +104,28 @@ public class HomeController extends BaseController { | |||||
| // throw new SystemException(ErrorCode.LOGIN_USER_OR_PWD_ERROR); | // throw new SystemException(ErrorCode.LOGIN_USER_OR_PWD_ERROR); | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | ||||
| } | } | ||||
| // check user | |||||
| MallUserInfo userCheck = mallUserInfoService.getByUsername(user.getUsername()); | |||||
| if(userCheck == null) { | |||||
| logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| if(userCheck.getStatus().equals(EnumMallUserStatus.NOT_VALID.getCode())) { | |||||
| logger.error(ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
| } | |||||
| boolean isLogin = false; | boolean isLogin = false; | ||||
| try { | try { | ||||
| Subject subject = SecurityUtils.getSubject(); | Subject subject = SecurityUtils.getSubject(); | ||||
| UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword()); | UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword()); | ||||
| subject.login(token); | subject.login(token); | ||||
| isLogin = true; | isLogin = true; | ||||
| } catch (MallinkException e) { | |||||
| } catch (UnknownAccountException e) { | |||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } catch (DisabledAccountException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| return new ResultData(ErrorCode.USER_PASSWD_ERR); | return new ResultData(ErrorCode.USER_PASSWD_ERR); | ||||
| @@ -24,6 +24,8 @@ import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | import me.chanjar.weixin.mp.bean.result.WxMpUser; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.apache.shiro.SecurityUtils; | import org.apache.shiro.SecurityUtils; | ||||
| import org.apache.shiro.authc.DisabledAccountException; | |||||
| import org.apache.shiro.authc.UnknownAccountException; | |||||
| import org.apache.shiro.subject.Subject; | import org.apache.shiro.subject.Subject; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.beans.factory.annotation.Qualifier; | import org.springframework.beans.factory.annotation.Qualifier; | ||||
| @@ -101,9 +103,13 @@ public class WechatLoginController extends BaseController { | |||||
| UseriFormallToken token = new UseriFormallToken(user.getUsername()); | UseriFormallToken token = new UseriFormallToken(user.getUsername()); | ||||
| subject.login(token); | subject.login(token); | ||||
| isLogin = true; | isLogin = true; | ||||
| } catch (MallinkException e) { | |||||
| } catch (UnknownAccountException e) { | |||||
| log.error(e.getMessage()); | log.error(e.getMessage()); | ||||
| ret.put("code", e.getErrorCode()); | |||||
| ret.put("code", ErrorCode.USER_IS_EMPTY.getCode()); | |||||
| ret.put("message", e.getMessage()); | |||||
| } catch (DisabledAccountException e) { | |||||
| log.error(e.getMessage()); | |||||
| ret.put("code", ErrorCode.USER_IS_LOCKED.getCode()); | |||||
| ret.put("message", e.getMessage()); | ret.put("message", e.getMessage()); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| log.error(e.getMessage()); | log.error(e.getMessage()); | ||||
| @@ -240,9 +246,12 @@ public class WechatLoginController extends BaseController { | |||||
| response.addCookie(unameCookie); | response.addCookie(unameCookie); | ||||
| return new ResultData(); | return new ResultData(); | ||||
| } catch (MallinkException e) { | |||||
| } catch (UnknownAccountException e) { | |||||
| log.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(), e.getMessage()); | |||||
| } catch (DisabledAccountException e) { | |||||
| log.error(e.getMessage()); | log.error(e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_LOCKED.getCode(), e.getMessage()); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| log.error(e.getMessage()); | log.error(e.getMessage()); | ||||
| return new ResultData(Result.ERROR, e.getMessage()); | return new ResultData(Result.ERROR, e.getMessage()); | ||||
| @@ -4,10 +4,11 @@ import com.iformall.common.ErrorCode; | |||||
| import com.iformall.domain.po.MallUserInfo; | import com.iformall.domain.po.MallUserInfo; | ||||
| import com.iformall.enums.EnumLoginType; | import com.iformall.enums.EnumLoginType; | ||||
| import com.iformall.enums.EnumMallUserStatus; | import com.iformall.enums.EnumMallUserStatus; | ||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.MallUserInfoService; | import com.iformall.service.MallUserInfoService; | ||||
| import org.apache.shiro.authc.AuthenticationInfo; | import org.apache.shiro.authc.AuthenticationInfo; | ||||
| import org.apache.shiro.authc.AuthenticationToken; | import org.apache.shiro.authc.AuthenticationToken; | ||||
| import org.apache.shiro.authc.DisabledAccountException; | |||||
| import org.apache.shiro.authc.UnknownAccountException; | |||||
| import org.apache.shiro.authc.credential.HashedCredentialsMatcher; | import org.apache.shiro.authc.credential.HashedCredentialsMatcher; | ||||
| import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||
| @@ -27,11 +28,11 @@ public class MyRetryLimitCredentialsMatcher extends HashedCredentialsMatcher { | |||||
| String username = (String)tk.getPrincipal(); | String username = (String)tk.getPrincipal(); | ||||
| MallUserInfo user = userService.getByUsername(username); | MallUserInfo user = userService.getByUsername(username); | ||||
| if(user == null) { | if(user == null) { | ||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||||
| throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
| } | } | ||||
| // 用户被禁用 | // 用户被禁用 | ||||
| if(user.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) { | if(user.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) { | ||||
| throw new MallinkException(ErrorCode.USER_IS_LOCKED); | |||||
| throw new DisabledAccountException(ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| @@ -7,11 +7,7 @@ import com.iformall.enums.EnumMallUserStatus; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.MallUserInfoService; | import com.iformall.service.MallUserInfoService; | ||||
| import org.apache.shiro.SecurityUtils; | import org.apache.shiro.SecurityUtils; | ||||
| import org.apache.shiro.authc.AuthenticationException; | |||||
| import org.apache.shiro.authc.AuthenticationInfo; | |||||
| import org.apache.shiro.authc.AuthenticationToken; | |||||
| import org.apache.shiro.authc.SimpleAuthenticationInfo; | |||||
| import org.apache.shiro.authc.UnknownAccountException; | |||||
| import org.apache.shiro.authc.*; | |||||
| import org.apache.shiro.authz.AuthorizationInfo; | import org.apache.shiro.authz.AuthorizationInfo; | ||||
| import org.apache.shiro.authz.SimpleAuthorizationInfo; | import org.apache.shiro.authz.SimpleAuthorizationInfo; | ||||
| import org.apache.shiro.realm.AuthorizingRealm; | import org.apache.shiro.realm.AuthorizingRealm; | ||||
| @@ -55,11 +51,11 @@ public class MyShiroRealm extends AuthorizingRealm { | |||||
| String username = (String)token.getPrincipal(); | String username = (String)token.getPrincipal(); | ||||
| MallUserInfo user = userService.getByUsername(username); | MallUserInfo user = userService.getByUsername(username); | ||||
| if(user == null) { | if(user == null) { | ||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||||
| throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
| } | } | ||||
| if(user.getStatus()==null || | if(user.getStatus()==null || | ||||
| !EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) {//用户被禁用 | !EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) {//用户被禁用 | ||||
| throw new MallinkException(ErrorCode.USER_IS_LOCKED); | |||||
| throw new DisabledAccountException(ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
| } | } | ||||
| SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( | SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( | ||||
| user, //用户 | user, //用户 | ||||
| @@ -53,9 +53,10 @@ public class MyShiroRealm extends AuthorizingRealm { | |||||
| // if (0==user.getEnable()) { | // if (0==user.getEnable()) { | ||||
| // throw new LockedAccountException(); // 帐号锁定 | // throw new LockedAccountException(); // 帐号锁定 | ||||
| // } | // } | ||||
| //用户被禁用 | |||||
| if(user.getStatus()==null || | if(user.getStatus()==null || | ||||
| !EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) {//用户被禁用 | |||||
| throw new UnknownAccountException("用户被禁用"); | |||||
| !EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) { | |||||
| throw new DisabledAccountException("用户被禁用"); | |||||
| } | } | ||||
| if(!user.getTenantId().equals("1")) { | if(!user.getTenantId().equals("1")) { | ||||
| // 只支持租户为1的用户 | // 只支持租户为1的用户 | ||||