The problem

Encountered in learning to Shiro, Shiro thrown org.. Apache Shiro. Authc. AuthenticationException abnormalities, abnormal complete is as follows:

org.apache.shiro.authc.AuthenticationException: Authentication failed for token submission [org.apache.shiro.authc.UsernamePasswordToken - xue8, rememberMe=false].  Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException).
Copy the code

The cause of this exception was an authentication error, but I thought there was nothing wrong with the Realm I wrote. After a bit of messing around and looking through some of Shiro’s source code, I finally realized the cause of this problem and wanted to document the process.

To solve

I added a breakpoint to Realm’s id authentication method doGetAuthenticationInfo for debugging

authenticationToken
password
getCredentials()
The user name
getPrincipal()
authenticationToken

doGetAuthenticationInfo
doGetAuthenticationInfo

subject.login(token)

doGetAuthenticationInfo
UsernamePasswordToken

UsernamePasswordToken
Realm
doGetAuthenticationInfo
AuthenticationToken authenticationToken

Can solve the problem.

Original address: ddnd.cn/2019/02/01/…