依赖Bean配置工具类变化测试
依赖Spring
org.springframework spring-context ${springV} org.springframework spring-test ${springV}
Shiro
org.apache.shiro shiro-core 1.3.2 org.apache.shiro shiro-ehcache 1.3.2 org.apache.shiro shiro-spring 1.3.2
日志
org.apache.logging.log4j log4j-web 2.17.1 org.apache.logging.log4j log4j-slf4j-impl 2.17.1
缓存
org.ehcache ehcache 3.9.0
开发辅助
Bean配置junit junit 4.13.2 test org.projectlombok lombok RELEASE compile
工具类变化
去掉static块
public class ShiroUtil {
public static Subject login(String username, String password) {
Subject s = SecurityUtils.getSubject();
try {
s.login(new UsernamePasswordToken(username, md5(password)));
} catch (AuthenticationException e) {
e.printStackTrace();
}
return s;
}
private static String md5(String input) {
return new Md5Hash(input, "manage", 1024).toString();
}
}
测试
没有多少变化,引入Spring测试
@ContextConfiguration("classpath:spring.xml")
@RunWith(SpringRunner.class)
public class HelloTest {
@Test
public void f1() {
Subject abc = ShiroUtil.login("abc", "123");
System.out.println("登陆状态" + abc.isAuthenticated());
System.out.println("有admin角色" + abc.hasRole("admin"));
System.out.println("有u1权限" + abc.isPermitted("u1"));
}
}
运行效果:



