'getting exception Authentication failed for token submission in apache shiro

i am new in apache shiro.i am getting exception when i execute this statement.

currentUser.login(token);

exception is

 errororg.apache.shiro.authc.AuthenticationException: Authentication failed for token submission [org.apache.shiro.authc.UsernamePasswordToken - [email protected], rememberMe=true].  Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException).

i am invoking this method for login.the code is.

  public boolean authorize(String username,String password)
{
    Boolean status=false;
    log.debug("the user id "+username+"passwrodD::"+password);
    Realm realm = new JdbcRealm();
    DefaultSecurityManager securityManager = new DefaultSecurityManager(realm);
    UsernamePasswordToken token = new UsernamePasswordToken(username, password);
    token.setRememberMe(true);
    SecurityUtils.setSecurityManager(securityManager);
    Subject currentUser = SecurityUtils.getSubject();

    Response r = null;
    log.debug("before process for login");
    try
    {
        currentUser.login(token);   //This throws an error upon form submission

        r = Response.ok().entity(token).build();            

    }
    catch (UnknownAccountException uae ) {
        //username wasn't in the system, show them an error message?
        System.out.println("the user name is invalid");
    } catch ( IncorrectCredentialsException ice ) {
        //password didn't match, try again?
        System.out.println("the password name is invalid");
    } catch ( LockedAccountException lae ) {
        //account for that username is locked - can't login.  Show them a message?

    } catch ( AuthenticationException ae ) {
        //unexpected condition - error?
        System.out.println("unexpect error"+ae);
    }
    return status;
}

my shiro.ini file

 [main]
 jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
 jdbcRealm.permissionsLookupEnabled = true
 jdbcRealm.authenticationQuery =select User_Password FROM  user_master where User_id=?
 ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
 ds.serverName = localhost
 ds.user = root
 ds.password = root
 ds.databaseName = test
 jdbcRealm.dataSource = $ds
 [users]
 [roles]
 [urls]

i include listener and filter in my web.xml file. i change the authenticationQuery to my query. and when i am executing i am getting this above error. and also i do know is it right way to modify or override query.



Solution 1:[1]

I think the problem is that you are missing securityManager.realm = $jdbcRealm in your shiro.ini

Solution 2:[2]

I just got this exception, and the problem was I was setting securityManager.realm incorrectly in shiro.ini. This is what I had:

[main]
fooRealm = com.company.foo.Realm
securityManager.realms = fooRealm

This is what fixed it (I was missing a $):

[main]
fooRealm = com.company.foo.Realm
securityManager.realms = $fooRealm

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mario
Solution 2 Abe Voelker