You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by salihrkc <sa...@live.com> on 2014/01/25 14:19:24 UTC

Can't login using Shiro with PasswordService

I am using Shiro 1.2.2 for security. I am trying to use PasswordService but i
can't login. It gives the following error.    

> org.apache.shiro.authc.IncorrectCredentialsException: Submitted
> credentials for token [org.apache.shiro.authc.UsernamePasswordToken -
> myUserName, rememberMe=false] did not match the expected credentials.


Here is how users are saved to the database.

    public void doRegister() throws SQLException{
        PasswordService dps = new DefaultPasswordService();
        System.out.println("Test succesful");
         con = ds.getConnection();
         PreparedStatement ps = con.prepareStatement("insert into
user(username, password, email, fullname) values (?, ?, ?, ?)");
         ps.setString(1, userName);
         ps.setString(2, dps.encryptPassword(password));
         ps.setString(3, emailAddress);
         ps.setString(4, "Test Test");
         ps.executeUpdate();        
    }

Here is how users login

    public void doLogin() {
        try {
            SecurityUtils.getSubject().login(new
UsernamePasswordToken(username, password));
        } catch (AccountException uae) {
            uae.printStackTrace();
        }

    }

Here is shiro.ini


    [main]
    shiro.loginUrl = /login.xhtml
    user.loginUrl = /login.xhtml
    
    passwordService =
org.apache.shiro.authc.credential.DefaultPasswordService
    passwordMatcher =
org.apache.shiro.authc.credential.TempFixPasswordMatcher
    passwordMatcher.passwordService = $passwordService
    
    jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
    jdbcRealm.credentialsMatcher = $passwordMatcher
    
    
    
    ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    ds.serverName = 95.85.13.105
    ds.user = myDBUser
    ds.password = myPassword
    ds.databaseName = myDBName
    jdbcRealm.dataSource= $ds
    
    jdbcRealm.authenticationQuery = SELECT password from user where username
= ?
    jdbcRealm.userRolesQuery = select role from userroles where userID =
(select id FROM user WHERE username = ?)
    
    securityManager.realm = $jdbcRealm
    
    
    [users]
    
    [roles]
    # format: roleName = permission1, permission2, ..., permissionN
    admin = *
    schwartz = lightsaber:*
    goodguy = winnebago:drive:eagle5
    
    [urls]
    /login.xhtml = authc
    /logout = logout
    /account/** = authc
    /remoting/** = authc, roles[b2bClient], perms["remote:invoke:lan,wan"]



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Can-t-login-using-Shiro-with-PasswordService-tp7579550.html
Sent from the Shiro User mailing list archive at Nabble.com.