OauthRealm.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. package com.qxgmat.util.shiro;
  2. import com.qxgmat.data.dao.entity.User;
  3. import com.qxgmat.service.UsersService;
  4. import org.apache.shiro.authc.*;
  5. import org.apache.shiro.authz.AuthorizationInfo;
  6. import org.apache.shiro.realm.AuthorizingRealm;
  7. import org.apache.shiro.subject.PrincipalCollection;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. /**
  10. * Created by GaoJie on 2017/11/3.
  11. */
  12. public class OauthRealm extends AuthorizingRealm {
  13. @Autowired
  14. private UsersService usersService;
  15. @Override
  16. protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
  17. return null;
  18. }
  19. @Override
  20. protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
  21. UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
  22. String code = token.getUsername();
  23. String platform = new String(token.getPassword());
  24. User user = usersService.Oauth(null, code, platform);
  25. return new SimpleAuthenticationInfo(user, platform, getName());
  26. }
  27. }