【问题标题】:getting exception Authentication failed for token submission in apache shiro在 apache shiro 中获取令牌提交的异常身份验证失败
【发布时间】:2013-11-08 09:17:46
【问题描述】:

我是 apache shiro 的新手。执行此语句时出现异常。

currentUser.login(token);

例外是

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

我正在调用此方法进行登录。代码是。

  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;
}

我的 shiro.ini 文件

 [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]

我在我的 web.xml 文件中包含监听器和过滤器。 我将 authenticationQuery 更改为我的查询。当我执行时,我收到了上述错误。而且我也知道修改或覆盖查询是否正确。

【问题讨论】:

  • 我只想实现用户登录。我想跳过滚动和权限查询..这可能吗?
  • 是的,这是可能的..
  • hi.any body 有一个想法,如果用户登录成功,那么我需要返回其他信息。怎么办?
  • 看看line 338 of this code 来自Stormpath。请注意,在用户成功通过身份验证后,PrincipalCollection 包含有关用户的所有信息将添加到 SimpleAuthenticationInfo。然后,您可以通过这种方式检索用户信息:Map<String, Object> userInfo = SecurityUtils.getSubject().getPrincipals().oneByType(java.util.Map.class);

标签: java shiro


【解决方案1】:

我认为问题在于您的shiro.ini 中缺少securityManager.realm = $jdbcRealm

【讨论】:

    【解决方案2】:

    我刚遇到这个异常,问题是我在shiro.ini 中错误地设置了securityManager.realm。这就是我所拥有的:

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

    这就是修复它的原因(我错过了$):

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

    【讨论】:

      猜你喜欢
      • 2021-04-13
      • 2015-05-17
      • 1970-01-01
      • 2020-06-23
      • 2018-07-23
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多