Shiro 的学习 原

2019-05-29 11:40:26 浏览数 (1)

为什么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");

0 人点赞