zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Shiro权限管理从一个简单的例子开始详解架构师

权限 详解 管理 简单 一个 开始 例子 架构师
2023-06-13 09:20:20 时间
(1)权限的继承性:A 包含 B,B无权限,但A有权限,此时B 的权限即为 A 的权限。如大厦里有公共厕所,进出大厦需要门禁,所以公共厕所的权限就是大厦的门禁权限。
(2)最近路劲匹配:如大厦某层有卫生间,要想到此卫生间需要有该层电梯权限,此时该卫生间的权限为该层电梯的权限,而不是大厦的门禁权限。
Shiro 的大管家管理着 Shiro 下的认证、授权、会话管理、缓存管理、以及 Realm 访问数据库,贯穿于始终的是加密。
    private static final transient Logger log = LoggerFactory.getLogger(Quickstart.class);
        Factory SecurityManager factory = new IniSecurityManagerFactory( classpath:shiro.ini );
            log.info( Retrieved the correct value! [ + value + ] );
            UsernamePasswordToken token = new UsernamePasswordToken( lonestarr , vespa );
                log.info( There is no user with username of + token.getPrincipal());
            } catch (IncorrectCredentialsException ice) {
                log.info( Password for account + token.getPrincipal() + was incorrect! );
                log.info( The account for username + token.getPrincipal() + is locked.   +
                        Please contact your administrator to unlock it. );
        log.info( User [ + currentUser.getPrincipal() + ] logged in successfully. );
            log.info( You may use a lightsaber ring.  Use it wisely. );
            log.info( Sorry, lightsaber rings are for schwartz masters only. );
            log.info( You are permitted to drive the winnebago with license plate (id) eagle5 .   +
            log.info( Sorry, you aren t allowed to drive the eagle5 winnebago! );
说明:获取 SecurityManager ,认证,认证失败的几种情况,成功登陆后是否拥有某个角色,某个角色是否有某个权限。
(2)多层次管理:如:user:query,user:edit,user:query,edit。第一部分为操作的领域,第二部分为执行的操作。可以使用通配符:user:*,*:query
介绍了权限的基础,介绍了 Shiro 的 HelloWorld,要明白其中重要的部分,如:认证、授权,以及Shiro 是如何来做这两件事情的。介绍官方demo 的 ini 配置方式,只是想更加深刻的去理解