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; } }