package com.izouma.awesomeadmin.shiro;

import com.izouma.awesomeadmin.model.UserInfo;
import org.apache.shiro.authc.*;

public class UserPasswordRealm extends BaseRealm {

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        UserInfo userInfo = null;
        UsernamePasswordToken userToken = (UsernamePasswordToken) token;
        userInfo = userInfoService.login(userToken.getUsername(), new String(userToken.getPassword()));
        if (userInfo == null) {
            throw new AuthenticationException("用户名或密码错误");
        }
        return new SimpleAuthenticationInfo(userInfo, token.getCredentials(), this.getName());
    }
}
