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