Shiro的SimpleAuthenticationInfo的principal赋值问题

doGetAuthenticationInfo 在 return 时 SimpleAuthenticationInfo 的赋值

 return new SimpleAuthenticationInfo(user.getStr("username"), user.getStr("password"), getName());

验证可以通过,当改为

 return new SimpleAuthenticationInfo(new ShiroUser(user), user.getStr("password"), getName());

抛出异常

Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException).

不知是哪里错了。

ShiroUser.java

 package com.xxx.shiro;

import java.io.Serializable;

import com.xxx.model.HrmResource;

public class ShiroUser implements Serializable {

    private static final long serialVersionUID = -9204685886813793596L;

    private Long id;
    private String username;
    private String lastname;
    private Integer status;

    public ShiroUser() {
    }

    public ShiroUser(HrmResource hrm) {
        this.setId(hrm.getLong("id"));
        this.setLastname(hrm.getStr("lastname"));
        this.setUsername(hrm.getStr("loginid"));
        this.setStatus(hrm.getInt("status"));
    }

    public String toString() {
        return getUsername();
    }

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ShiroUser other = (ShiroUser) obj;
        if (this.username == null) {
            if (other.username != null)
                return false;
        } else if (!this.username.equals(other.username))
            return false;
        return true;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问