| | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.PageParamMapper; |
| | | import com.whyc.mapper.UserMapper; |
| | | import com.whyc.pojo.PageParam; |
| | | import com.whyc.pojo.PermitGroupUser; |
| | | import com.whyc.pojo.UserClient; |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.MessageUtils; |
| | | import com.whyc.util.RSAUtil; |
| | | import com.whyc.pojo.*; |
| | | import com.whyc.util.*; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.apache.shiro.authc.AuthenticationException; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLDecoder; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | |
| | | |
| | | @Autowired |
| | | private BaoJiGroupUserService baoJiGroupUserService; |
| | | |
| | | @Autowired |
| | | private PageParam2Service pageParam2Service; |
| | | |
| | | public Response login(String userName, String password, HttpServletRequest request) { |
| | | UsernamePasswordToken userToken = new UsernamePasswordToken(userName, password); |
| | |
| | | return new Response<>().set(1,false,"密码错误"); |
| | | } |
| | | public Response login2(String userName, String pwd, HttpServletRequest request) throws UnsupportedEncodingException { |
| | | String password = URLDecoder.decode(pwd, "utf-8"); |
| | | //String password = URLDecoder.decode(pwd, "utf-8"); |
| | | String password = pwd; |
| | | |
| | | String[] dataArr = RSAUtil.decryptFront(password, RSAUtil.fontSeparator); |
| | | //验签md5 |
| | |
| | | return new Response<>().set(1,false,"密码错误"); |
| | | } |
| | | |
| | | public Response loginByRSA(String userName, String pwd,String deliveredCode, HttpServletRequest request) { |
| | | public Response loginByRSA(String userName, String pwd, String deliveredCode, HttpServletRequest request, Integer validCode) { |
| | | Response<Object> response = new Response<>(); |
| | | deliveredCode = deliveredCode.toUpperCase(); |
| | | if(YamlProperties.fontDynamicCodeSwitch.toLowerCase().equals("on")) { |
| | | String fontDynamicCode = (String) ActionUtil.getSession().getAttribute("fontDynamicCode"); |
| | | if (fontDynamicCode == null || "".equals(fontDynamicCode)) { |
| | | return response.set(1, false, MessageUtils.getMessage("RefreshVerification")); |
| | | } |
| | | if (!deliveredCode.equals(fontDynamicCode.toUpperCase())) { |
| | | return response.set(1, false, MessageUtils.getMessage("VerificationError")); |
| | | //默认赋值0 |
| | | response.setData3(0); |
| | | //Locale.setDefault(Locale.ENGLISH); |
| | | deliveredCode = deliveredCode.toUpperCase(Locale.ENGLISH); |
| | | if(validCode ==null ) { //属性不存在,则进行验证码校验;属性存在,则不进行验证码校验 |
| | | if (YamlProperties.fontDynamicCodeSwitch.toLowerCase(Locale.ENGLISH).equals("true")) { |
| | | String fontDynamicCode = (String) ActionUtil.getSession().getAttribute("fontDynamicCode"); |
| | | if (fontDynamicCode == null || "".equals(fontDynamicCode)) { |
| | | return response.set(1, false, MessageUtils.getMessage("RefreshVerification")); |
| | | } |
| | | if (!deliveredCode.equals(fontDynamicCode.toUpperCase(Locale.ENGLISH))) { |
| | | return response.set(1, false, MessageUtils.getMessage("VerificationError")); |
| | | } |
| | | } |
| | | } |
| | | //验证正确,清除验证码 |
| | |
| | | |
| | | ServletContext servletContext = request.getServletContext(); |
| | | Enumeration<String> attributeNames = servletContext.getAttributeNames(); |
| | | |
| | | QueryWrapper<UserInf> queryWrapper = Wrappers.query(); |
| | | queryWrapper.select("uId", "status", "visit_ip", "visit_time", "password_update_time", "last_login_time").eq("uName", userName); |
| | | UserInf userInf = userMapper.selectOne(queryWrapper); |
| | | //每个登录的用户都有一个全局变量,里面存着对应的SessionId; |
| | | //同一个账号,后面登录的,会挤掉之前登录的SessionId,这个todo,做限制账号同时登陆人数为1 |
| | | |
| | | //查询账号状态 |
| | | if(userInf == null){ |
| | | return response.set(1,false,MessageUtils.getMessage("AccountOrPasswordError")); |
| | | } |
| | | if (userInf.getStatus() != 1) { |
| | | switch (userInf.getStatus()) { |
| | | case 0: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_CANCEL.getLabel()); |
| | | break; |
| | | case 2: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_HIBERNATE.getLabel()); |
| | | break; |
| | | case 3: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_LOCK.getLabel()); |
| | | break; |
| | | case 4: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_LOCK_FAIL.getLabel()); |
| | | break; |
| | | default: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + MessageUtils.getMessage("Nothing")); |
| | | } |
| | | return response.set(1, false); |
| | | } |
| | | |
| | | //严格标准下的规则校验 |
| | | if (YamlProperties.systemType == 2) { |
| | | //登录之前,首先校验允许时间和登录ip |
| | | boolean ipPass = true; |
| | | |
| | | String firstTime = userInf.getVisitTime().split("~")[0]; |
| | | String lastTime = userInf.getVisitTime().split("~")[1]; |
| | | |
| | | List<String> ipRules = new LinkedList<>(); |
| | | String ipRuleStr = userInf.getVisitIp(); |
| | | ipRules = Arrays.asList(ipRuleStr.split(",")); |
| | | |
| | | Calendar instance = Calendar.getInstance(); |
| | | String hourOfDay = String.format("%1$02d", instance.get(Calendar.HOUR_OF_DAY)); |
| | | int minute = instance.get(Calendar.MINUTE); |
| | | int second = instance.get(Calendar.SECOND); |
| | | String nowTime = hourOfDay + ":" + minute + ":" + second; |
| | | //登录时间校验 |
| | | if (nowTime.compareTo(firstTime) >= 0 && nowTime.compareTo(lastTime) <= 0) { |
| | | //登录ip校验 |
| | | String clientIp = ActionUtil.getRequest().getRemoteAddr(); |
| | | if (!ipRules.contains("*")) { |
| | | for (String ipRule : ipRules) { |
| | | ipPass = true; |
| | | //ip规则格式为 * 或者 xxx.xxx.x.x |
| | | String[] ipArr = clientIp.split("\\."); |
| | | String[] ipRuleArr = ipRule.split("\\."); |
| | | for (int i = 0; i < ipRuleArr.length; i++) { |
| | | if (!ipRuleArr[i].equals("*") && !ipRuleArr[i].equals(ipArr[i])) { |
| | | ipPass = false; |
| | | break; |
| | | } |
| | | } |
| | | if (ipPass) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (!ipPass) { |
| | | return response.set(1, false, MessageUtils.getMessage("IPProhibition")); |
| | | } |
| | | } else { |
| | | return response.set(1, false, MessageUtils.getMessage("LoginOutOfAllowed")); |
| | | } |
| | | //首次登录,密码修改;超过3个月未修改密码,强制修改密码 |
| | | Date passwordUpdateTime = userInf.getPasswordUpdateTime(); |
| | | Calendar now = Calendar.getInstance(); |
| | | now.add(Calendar.MONTH, -3); |
| | | if (passwordUpdateTime == null) { //密码修改时间为空,尚未修改初始口令 |
| | | /*response.setCode(3); |
| | | response.setData(false); |
| | | response.setMsg(MessageUtils.getMessage("FirstLoginModify")); |
| | | return response;*/ |
| | | response.setData3(2); |
| | | } else if (passwordUpdateTime.compareTo(now.getTime()) < 0) { |
| | | /*response.setCode(2); |
| | | response.setData(false); |
| | | response.setMsg(MessageUtils.getMessage("ThreeMonthModify")); |
| | | return response;*/ |
| | | response.setData3(3); |
| | | } |
| | | } |
| | | |
| | | try { |
| | | subject.login(userToken); |
| | | } catch (Exception e) { |
| | |
| | | PageParam loginFailTimesLimit = pageParamMapper.findByCategoryId(9).get(0); |
| | | if ((++loginFailTimes) == loginFailTimesLimit.getStatus()) { |
| | | //达到限制次数,锁定账号 |
| | | //userService.lock(subject.getUId()); |
| | | userService.lock(userInf.getUId()); |
| | | //清除登录错误次数统计 |
| | | loginFailAttributeList.forEach(servletContext::removeAttribute); |
| | | } else { |
| | | servletContext.setAttribute(userName + "_login_fail_times_" + System.currentTimeMillis(), 0); |
| | | } |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | return response.set(1, false, MessageUtils.getMessage("PasswordError")); |
| | | return response.set(1, false, MessageUtils.getMessage("AccountOrPasswordError")); |
| | | }else if(e instanceof AuthenticationException){ |
| | | return response.set(1, false, "密码解析失败"); |
| | | } |
| | | return response.set(1, false, message); |
| | | } |
| | | |
| | | QueryWrapper<UserInf> queryWrapper = Wrappers.query(); |
| | | queryWrapper.select("uId", "status", "visit_ip", "visit_time", "password_update_time", "last_login_time").eq("uName", userName); |
| | | UserInf userInf = userMapper.selectOne(queryWrapper); |
| | | if (subject.isAuthenticated()) { |
| | | //每个登录的用户都有一个全局变量,里面存着对应的SessionId; |
| | | //同一个账号,后面登录的,会挤掉之前登录的SessionId,这个todo,做限制账号同时登陆人数为1 |
| | | |
| | | //查询账号状态 |
| | | if (userInf.getStatus() != 1) { |
| | | switch (userInf.getStatus()) { |
| | | case 0: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_CANCEL.getLabel()); |
| | | break; |
| | | case 2: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_HIBERNATE.getLabel()); |
| | | break; |
| | | case 3: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_LOCK.getLabel()); |
| | | break; |
| | | case 4: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_LOCK_FAIL.getLabel()); |
| | | break; |
| | | default: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + MessageUtils.getMessage("Nothing")); |
| | | } |
| | | return response.set(1, false); |
| | | //验证密码时效性 |
| | | int flag=userService.checkPasswordValidity(userInf); |
| | | if(flag==-1){ |
| | | return response.set(1, false, "密码长期未修改已失效,请修改密码"); |
| | | } |
| | | |
| | | //严格标准下的规则校验 |
| | | if (YamlProperties.systemType == 2) { |
| | | //登录之前,首先校验允许时间和登录ip |
| | | boolean ipPass = true; |
| | | |
| | | String firstTime = userInf.getVisitTime().split("~")[0]; |
| | | String lastTime = userInf.getVisitTime().split("~")[1]; |
| | | |
| | | List<String> ipRules = new LinkedList<>(); |
| | | String ipRuleStr = userInf.getVisitIp(); |
| | | ipRules = Arrays.asList(ipRuleStr.split(",")); |
| | | |
| | | Calendar instance = Calendar.getInstance(); |
| | | String hourOfDay = String.format("%1$02d", instance.get(Calendar.HOUR_OF_DAY)); |
| | | int minute = instance.get(Calendar.MINUTE); |
| | | int second = instance.get(Calendar.SECOND); |
| | | String nowTime = hourOfDay + ":" + minute + ":" + second; |
| | | //登录时间校验 |
| | | if (nowTime.compareTo(firstTime) >= 0 && nowTime.compareTo(lastTime) <= 0) { |
| | | //登录ip校验 |
| | | String clientIp = ActionUtil.getRequest().getRemoteAddr(); |
| | | if (!ipRules.contains("*")) { |
| | | for (String ipRule : ipRules) { |
| | | ipPass = true; |
| | | //ip规则格式为 * 或者 xxx.xxx.x.x |
| | | String[] ipArr = clientIp.split("\\."); |
| | | String[] ipRuleArr = ipRule.split("\\."); |
| | | for (int i = 0; i < ipRuleArr.length; i++) { |
| | | if (!ipRuleArr[i].equals("*") && !ipRuleArr[i].equals(ipArr[i])) { |
| | | ipPass = false; |
| | | break; |
| | | } |
| | | } |
| | | if (ipPass) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (!ipPass) { |
| | | return response.set(1, false, MessageUtils.getMessage("IPProhibition")); |
| | | } |
| | | } else { |
| | | return response.set(1, false, MessageUtils.getMessage("LoginOutOfAllowed")); |
| | | } |
| | | //首次登录,密码修改;超过3个月未修改密码,强制修改密码 |
| | | Date passwordUpdateTime = userInf.getPasswordUpdateTime(); |
| | | Calendar now = Calendar.getInstance(); |
| | | now.add(Calendar.MONTH, -3); |
| | | if (passwordUpdateTime == null) { //密码修改时间为空,尚未修改初始口令 |
| | | response.setCode(3); |
| | | response.setData(false); |
| | | response.setMsg(MessageUtils.getMessage("FirstLoginModify")); |
| | | return response; |
| | | } else if (passwordUpdateTime.compareTo(now.getTime()) < 0) { |
| | | response.setCode(2); |
| | | response.setData(false); |
| | | response.setMsg(MessageUtils.getMessage("ThreeMonthModify")); |
| | | return response; |
| | | } |
| | | } |
| | | |
| | | //登录成功 |
| | | servletContext.setAttribute(userName, request.getSession().getId()); |
| | | //日登录用户统计 |
| | | HashMap<String, String> loginMap = (HashMap<String, String>) servletContext.getAttribute("login"); |
| | | if(loginMap == null){ |
| | | loginMap = new HashMap<>(); |
| | | servletContext.setAttribute("login", loginMap); |
| | | } |
| | | String dateStr = DateUtil.YYYY_MM_DD.format(new Date()); |
| | | loginMap.put(userName, dateStr); |
| | | //累计访问人次 |
| | | pageParam2Service.updateVisitCount(); |
| | | //Session存储当前用户及权限组列表 |
| | | request.getSession().setAttribute("user", subject.getPrincipal()); |
| | | request.getSession().setMaxInactiveInterval(60*60*24); |
| | |
| | | dataList.add(subject.getPrincipal()); |
| | | PermitGroupUser permitGroup = permitGroupUserService.getPermitGroup(userInf.getUId()); |
| | | if(permitGroup == null){ |
| | | return new Response().set(1, false, MessageUtils.getMessage("userNoPermitGroup")); |
| | | return response.set(1, false, MessageUtils.getMessage("userNoPermitGroup")); |
| | | }else { |
| | | int permitGroupId = permitGroup.getPermitGroupId(); |
| | | dataList.add(permitGroupId); |
| | |
| | | String mapName = mapOutlineService.selectMapName(); |
| | | dataList.add(mapName); |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | return new Response<>().setII(1, true, dataList, MessageUtils.getMessage("LoginSucceeded")); |
| | | return response.setII(1, true, dataList, MessageUtils.getMessage("LoginSucceeded")); |
| | | } |
| | | return new Response().set(1, false, MessageUtils.getMessage("AuthenticationFailed")); |
| | | return response.set(1, false, MessageUtils.getMessage("AuthenticationFailed")); |
| | | } |
| | | |
| | | // 将所有登陆的用户的信息存到application中 |
| | |
| | | //内存 |
| | | ServletContext servletContext = request.getServletContext(); |
| | | Enumeration<String> attributeNames = servletContext.getAttributeNames(); |
| | | |
| | | QueryWrapper<UserInf> queryWrapper = Wrappers.query(); |
| | | queryWrapper.select("uId", "status", "visit_ip", "visit_time", "password_update_time", "last_login_time").eq("uName", userName); |
| | | UserInf userInf = userMapper.selectOne(queryWrapper); |
| | | |
| | | //每个登录的用户都有一个全局变量,里面存着对应的SessionId; |
| | | //同一个账号,后面登录的,会挤掉之前登录的SessionId,这个todo,做限制账号同时登陆人数为1 |
| | | |
| | | //查询账号状态 |
| | | if(userInf == null){ |
| | | return response.set(1,false,MessageUtils.getMessage("AccountOrPasswordError")); |
| | | } |
| | | if (userInf.getStatus() != 1) { |
| | | switch (userInf.getStatus()) { |
| | | case 0: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_CANCEL.getLabel()); |
| | | break; |
| | | case 2: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_HIBERNATE.getLabel()); |
| | | break; |
| | | case 3: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_LOCK.getLabel()); |
| | | break; |
| | | case 4: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_LOCK_FAIL.getLabel()); |
| | | break; |
| | | default: |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + MessageUtils.getMessage("Nothing")); |
| | | } |
| | | return response.set(1, false); |
| | | } |
| | | |
| | | //严格标准下的规则校验 |
| | | if (YamlProperties.systemType == 2) { |
| | | //登录之前,首先校验允许时间和登录ip |
| | | boolean ipPass = true; |
| | | |
| | | String firstTime = userInf.getVisitTime().split("~")[0]; |
| | | String lastTime = userInf.getVisitTime().split("~")[1]; |
| | | |
| | | List<String> ipRules = new LinkedList<>(); |
| | | String ipRuleStr = userInf.getVisitIp(); |
| | | ipRules = Arrays.asList(ipRuleStr.split(",")); |
| | | |
| | | Calendar instance = Calendar.getInstance(); |
| | | String hourOfDay = String.format("%1$02d", instance.get(Calendar.HOUR_OF_DAY)); |
| | | int minute = instance.get(Calendar.MINUTE); |
| | | int second = instance.get(Calendar.SECOND); |
| | | String nowTime = hourOfDay + ":" + minute + ":" + second; |
| | | //登录时间校验 |
| | | if (nowTime.compareTo(firstTime) >= 0 && nowTime.compareTo(lastTime) <= 0) { |
| | | //登录ip校验 |
| | | String clientIp = ActionUtil.getRequest().getRemoteAddr(); |
| | | if (!ipRules.contains("*")) { |
| | | for (String ipRule : ipRules) { |
| | | ipPass = true; |
| | | //ip规则格式为 * 或者 xxx.xxx.x.x |
| | | String[] ipArr = clientIp.split("\\."); |
| | | String[] ipRuleArr = ipRule.split("\\."); |
| | | for (int i = 0; i < ipRuleArr.length; i++) { |
| | | if (!ipRuleArr[i].equals("*") && !ipRuleArr[i].equals(ipArr[i])) { |
| | | ipPass = false; |
| | | break; |
| | | } |
| | | } |
| | | if (ipPass) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (!ipPass) { |
| | | return response.set(1, false, MessageUtils.getMessage("IPProhibition")); |
| | | } |
| | | } else { |
| | | return response.set(1, false, MessageUtils.getMessage("LoginOutOfAllowed")); |
| | | } |
| | | //首次登录,密码修改;超过3个月未修改密码,强制修改密码 |
| | | Date passwordUpdateTime = userInf.getPasswordUpdateTime(); |
| | | Calendar now = Calendar.getInstance(); |
| | | now.add(Calendar.MONTH, -3); |
| | | if (passwordUpdateTime == null) { //密码修改时间为空,尚未修改初始口令 |
| | | response.setCode(3); |
| | | response.setData(false); |
| | | response.setMsg(MessageUtils.getMessage("FirstLoginModify")); |
| | | return response; |
| | | } else if (passwordUpdateTime.compareTo(now.getTime()) < 0) { |
| | | response.setCode(2); |
| | | response.setData(false); |
| | | response.setMsg(MessageUtils.getMessage("ThreeMonthModify")); |
| | | return response; |
| | | } |
| | | } |
| | | try { |
| | | subject.login(userToken); |
| | | }catch (Exception e){ |
| | |
| | | PageParam loginFailTimesLimit = pageParamMapper.findByCategoryId(9).get(0); |
| | | if ((++loginFailTimes) == loginFailTimesLimit.getStatus()) { |
| | | //达到限制次数,锁定账号 |
| | | //userService.lock(subject.getUId()); |
| | | userService.lock(userInf.getUId()); |
| | | //清除登录错误次数统计 |
| | | loginFailAttributeList.forEach(servletContext::removeAttribute); |
| | | } else { |
| | |
| | | return new Response<>().set(1,false,"uKey验证不通过"); |
| | | } |
| | | |
| | | QueryWrapper<UserInf> queryWrapper = Wrappers.query(); |
| | | queryWrapper.select("uId", "status", "visit_ip", "visit_time", "password_update_time", "last_login_time").eq("uName", userName); |
| | | UserInf userInf = userMapper.selectOne(queryWrapper); |
| | | //每个登录的用户都有一个全局变量,里面存着对应的SessionId; |
| | | //同一个账号,后面登录的,会挤掉之前登录的SessionId,这个todo,做限制账号同时登陆人数为1 |
| | | |
| | | //查询账号状态 |
| | | if (userInf.getStatus() != 1) { |
| | | switch (userInf.getStatus()) { |
| | | case 0: |
| | | response.setMsg("当前账号的状态异常,无法登录. 异常信息为: " + UserConstant.ACCOUNT_STATUS_CANCEL.getLabel()); |
| | | break; |
| | | case 2: |
| | | response.setMsg("当前账号的状态异常,无法登录. 异常信息为: " + UserConstant.ACCOUNT_STATUS_HIBERNATE.getLabel()); |
| | | break; |
| | | case 3: |
| | | response.setMsg("当前账号的状态异常,无法登录. 异常信息为: " + UserConstant.ACCOUNT_STATUS_LOCK.getLabel()); |
| | | break; |
| | | case 4: |
| | | response.setMsg("当前账号的状态异常,无法登录. 异常信息为: " + UserConstant.ACCOUNT_STATUS_LOCK_FAIL.getLabel()); |
| | | break; |
| | | default: |
| | | response.setMsg("当前账号的状态异常,无法登录. 异常信息为: 无"); |
| | | } |
| | | return response.set(1, false); |
| | | } |
| | | |
| | | //严格标准下的规则校验 |
| | | if (YamlProperties.systemType == 2) { |
| | | //登录之前,首先校验允许时间和登录ip |
| | | boolean ipPass = true; |
| | | |
| | | String firstTime = userInf.getVisitTime().split("~")[0]; |
| | | String lastTime = userInf.getVisitTime().split("~")[1]; |
| | | |
| | | List<String> ipRules = new LinkedList<>(); |
| | | String ipRuleStr = userInf.getVisitIp(); |
| | | ipRules = Arrays.asList(ipRuleStr.split(",")); |
| | | |
| | | Calendar instance = Calendar.getInstance(); |
| | | String hourOfDay = String.format("%1$02d", instance.get(Calendar.HOUR_OF_DAY)); |
| | | int minute = instance.get(Calendar.MINUTE); |
| | | int second = instance.get(Calendar.SECOND); |
| | | String nowTime = hourOfDay + ":" + minute + ":" + second; |
| | | //登录时间校验 |
| | | if (nowTime.compareTo(firstTime) >= 0 && nowTime.compareTo(lastTime) <= 0) { |
| | | //登录ip校验 |
| | | String clientIp = ActionUtil.getRequest().getRemoteAddr(); |
| | | if (!ipRules.contains("*")) { |
| | | for (String ipRule : ipRules) { |
| | | ipPass = true; |
| | | //ip规则格式为 * 或者 xxx.xxx.x.x |
| | | String[] ipArr = clientIp.split("\\."); |
| | | String[] ipRuleArr = ipRule.split("\\."); |
| | | for (int i = 0; i < ipRuleArr.length; i++) { |
| | | if (!ipRuleArr[i].equals("*") && !ipRuleArr[i].equals(ipArr[i])) { |
| | | ipPass = false; |
| | | break; |
| | | } |
| | | } |
| | | if (ipPass) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (!ipPass) { |
| | | return response.set(1, false, "您的IP禁止访问,请知晓"); |
| | | } |
| | | } else { |
| | | return response.set(1, false, "登录时间不在允许的时间范围内"); |
| | | } |
| | | //首次登录,密码修改;超过3个月未修改密码,强制修改密码 |
| | | Date passwordUpdateTime = userInf.getPasswordUpdateTime(); |
| | | Calendar now = Calendar.getInstance(); |
| | | now.add(Calendar.MONTH, -3); |
| | | if (passwordUpdateTime == null) { //密码修改时间为空,尚未修改初始口令 |
| | | response.setCode(3); |
| | | response.setData(false); |
| | | response.setMsg("首次登录,请先修改初始化口令"); |
| | | return response; |
| | | } else if (passwordUpdateTime.compareTo(now.getTime()) < 0) { |
| | | response.setCode(2); |
| | | response.setData(false); |
| | | response.setMsg("超过3个月没有修改口令,请修改口令后重新登录"); |
| | | return response; |
| | | } |
| | | } |
| | | |
| | | //登录成功 |
| | | servletContext.setAttribute(userName, request.getSession().getId()); |
| | | //日登录用户统计 |
| | | HashMap<String, String> loginMap = (HashMap<String, String>) servletContext.getAttribute("login"); |
| | | if(loginMap == null){ |
| | | loginMap = new HashMap<>(); |
| | | servletContext.setAttribute("login", loginMap); |
| | | } |
| | | String dateStr = DateUtil.YYYY_MM_DD.format(new Date()); |
| | | loginMap.put(userName, dateStr); |
| | | //累计访问人次 |
| | | pageParam2Service.updateVisitCount(); |
| | | //Session存储当前用户及权限组列表 |
| | | request.getSession().setAttribute("user", subject.getPrincipal()); |
| | | request.getSession().setAttribute("permits", ActionUtil.getGson().toJson(permitGroupUserService.getItemList(userInf.getUId()))); |
| | |
| | | if (user != null && login_time != null) { |
| | | UserClient client = map.get(user.getUName()); |
| | | if (client != null) { |
| | | if (login_time != client.getLogin_times()) { |
| | | if (!login_time.equals(client.getLogin_times())) { |
| | | model.setCode(1); |
| | | //model.setMsg(getText("The landing on the account in another host, please log in again")); |
| | | model.setMsg("The landing on the account in another host, please log in again"); |
| | |
| | | UserInf user = (UserInf) httpSession.getAttribute("user"); |
| | | //System.out.println("webSocket:"+user); |
| | | if(user!=null){ |
| | | String sessionId = (String) httpSession.getServletContext().getAttribute(user.getUName()); |
| | | ServletContext servletContext = httpSession.getServletContext(); |
| | | String sessionId = (String) servletContext.getAttribute(user.getUName()); |
| | | if(httpSession.getId().equals(sessionId)){ |
| | | //用户在线状态校验成功,更新当前用户的在线时间 |
| | | HashMap<String, Long> onlineMap = (HashMap<String, Long>) servletContext.getAttribute("online"); |
| | | if(onlineMap == null){ |
| | | onlineMap = new HashMap<>(); |
| | | servletContext.setAttribute("online", onlineMap); |
| | | } |
| | | onlineMap.put(user.getUName(), System.currentTimeMillis()); |
| | | model.set(1,user,null); |
| | | }else{ |
| | | model.set(1,false,"不同主机登录"); |