0
点赞
收藏
分享

微信扫一扫

Shiro——主配置文件

颜娘娘的碎碎念 2022-02-03 阅读 56

文章目录

四大区域

# =======================
# 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();
}

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

举报

相关推荐

0 条评论