ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Shiro——主配置文件

2022-02-03 18:32:00  阅读:152  来源: 互联网

标签:配置文件 roles urls Student main IOC Shiro users


文章目录

四大区域

# =======================
# Shiro INI configuration
# =======================

[main]
# Objects and their properties are defined here,
# Such as the securityManager, Realms and anything
# else needed to build the SecurityManager

[users]
# The 'users' section is for simple deployments
# when you only need a small number of statically-defined
# set of User accounts.

[roles]
# The 'roles' section is for simple deployments
# when you only need a small number of statically-defined
# roles.

[urls]
# The 'urls' section is used for url-based security
# in web applications.  We'll discuss this section in the
# Web documentation

main:IOC容器

声明一个SecurityManager,shiro会自动使用它:

sm = org.apache.shiro.mgt.DefaultSecurityManager

为其指定一个Realm:

r= base.test.MyRealm
sm.realms = $r

users:用户名 > 密码,角色

abc = 123,user,admin,root

其中,123是密码,后面是三个角色

roles:角色 > 权限

简简单单

user = u1,u2,u3
admin = a1,a2,a3
root = r1,r2,r3

urls:路径 > 拦截器

**=anon

左侧是路径,右侧是拦截器

番外:测试IOC

一个学生类:

public class Student {
	public Student() {
		System.out.println("new Student()");
	}
}

在容器中声明:

[main]
s1 = base.test.entity.Student

测试代码:

@Test
public void f6() {
	SecurityManager sm = new IniSecurityManagerFactory("classpath:shiro.ini").getInstance();
}

运行结果:
在这里插入图片描述
成功!

标签:配置文件,roles,urls,Student,main,IOC,Shiro,users
来源: https://blog.csdn.net/qq_37284843/article/details/122777139

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有