Java安全框架 Apache Shiro学习-1-ini 配置
简单登录流程:
Apache Shiro Configuration
Shiro 配置--ini
》适用于用户少且不需要在运行时动态创建的情景
1. web.xml 中自定义shiro.ini位置(默认位置)
/WEB-INF/shiro.ini or classpath:shiro.ini
配置内容
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class>
<init-param>
<param-name>configPath</param-name>
<param-value>/WEB-INF/anotherFile.ini</param-value>
</init-param>
</filter>
2. Shiro.ini 示例
# =======================
# 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] 主配置
configure the application's SecurityManager instance and any of its dependencies, such as Realms.
配置SecurityManager 及其依赖,如Realms(安全数据源).
[main]
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher # 加密密码匹配
# true = hex, false = base64:
sha256Matcher.storedCredentialsHexEncoded = false
myRealm = com.company.security.shiro.DatabaseRealm
myRealm.connectionTimeout = 30000
myRealm.username = jsmith # 内部被转换为 myRealm.setUsername("jsmith");
myRealm.password = secret
myRealm.credentialsMatcher = $sha256Matcher # 凭证(密码)加密
securityManager.sessionManager.globalSessionTimeout = 1800000
多个属性(逗号 ,)
securityManager.sessionManager.sessionListeners = $sessionListener1, $sessionListener2
Map形式属性设置
object1 = com.company.some.Class
object2 = com.company.another.Class
...
anObject = some.class.with.a.Map.property
anObject.mapProperty = key1:$object1, key2:$object2
重复设置的属性,后写的覆盖前面的
myRealm = com.company.security.MyRealm
...
myRealm = com.company.security.DatabaseRealm #(覆盖了前面的myRealm)
[users] 用户配置
[users]
admin = secret # A password is required.
lonestarr = vespa, goodguy, schwartz
darkhelmet = ludicrousspeed, badguy, schwartz
# user1 = sha256-hashed-hex-encoded password, role1, role2, ... # 可以使用 shiro 的Command Line Hasher 来加密密码。需要配置 credentialsMatcher
格式: 用户 = 密码,角色1,角色2,... ,角色N
username = password, roleName1, roleName2, ..., roleNameN
[roles] 角色配置
[roles]
# 'admin' role has all permissions, indicated by the wildcard '*'
admin = * # 所有权限
# The 'schwartz' role can do anything (*) with any lightsaber:
schwartz = lightsaber:* # 角色 schwartz 拥有对资源 lightsaber 做任何事的权限
# The 'goodguy' role is allowed to 'drive' (action) the winnebago (type) with
# license plate 'eagle5' (instance specific id)
goodguy = winnebago:drive:eagle5 # 角色 goodguy 拥有对 id 为 eagle5 的 winnebago 资源执行 drive 的权限
格式:角色 = 权限定义1,权限定义2,... ,权限定义N
rolename = permissionDefinition1, permissionDefinition2, ..., permissionDefinitionN
权限定义:http://shiro.apache.org/permissions.html
[url] web应用中url过滤
[urls]
/index.html = anon
/user/create = anon
/account/**=ssl,authc # Any request to my application's path of /account or any of it's sub paths (/account/foo, /account/bar/baz, etc) will trigger the 'ssl, authc' filter chain
/user/** = authc
/admin/** = authc, roles[administrator]
/rest/** = authc, rest
/remoting/rpc/** = authc, perms["remote:invoke"]
格式:
URL_Ant_Path_Expression = Path_Specific_Filter_Chain
注意:
1. 所有URL都是相对于 HttpServletRequest.getContextPath() 值而言的
2. URL过滤原则是 FIRST MATCH WINS. 后面的不会覆盖前面的!
url中过滤器(anno等)定义:
filter1[optional_config1], filter2[optional_config2], ..., filterN[optional_configN] # 如 authc, perms["remote:invoke"]
注意:若filter不是shiro中已定义的(DefaultFilter),而是自己继承 PathMatchingFilter 实现的,则需要在【main】中先声明
测试时,可以在【main】中禁用 filter
[main]
...
# configure Shiro's default 'ssl' filter to be disabled while testing:
ssl.enabled = false
登录请求login.do不能设为authc
Java安全框架 Apache Shiro学习-1-ini 配置的更多相关文章
- Apache Shiro学习-2-Apache Shiro Web Support
Apache Shiro Web Support 1. 配置 将 Shiro 整合到 Web 应用中的最简单方式是在 web.xml 的 Servlet ContextListener 和 Fil ...
- Apache Shiro 学习记录5
本来这篇文章是想写从Factory加载ini配置到生成securityManager的过程的....但是貌似涉及的东西有点多...我学的又比较慢...很多类都来不及研究,我又怕等我后面的研究了前面的都 ...
- apache shiro学习笔记
一.权限概述 1.1 认证与授权 认证:系统提供的用于识别用户身份的功能,通常登录功能就是认证功能-----让系统知道你是谁?? 授权:系统授予用户可以访问哪些功能的许可(证书)----让系统知道你能 ...
- Apache shiro学习总结
Apache shiro集群实现 (一) shiro入门介绍 Apache shiro集群实现 (二) shiro 的INI配置 Apache shiro集群实现 (三)shiro身份认证(Shiro ...
- Apache Shiro 学习记录2
写完上篇随笔以后(链接).....我也想自己尝试一下写一个Strategy.....Shiro自带了3个Strategy,教程(链接)里作者也给了2个.....我想写个都不一样的策略.....看来看去 ...
- Apache Shiro 学习记录1
最近几天在学习Apache Shiro......看了一些大神们的教程.....感觉收获不少.....但是毕竟教程也只是指引一下方向....即使是精品教程,仍然有很多东西都没有说明....所以自己也稍 ...
- 《Shiro框架》shiro学习中报错解决方法
[1] 最近在学习shiro,在学习过程中出现了一个问题,报错如下: org.apache.shiro.UnavailableSecurityManagerException: No Security ...
- Apache Shiro(六)-基于URL配置权限
数据库 先准备数据库啦. DROP DATABASE IF EXISTS shiro; CREATE DATABASE shiro DEFAULT CHARACTER SET utf8; USE sh ...
- 权限框架Apache Shiro 和 Spring Security
Shiro 首先Shiro较之 Spring Security,Shiro在保持强大功能的同时,还在简单性和灵活性方面拥有巨大优势.Shiro是一个强大而灵活的开源安全框架,能够非常清晰的处理认证.授 ...
随机推荐
- Quartz 2D编程指南(5) - 变换(Transforms)
Quartz 2D 绘制模型定义了两种独立的坐标空间:用户空间(用于表现文档页)和设备空间(用于表现设备的本地分辨率).用户坐标空间用浮点数表示坐标,与设备空间的像素分辨率没有关系.当我们需要一个点或 ...
- CH1802 表达式计算4
题意 给出一个表达式,其中运算符仅包含+,-,*,/,^(加 减 乘 整除 乘方)要求求出表达式的最终值 数据可能会出现括号情况,还有可能出现多余括号情况 数据保证不会出现>=2^31的答案 数 ...
- ambassador kubernetes native api gateway
github 上的介绍: Ambassador is an open source Kubernetes-native API Gateway built on Envoy, designed for ...
- 关于如何利用Pocket CHM Pro制作帮助文档
关于如何利用Pocket CHM Pro制作帮助文档 编写人:CC阿爸 2015-4-6 今天在这里,我想与大家一起分享如何利用Pocket CHM Pro制作软件系统的帮助文档,在此做个小结,以供参 ...
- Spring Cloud 服务网关Zuul
Spring Cloud 服务网关Zuul 服务网关是分布式架构中不可缺少的组成部分,是外部网络和内部服务之间的屏障,例如权限控制之类的逻辑应该在这里实现,而不是放在每个服务单元. Spring Cl ...
- nginx基于TCP的反向代理
一.4层的负载均衡 Nginx Plus的商业授权版开始具有TCP负载均衡的功能.从Nginx 1.7.7版本开始加入的,现在变成了一个商业收费版本,想要试用,需要在官网申请.也就是说,Nginx除了 ...
- (转) Docker EE/Docker CE简介与版本规划
随着Docker的不断流行与发展,docker公司(或称为组织)也开启了商业化之路,Docker 从 17.03版本之后分为 CE(Community Edition) 和 EE(Enterprise ...
- 第八章 Health Check
8.1 默认的健康检查 每个容器启动时会执行一个进程,此进程由Dockerfile的CMD或ENTRYPOINT指定.如果进程退出时返回码非零,则认为容器发生故障,K8s就会根据restartPoli ...
- 用户的 添加 权限 MySql远程登录
添加一个用户 '; 为这个叫mongo的用户赋予操作z_0811数据库的所有权限 '; mysql如何修改开启允许远程连接 关于mysql远程连接的问题,大家在公司工作中,经常会遇到mysql数据 ...
- Java类的初始化与实例对象的初始化
Java对象初始化详解 2013/04/10 · 开发 · 1 评论· java 分享到:43 与<YII框架>不得不说的故事—扩展篇 sass进阶篇 Spring事务管理 Android ...
/WEB-INF/shiro.ini or classpath:shiro.ini
<filter><filter-name>ShiroFilter</filter-name><filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class><init-param><param-name>configPath</param-name><param-value>/WEB-INF/anotherFile.ini</param-value></init-param></filter>
# =======================# 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] 主配置
[main]sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher # 加密密码匹配# true = hex, false = base64:sha256Matcher.storedCredentialsHexEncoded = falsemyRealm = com.company.security.shiro.DatabaseRealmmyRealm.connectionTimeout = 30000myRealm.username = jsmith # 内部被转换为myRealm.setUsername("jsmith");myRealm.password = secretmyRealm.credentialsMatcher = $sha256Matcher # 凭证(密码)加密securityManager.sessionManager.globalSessionTimeout = 1800000
securityManager.sessionManager.sessionListeners = $sessionListener1, $sessionListener2
object1 = com.company.some.Classobject2 = com.company.another.Class...anObject = some.class.with.a.Map.propertyanObject.mapProperty = key1:$object1, key2:$object2
myRealm = com.company.security.MyRealm...myRealm = com.company.security.DatabaseRealm #(覆盖了前面的myRealm)
[users] 用户配置
[users]admin = secret #A password is required.lonestarr = vespa, goodguy, schwartzdarkhelmet = ludicrousspeed, badguy, schwartz# user1 = sha256-hashed-hex-encoded password, role1, role2, ... # 可以使用 shiro 的Command Line Hasher 来加密密码。需要配置 credentialsMatcher
username = password, roleName1, roleName2, ..., roleNameN
[roles] 角色配置
[roles]# 'admin' role has all permissions, indicated by the wildcard '*'admin = * # 所有权限# The 'schwartz' role can do anything (*) with any lightsaber:schwartz = lightsaber:* # 角色 schwartz 拥有对资源 lightsaber 做任何事的权限# The 'goodguy' role is allowed to 'drive' (action) the winnebago (type) with# license plate 'eagle5' (instance specific id)goodguy = winnebago:drive:eagle5 # 角色goodguy 拥有对 id 为 eagle5 的 winnebago 资源执行 drive 的权限
rolename = permissionDefinition1, permissionDefinition2, ..., permissionDefinitionN
权限定义:http://shiro.apache.org/permissions.html
[url] web应用中url过滤
[urls]/index.html = anon/user/create = anon/account/**=ssl,authc # Any request to my application's path of /account or any of it's sub paths (/account/foo, /account/bar/baz, etc) will trigger the 'ssl, authc' filter chain/user/** = authc/admin/** = authc, roles[administrator]/rest/** = authc, rest/remoting/rpc/** = authc, perms["remote:invoke"]
URL_Ant_Path_Expression = Path_Specific_Filter_Chain
filter1[optional_config1], filter2[optional_config2], ..., filterN[optional_configN] # 如 authc, perms["remote:invoke"]
[main]...# configure Shiro's default 'ssl' filter to be disabled while testing:ssl.enabled = false
Apache Shiro Web Support 1. 配置 将 Shiro 整合到 Web 应用中的最简单方式是在 web.xml 的 Servlet ContextListener 和 Fil ...
本来这篇文章是想写从Factory加载ini配置到生成securityManager的过程的....但是貌似涉及的东西有点多...我学的又比较慢...很多类都来不及研究,我又怕等我后面的研究了前面的都 ...
一.权限概述 1.1 认证与授权 认证:系统提供的用于识别用户身份的功能,通常登录功能就是认证功能-----让系统知道你是谁?? 授权:系统授予用户可以访问哪些功能的许可(证书)----让系统知道你能 ...
Apache shiro集群实现 (一) shiro入门介绍 Apache shiro集群实现 (二) shiro 的INI配置 Apache shiro集群实现 (三)shiro身份认证(Shiro ...
写完上篇随笔以后(链接).....我也想自己尝试一下写一个Strategy.....Shiro自带了3个Strategy,教程(链接)里作者也给了2个.....我想写个都不一样的策略.....看来看去 ...
最近几天在学习Apache Shiro......看了一些大神们的教程.....感觉收获不少.....但是毕竟教程也只是指引一下方向....即使是精品教程,仍然有很多东西都没有说明....所以自己也稍 ...
[1] 最近在学习shiro,在学习过程中出现了一个问题,报错如下: org.apache.shiro.UnavailableSecurityManagerException: No Security ...
数据库 先准备数据库啦. DROP DATABASE IF EXISTS shiro; CREATE DATABASE shiro DEFAULT CHARACTER SET utf8; USE sh ...
Shiro 首先Shiro较之 Spring Security,Shiro在保持强大功能的同时,还在简单性和灵活性方面拥有巨大优势.Shiro是一个强大而灵活的开源安全框架,能够非常清晰的处理认证.授 ...
Quartz 2D 绘制模型定义了两种独立的坐标空间:用户空间(用于表现文档页)和设备空间(用于表现设备的本地分辨率).用户坐标空间用浮点数表示坐标,与设备空间的像素分辨率没有关系.当我们需要一个点或 ...
题意 给出一个表达式,其中运算符仅包含+,-,*,/,^(加 减 乘 整除 乘方)要求求出表达式的最终值 数据可能会出现括号情况,还有可能出现多余括号情况 数据保证不会出现>=2^31的答案 数 ...
github 上的介绍: Ambassador is an open source Kubernetes-native API Gateway built on Envoy, designed for ...
关于如何利用Pocket CHM Pro制作帮助文档 编写人:CC阿爸 2015-4-6 今天在这里,我想与大家一起分享如何利用Pocket CHM Pro制作软件系统的帮助文档,在此做个小结,以供参 ...
Spring Cloud 服务网关Zuul 服务网关是分布式架构中不可缺少的组成部分,是外部网络和内部服务之间的屏障,例如权限控制之类的逻辑应该在这里实现,而不是放在每个服务单元. Spring Cl ...
一.4层的负载均衡 Nginx Plus的商业授权版开始具有TCP负载均衡的功能.从Nginx 1.7.7版本开始加入的,现在变成了一个商业收费版本,想要试用,需要在官网申请.也就是说,Nginx除了 ...
随着Docker的不断流行与发展,docker公司(或称为组织)也开启了商业化之路,Docker 从 17.03版本之后分为 CE(Community Edition) 和 EE(Enterprise ...
8.1 默认的健康检查 每个容器启动时会执行一个进程,此进程由Dockerfile的CMD或ENTRYPOINT指定.如果进程退出时返回码非零,则认为容器发生故障,K8s就会根据restartPoli ...
添加一个用户 '; 为这个叫mongo的用户赋予操作z_0811数据库的所有权限 '; mysql如何修改开启允许远程连接 关于mysql远程连接的问题,大家在公司工作中,经常会遇到mysql数据 ...
Java对象初始化详解 2013/04/10 · 开发 · 1 评论· java 分享到:43 与<YII框架>不得不说的故事—扩展篇 sass进阶篇 Spring事务管理 Android ...