package com.izouma.awesomeadmin.shiro;

import com.izouma.awesomeadmin.model.UserInfo;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;

public class AppTokenRealm extends BaseRealm {
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        UserInfo userInfo = null;
        AppToken token = (AppToken) authenticationToken;
        userInfo = userInfoService.loginAppToken(token.getToken());
        if (userInfo == null) {
            throw new AuthenticationException("token无效");
        }
        return new SimpleAuthenticationInfo(userInfo, token.getCredentials(), this.getName());
    }
}
