• 大小: 2.84MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-01
  • 语言: Java
  • 标签: 权限管理  

资源简介

全程手把手带你运用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.xml

    .......      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.xml

    .......       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.xml

    .......      4898  2017-10-17 11:29  project\p1xn6d\permission\.idea\artifacts\permission_war_exploded.xml

    .......       805  2017-10-17 11:29  project\p1xn6d\permission\.idea\compiler.xml

    .......       143  2017-10-17 11:29  project\p1xn6d\permission\.idea\deployment.xml

............此处省略434个文件信息

评论

共有 条评论