时间:2021-07-01 10:21:17 帮助过:36人阅读
java文件
package shiro; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.config.IniSecurityManagerFactory; import org.apache.shiro.util.Factory; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.subject.Subject; public class ShiroTest { public static void main(String[] args) { //初始化工厂 Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:shiro/jdbcRealm.ini"); SecurityManager securityManager=factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); Subject subject=SecurityUtils.getSubject(); UsernamePasswordToken token=new UsernamePasswordToken("tom","123"); try { subject.login(token); System.out.println("登陆成功"); } catch (Exception e) { e.printStackTrace(); System.out.println("登陆失败"); } subject.logout(); } }
数据库
shiro连接数据库
标签:ken src use blog url nis out nbsp eal