为什么80%的码农都做不了架构师?>>>
Shiro 加密
代码语言:javascript复制CustomRealm customRealm = new CustomRealm();
// 哈希凭证匹配器
HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
hashedCredentialsMatcher.setHashAlgorithmName("md5");
hashedCredentialsMatcher.setHashIterations(1);
customRealm.setCredentialsMatcher(hashedCredentialsMatcher);
// 1.构建SecurityManager环境
DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager();
defaultSecurityManager.setRealm(customRealm);
// 2.主体提交认证请求
SecurityUtils.setSecurityManager(defaultSecurityManager);
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken("zhangsan", "654321");
subject.login(token);
System.out.println("isAuthenticated " subject.isAuthenticated());
subject.checkRole("admin");
subject.checkPermission("user:add");
subject.checkPermission("user:update");