
Spring
org.springframework spring-context${springV} org.springframework spring-test${springV}
Shiro
org.apache.shiro shiro-core1.3.2 org.apache.shiro shiro-ehcache1.3.2 org.apache.shiro shiro-spring1.3.2
日志
org.apache.logging.log4j log4j-web2.17.1 org.apache.logging.log4j log4j-slf4j-impl2.17.1
缓存
org.ehcache ehcache3.9.0
开发辅助
Bean配置junit junit4.13.2 test org.projectlombok lombokRELEASE 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"));
}
}
运行效果:
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)