shiroUtil工具类

package com.chabansheng.util;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

public class ShiroUtil {
    public static Subject login(String shiroConfig,String username,String password){
        Factory<SecurityManager> factory=new IniSecurityManagerFactory(shiroConfig);
        SecurityManager securityManager=factory.getInstance();
        SecurityUtils.setSecurityManager(securityManager);
        Subject currentUser=SecurityUtils.getSubject();
        UsernamePasswordToken token=new UsernamePasswordToken(username, password);
        
        try{
            currentUser.login(token);
            System.out.println("验证成功");
        }catch(AuthenticationException e){
            e.printStackTrace();
            System.out.println("验证shibai");
        }
        return currentUser;
    }
}

 

上一篇:Android中 使用 WebSocket 实现消息通信


下一篇:ThingsBoard入门实战(六):设备列表和带状态跳转