shiro管理多登录入口配置,手机端登录与网页端登录

shiro管理多登录入口配置,手机端登录与网页端登录

1、2个Realm:分别为手机端、网页端的

/**
 * 自定义MobileRealm .
 */
public class MobileRealm extends AuthorizingRealm {
	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {	
		return null;
	}
	@Override
	// 验证的核心方法
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
		String userCode = (String) token.getPrincipal();
		UsernamePasswordToken usernamePassword = (UsernamePasswordToken) token;
		char[] passWord = usernamePassword.getPassword();
		if (StringUtil.isEmpty(userCode)) {
			throw new UserNameNullException();// 账号为空
		}
		if (StringUtil.isEmpty(passWord)) {
			throw new PassWordNullException();// 密码为空
		}
		// 根据登录名查询操作员
		Admin operator = null;
		try {
			operator = adminService.getAdminUserByUserCode(userCode);
		} catch (Exception e) {
			e.printStackTrace();
		}

		if (operator == null) {
			throw new UnknownAccountException();// 没找到帐号
		}

		if (!Constants.UserLockStatus.UNLOCK.equals(operator.getLock_status())) {
			throw new LockedAccountException(); // 账号锁定或者不是生效状态
		}
		if (!Constants.UserStatus.OPEN.equals(operator.getUser_status())) {
			throw new LockedAccountException(); // 账号锁定或者不是生效状态
		}
		// 交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配
		SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(operator.getUser_name(), // 登录名
				operator.getUser_pswd(), // 密码
				getName() // realm name
		);
		return authenticationInfo;
	}
	@Override
	public void clearCachedAuthorizationInfo(PrincipalCollection principals) {
		super.clearCachedAuthorizationInfo(principals);
	}
	@Override
	public void clearCachedAuthenticationInfo(PrincipalCollection principals) {
		super.clearCachedAuthenticationInfo(principals);
	}
	@Override
	public void clearCache(PrincipalCollection principals) {
		super.clearCache(principals);
	}
	public void clearAllCachedAuthorizationInfo() {
		getAuthorizationCache().clear();
	}
	public void clearAllCachedAuthenticationInfo() {
		getAuthenticationCache().clear();
	}
	public void clearAllCache() {
		clearAllCachedAuthenticationInfo();
		clearAllCachedAuthorizationInfo();
	}
}
/**
 * 自定义realm .
 *
 */
public class WebRealm extends AuthorizingRealm {

	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
		return null;
	}
	@Override
	// 验证的核心方法
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
		String userCode = (String) token.getPrincipal();
		UsernamePasswordToken usernamePassword = (UsernamePasswordToken) token;
		char[] passWord = usernamePassword.getPassword();
		if (StringUtil.isEmpty(userCode)) {
			throw new UserNameNullException();// 账号为空
		}
		if (StringUtil.isEmpty(passWord)) {
			throw new PassWordNullException();// 密码为空
		}
		// 根据登录名查询操作员
		Admin operator = null;
		try {
			operator = adminService.getAdminUserByUserCode(userCode);
		} catch (Exception e) {
			e.printStackTrace();
		}

		if (operator == null) {
			throw new UnknownAccountException();// 没找到帐号
		}

		if (!Constants.UserLoc
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值