shiro自定义Realm时发生异常

错误1:org.apache.shiro.authc.AuthenticationException: Authentication failed for token submission [cn.itsource.crm.shiro.util.CrmToken - 061HqmnI0EJ1lg28fwmI0jFrnI0Hqmnt, rememberMe=false]. Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException).

错误提示我们,自定义的异常应该继承AuthenticationException,而我们继承的是:

public class WechatBindingException extends RuntimeException {

}

修改为如下所示后,错误解决

public class WechatBindingException extends AuthenticationException {

}

错误2:org.apache.shiro.authc.AuthenticationException: Authentication token of type [class cn.itsource.crm.shiro.util.CrmToken] could not be authenticated by any configured realms. Please ensure that at least one realm can authenticate these tokens.

由错误可知,提示自定义token有问题,在自定义认证器中断点测试后发现,原来是配置文件中强行给Realm取了名字:

shiro自定义Realm时发生异常_第1张图片

而在LoginType中:

shiro自定义Realm时发生异常_第2张图片

所以在自定义认证器中比较时,添加不进matchRealms,导致进入不了doSingleRealmAuthentication方法,所以验证失败:

shiro自定义Realm时发生异常_第3张图片

你可能感兴趣的:(shiro自定义Realm时发生异常)