XiaoRuby
2023-07-13 27e9d7d2c7db63c5f12c83e069980213398e8337
user-server/src/main/java/com/yuanchu/limslaboratory/shiro/realm/ShiroRealm.java
@@ -2,10 +2,8 @@
import com.yuanchu.limslaboratory.pojo.User;
import com.yuanchu.limslaboratory.service.UserService;
import com.yuanchu.limslaboratory.utils.MyUtils;
import com.yuanchu.limslaboratory.utils.SpringUtils;
import com.yuanchu.limslaboratory.utils.SpringUtil;
import org.apache.shiro.authc.*;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
@@ -32,24 +30,12 @@
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) {
        String principal = (String) authenticationToken.getPrincipal();
        //获取UserService对象
        UserService userService = SpringUtils.getBean(UserService.class);
        UserService userService = SpringUtil.getBean(UserService.class);
        user = userService.AccordingUsernameSelectAll(principal);
        MyUtils.PrintLog(user.toString());
        if (!ObjectUtils.isEmpty(user)) {
            return new SimpleAuthenticationInfo(user.getAccount(), user.getPassword(), this.getName());
        } else {
            throw new UnknownAccountException();
        }
    }
    @Override
    public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) {
//        HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
//        //设置使用MD5加密算法
//        hashedCredentialsMatcher.setHashAlgorithmName(Md5Hash.ALGORITHM_NAME);
//        //散列次数
//        hashedCredentialsMatcher.setHashIterations(1024);
//        super.setCredentialsMatcher(hashedCredentialsMatcher);
        super.setCredentialsMatcher(credentialsMatcher);
    }
}