zadada 2015-09-10 00:58
浏览 7139

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;
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料