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; } }
标签:String,shiroUtil,org,apache,import,工具,currentUser,shiro 来源: https://www.cnblogs.com/375163374lsb/p/10543314.html