jeesite新增登陆验证

需求

最近使用jeesite做项目,项目要求在登陆这块要求不用系统的验证规则,二十使用用户的验证规则,那就意味着jeesite的验证都不需要了,直接走用户的就好,但是jeesite的用户获取user权限会去查数据库,然后生成user权限,我对这块不熟,没办法,我只能给自己数据库中导入一份用户数据,然后密码统一,在通过客户这边的校验后,再走我的验证。这样就符合客户的需求页符合系统的需要。具体操作如下

大体步骤

其实在我这个思路下方法较简单,改动很小。只要找到类文件
/jeesite/src/main/java/com/thinkgem/jeesite/modules/sys/security/SystemAuthorizingRealm.java

protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) {
		UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
		
		int activeSessionSize = getSystemService().getSessionDao().getActiveSessions(false).size();
		if (logger.isDebugEnabled()){
			logger.debug("login submit, active session size: {}, username: {}", activeSessionSize, token.getUsername());
		}
		
		// 校验登录验证码
		if (LoginController.isValidateCodeLogin(token.getUsername(), false, false)){
			Session session = UserUtils.getSession();
			String code = (String)session.getAttribute(ValidateCodeServlet.VALIDATE_CODE);
			if (token.getCaptcha() == null || !token.getCaptcha().toUpperCase().equals(code)){
				throw new AuthenticationException("msg:验证码错误, 请重试.");
			}
		}
		/***
		 *--->在这里增加上你要的验证然后设置同意密码就好
		*/
		// 校验用户名密码
		//也就是这样
		if(客户规则=true){
		   String pwd = "admin";//你导入的用户数据的统一密码,不过密码要经过系统转换并且不同时间段生成密码不同
		   //这样既能通过用户的验证,也能通过你自己验证,不然就只能去删除系统内的密码校验,
		   //不过我实在太菜发现删了后我不能调整正确,只能使用这种取巧的方法
		   token.setPassword(pwd.toCharArray());
			User user = getSystemService().getUserByLoginName(token.getUsername());
			if (user != null) {
				if (Global.NO.equals(user.getLoginFlag())){
					throw new AuthenticationException("msg:该已帐号禁止登录.");
				}
				byte[] salt = Encodes.decodeHex(user.getPassword().substring(0,16));
				return new SimpleAuthenticationInfo(new Principal(user, token.isMobileLogin()), 
						user.getPassword().substring(16), ByteSource.Util.bytes(salt), getName());
			} else {
				return null;
			}
		}
		
	}

猜你喜欢

转载自blog.csdn.net/qq_36963177/article/details/82907183