package com.qxgmat.util.shiro; import com.qxgmat.data.dao.entity.User; import com.qxgmat.service.UsersService; import org.apache.shiro.authc.*; import org.apache.shiro.authz.AuthorizationInfo; import org.apache.shiro.realm.AuthorizingRealm; import org.apache.shiro.subject.PrincipalCollection; import org.springframework.beans.factory.annotation.Autowired; /** * Created by GaoJie on 2017/11/3. */ public class OauthRealm extends AuthorizingRealm { @Autowired private UsersService usersService; @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { return null; } @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; String code = token.getUsername(); String platform = new String(token.getPassword()); User user = usersService.Oauth(null, code, platform); return new SimpleAuthenticationInfo(user, platform, getName()); } }