资源简介
全程手把手带你运用Java技术栈,打造一套基于最流行的RBAC拓展模型的,分布式的,有界面的,高灵活性,高拓展性的企业级权限管理系统。源代码
代码片段和文件信息
package com.mmall.demo2;
import com.mmall.demo2.model.Permission;
import com.mmall.demo2.model.Role;
import com.mmall.demo2.model.User;
import com.mmall.demo2.service.UserService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class AuthRealm extends AuthorizingRealm {
@Autowired
private UserService userService;
// 授权
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
User user = (User) principals.fromRealm(this.getClass().getName()).iterator().next();
List permissionList = new ArrayList<>();
List roleNameList = new ArrayList<>();
Set roleSet = user.getRoles();
if (CollectionUtils.isNotEmpty(roleSet)) {
for(Role role : roleSet) {
roleNameList.add(role.getRname());
Set permissionSet = role.getPermissions();
if (CollectionUtils.isNotEmpty(permissionSet)) {
for (Permission permission : permissionSet) {
permissionList.add(permission.getName());
}
}
}
}
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addStringPermissions(permissionList);
info.addRoles(roleNameList);
return info;
}
// 认证登录
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;
String username = usernamePasswordToken.getUsername();
User user = userService.findByUsername(username);
return new SimpleAuthenticationInfo(user user.getPassword() this.getClass().getName());
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 249 2017-10-17 11:29 project\p1xn6d\apacheshiro\.gitignore
....... 47610 2017-10-17 11:29 project\p1xn6d\apacheshiro\.mvn\wrapper\maven-wrapper.jar
....... 110 2017-10-17 11:29 project\p1xn6d\apacheshiro\.mvn\wrapper\maven-wrapper.properties
....... 1735 2017-10-17 11:29 project\p1xn6d\apacheshiro\init.sql
....... 6468 2017-10-17 11:29 project\p1xn6d\apacheshiro\mvnw
....... 4994 2017-10-17 11:29 project\p1xn6d\apacheshiro\mvnw.cmd
....... 2915 2017-10-17 11:29 project\p1xn6d\apacheshiro\pom.xm
....... 2438 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\AuthRealm.java
....... 1877 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\controller\TestController.java
....... 699 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\CredentialMatcher.java
....... 485 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\Demo2Application.java
....... 3222 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\DruidConfiguration.java
....... 207 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\mapper\UserMapper.java
....... 517 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\model\Permission.java
....... 858 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\model\Role.java
....... 813 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\model\User.java
....... 146 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\service\UserService.java
....... 432 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\service\UserServiceImpl.java
....... 396 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\ServletInitializer.java
....... 2940 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\java\com\mmall\demo2\ShiroConfiguration.java
....... 457 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\resources\application.properties
....... 1301 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\resources\mappers\UserMapper.xm
....... 178 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\webapp\pages\index.jsp
....... 345 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\webapp\pages\login.jsp
....... 157 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\main\webapp\pages\unauthorized.jsp
....... 331 2017-10-17 11:29 project\p1xn6d\apacheshiro\src\test\java\com\mmall\demo2\Demo2ApplicationTests.java
....... 289 2017-10-17 11:29 project\p1xn6d\permission\.idea\artifacts\permission_war.xm
....... 4898 2017-10-17 11:29 project\p1xn6d\permission\.idea\artifacts\permission_war_exploded.xm
....... 805 2017-10-17 11:29 project\p1xn6d\permission\.idea\compiler.xm
....... 143 2017-10-17 11:29 project\p1xn6d\permission\.idea\deployment.xm
............此处省略434个文件信息
相关资源
- 权限管理系统JSP和Servlet开发
- Android6.0以上权限管理
- java写的用户权限管理源代码
- 权限管理模块
- Java serlvet+Jdbc+jsp+mysql 用户权限管理系
- java权限管理系统
- Android6.0新权限管理详解Demo
- 基于角色的java权限管理
- 毕业设计ssm点餐项目
- java+mysql权限管理系统
- javaweb 通用权限管理系统
- JSP权限管理系统
- 完整J2EE架构的用户权限管理系统源码
- 通用权限管理系统源码(新手级+附数
- javaweb快速开发框架
- JavaWeb通用权限管理的设计
- 基于SSM(Spring+SpringMVC+MyBatis)和Boot
- Java开发企业级权限管理系统
- shiro-all-1.4.0.jar
- SpringBoot与Shiro整合-权限管理实战视频
- java ssm权限管理系统 慕课实战
- 根据厂商rom打开权限管理(android代码
- 权限管理系统(SpringMvc+Spring+MyBatis框
- 后台脚手架框架(权限管理系统)源
- Java开发企业级权限管理系统.zip
- java权限管理代码
- 用java做的新闻网站设计实现包含后台
- java简单的权限管理系统源码+数据库
- java后台权限管理系统源码
- Springboot + shiro权限管理
评论
共有 条评论