*First Project Realm (The one that Works) *
package gr.histopath.platform.lib;

import gr.histopath.platform.model.DAO.UserDAO;
import gr.histopath.platform.model.TransferObjects.User;
import org.apache.shiro.authc.*;
import org.apache.shiro.codec.Base64;
import org.apache.shiro.realm.jdbc.JdbcRealm;
import org.apache.shiro.util.ByteSource;

public class  MyRealm extends JdbcRealm {

    private UserDAO userDAO;
    private User user;
    private String password;
    private ByteSource salt;


    public MyRealm() {
        this.userDAO = new UserDAO();
        setSaltStyle(SaltStyle.COLUMN);
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken
token) throws AuthenticationException {
        // identify account to log to
        UsernamePasswordToken userPassToken = (UsernamePasswordToken) token;
        String username = userPassToken.getUsername();

        if (username.equals(null)) {
            System.out.println("Username is null.");
            return null;
        }

        // read password hash and salt from db
        System.out.println("Username: " + username);
        this.user = userDAO.getByUsername(username);
        this.userDAO.closeEntityManager();
        System.out.println("user's email: " + this.user.getUsername());

        if (this.user == null) {
            System.out.println("No account found for user [" + username +
"]");
            return null;
        }
        this.password = this.user.getPassword();
        this.salt =
ByteSource.Util.bytes(Base64.decode(this.user.getSalt()));

        SaltedAuthenticationInfo info = new SimpleAuthenticationInfo(user,
password, salt, getName());
//        SimpleAccount simpleAccount = new SimpleAccount(this.user,
this.password, this.salt, getName());

        return info;
//        return simpleAccount;
    }

}


*The Second MyRealm (the one that fails)*

package gr.gourvas.platform.lib;

import gr.gourvas.platform.model.DAO.UserDAO;
import gr.gourvas.platform.model.TransferObjects.User;
import org.apache.shiro.authc.*;
import org.apache.shiro.codec.Base64;
import org.apache.shiro.realm.jdbc.JdbcRealm;
import org.apache.shiro.util.ByteSource;

public class MyRealm extends JdbcRealm {

    private UserDAO userDAO;
    private User user;
    private String password;
    private ByteSource salt;


    public MyRealm() {
        this.userDAO = new UserDAO();
        setSaltStyle(SaltStyle.COLUMN);
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken
token) throws AuthenticationException {
        // identify account to log to
        UsernamePasswordToken userPassToken = (UsernamePasswordToken) token;
        String username = userPassToken.getUsername();

        if (username.equals(null)) {
            System.out.println("Username is null.");
            return null;
        }

        // read password hash and salt from db
        System.out.println("Username: " + username);
        this.user = userDAO.getByUsername(username);
        this.userDAO.closeEntityManager();
        System.out.println("user's email: " + this.user.getUsername());

        if (this.user == null) {
            System.out.println("No account found for user [" + username +
"]");
            return null;
        }
        this.password = this.user.getPassword();
        this.salt =
ByteSource.Util.bytes(Base64.decode(this.user.getSalt()));

        SaltedAuthenticationInfo info = new
SimpleAuthenticationInfo(this.user, this.password, this.salt, getName());
//        SimpleAccount simpleAccount = new SimpleAccount(this.user,
this.password, this.salt, getName());

        return info;
//        return simpleAccount;
    }

}




They are identical. 



--
Sent from: http://shiro-user.582556.n2.nabble.com/

Reply via email to