在Apache Shiro - Maven项目中,subject是null alwasys

时间:2017-04-04 06:23:41

标签: java shiro

返回 Null

Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
Subject currentUser = SecurityUtils.getSubject();
System.out.println(currentUser.getPrincipal());

总是它返回null,我错过了什么? 领域是:org.apache.shiro.realm.jdbc.JdbcRealm

1 个答案:

答案 0 :(得分:1)

校长为null,因为您没有登录用户。请查看Subject.isAuthenticated()Subject.login()