shiro

shiro入门

允我心安 提交于 2019-12-03 10:12:29
Shiro 简介 1. 什么是 shiro shiro是 apache的一个开源框架,是一个权限管理的框架,实现 用户认证、用户授权。 spring中有 spring security (原名 Acegi),是一个权限框架,它和 spring依赖过于紧密,没有 shiro使用简单。 shiro不依赖于 spring, shiro不仅可以实现 web应用的权限管理,还可以实现 c/s系统, 分布式系统权限管理, shiro属于轻量框架,越来越多企业项目开始使用 shiro。 2. 在应用程序角度来观察如何使用 Shiro完成工作 (图 01) Subject:主体,代表了当前“用户”,这个用户不一定是一个具体的人,与当前应用交互的任何东西都是 Subject,如网络爬虫,机器人等;即一个抽象概念;所有 Subject 都绑定到 SecurityManager,与 Subject的所有交互都会委托给 SecurityManager;可以把 Subject认为是一个门面; SecurityManager才是实际的执行者; SecurityManager:安全管理器;即所有与安全有关的操作都会与 SecurityManager 交互;且它管理着所有 Subject;可以看出它是 Shiro 的核心,它负责与后边介绍的其他组件进行交互,如果学习过 SpringMVC,你可以把它看成

Shiro入门

那年仲夏 提交于 2019-12-03 10:04:26
Shiro入门 1. 什么是shiro shiro是apache的一个开源框架,是一个权限管理的框架,实现 用户认证、用户授权。 spring中有spring security (原名Acegi),是一个权限框架,它和spring依赖过于紧密,没有shiro使用简单。 shiro不依赖于spring,shiro不仅可以实现 web应用的权限管理,还可以实现c/s系统, 分布式系统权限管理,shiro属于轻量框架,越来越多企业项目开始使用shiro。 2. 在应用程序角度来观察如何使用Shiro完成工作(图01) Subject:主体,代表了当前“用户”,这个用户不一定是一个具体的人,与当前应用交互的任何东西都是Subject,如网络爬虫,机器人等;即一个抽象概念;所有Subject 都绑定到SecurityManager,与Subject的所有交互都会委托给SecurityManager;可以把Subject认为是一个门面;SecurityManager才是实际的执行者; SecurityManager:安全管理器;即所有与安全有关的操作都会与SecurityManager 交互;且它管理着所有Subject;可以看出它是Shiro 的核心,它负责与后边介绍的其他组件进行交互,如果学习过SpringMVC,你可以把它看成DispatcherServlet前端控制器; Realm:域

How to configure Shiro with Spring Boot

孤街浪徒 提交于 2019-12-03 10:03:16
问题 I have a Spring MVC web application that uses Shiro authentication using Spring configuration rather than a shiro.ini. I want to transition to a Spring Boot application. I have been mainly successful. The application starts in Spring Boot and my Shiro environment gets setup. However I just cannot work out how to setup the Shiro Filter correctly. I need this to be working to make sure requests end up being handled by the correct thread. In the original app I configured the Shiro Filter in the

Shiro入门

微笑、不失礼 提交于 2019-12-03 09:58:33
1. 什么是 shiro shiro 是 apache 的一个开源框架,是一个权限管理的框架,实现 用户认证、用户授权。 spring 中有 spring security ( 原名 Acegi) ,是一个权限框架,它和 spring 依赖过于紧密,没有 shiro 使用简单。 shiro 不依赖于 spring , shiro 不仅可以实现 web 应用的权限管理,还可以实现 c/s 系统, 分布式系统权限管理, shiro 属于轻量框架,越来越多企业项目开始使用 shiro 。 2. 在应用程序角度来观察如何使用 Shiro 完成工作 ( 图 01) Subject :主体,代表了当前“用户”,这个用户不一定是一个具体的人,与当前应用交互的任何东西都是 Subject ,如网络爬虫,机器人等;即一个抽象概念;所有 Subject 都绑定到 SecurityManager ,与 Subject 的所有交互都会委托给 SecurityManager ;可以把 Subject 认为是一个门面; SecurityManager 才是实际的执行者; SecurityManager :安全管理器;即所有与安全有关的操作都会与 SecurityManager 交互;且它管理着所有 Subject ;可以看出它是 Shiro 的核心,它负责与后边介绍的其他组件进行交互,如果学习过

shiro异步请求返回JSON响应

蓝咒 提交于 2019-12-03 09:35:38
shiro异步请求返回JSON响应 需求1:当shiro请求资源,但是没有进行认证时,默认是进行重定向,现在需要返回JSON响应。注意异步请求,服务器重定向后,ajax拿到的是浏览器重定向后的到的页面源码。 解决2: 自定义FormAuthenticationFilter。覆盖onAccessDenied方法。返回JSON字符串。并将自定义的过滤器添加到ShiroFilterFactoryBean,键的名称为authc。 需求2:ShiroFilterFactoryBean用注解时,过滤的urls被写死在代码中,需要将urls的配置放到配置文件中。 解决2: 方法1:ShiroFilterFactoryBean不使用注解方法,而是xml配置注入。@ImportResource("classpath:shiro/shiro-config.xml") 方法2:自己通过shiro的Ini类加载ini配置文件。读取自定义的urls。 步骤 自定义 authc 对应过滤器 FormAuthenticationFilter。覆盖 onAccessDenied 方法返回JSON响应。 将自定义过滤器添加到 ShiroFilterFactoryBean。名称为 authc 。 ResultFormAuthenticationFilter package com.mozq.shiro.shiro01

shiro源码分析2

醉酒当歌 提交于 2019-12-03 09:08:07
简介 SecurityManager:安全管理器,Shiro最核心组件。Shiro通过SecurityManager来管理内部组件实例,并通过它来提供安全管理的各种服务。 Authenticator:认证器,认证AuthenticationToken是否有效。 Authorizer:授权器,处理角色和权限。 SessionManager:Session管理器,管理Session。 Subject:当前操作主体,表示当前操作用户。 SubjectContext:Subject上下文数据对象。 AuthenticationToken:认证的token信息(用户名、密码等)。 ThreadContext:线程上下文对象,负责绑定对象到当前线程。 在学习和使用Shiro过程中,我们都知道SecurityManager接口在Shiro中是最为核心的接口。我们就沿着这个接口进行分析。 下面的代码是SecurityManager接口的定义: public interface SecurityManager extends Authenticator, Authorizer, SessionManager { /** * 登录 */ Subject login(Subject subject, AuthenticationToken authenticationToken) throws

Shiro Authenticates Non-existent User in LDAP

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can anyone suggest why Shiro tells me in my trace logs below that a non existent user "anybody" is authenticated ok? It seems to give itself a session earlier on in the log prior to actually authenticating. I assume that this is just to run the authentication. It redirects ok to my ShiroFilterFactoryBean loginUrl if I logout and then try to access any secured url. But then it will authenticate any user. Jan 27 20:25:16 TRACE org.apache.shiro.subject.support.DelegatingSubject - attempting to get session; create = false; session is null =

Apache Shiro credentials based security for Rest service

扶醉桌前 提交于 2019-12-03 08:55:20
I'm creating a App using Shiro as the security framework. The app have two parts; Web and Rest. The Web is using Shiro's default FormAuthenticationFilter . I'm happy with the session based approach. The stand alone app which is using Rest, I want to limit from using the FormAuthenticationFilter and from creating a session, which I'm able to do via shiro.ini file I need to implement credentials based security on the rest service. Browsing on the web I saw some blogs suggesting that you create your own Realm and filter to handle this scenario. But no details on how to do this. Is it possible to

Shiro complaining “There is no session with id xxx” with DefaultSecurityManager

匿名 (未验证) 提交于 2019-12-03 08:35:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Apache Shiro 1.2.0 in a long-running application that reads messages from a queue and and takes action. The action taken requires a Shiro authenticated session, so I've implemented an "ActAsAuthenticationToken" and custom credentials matcher which allows us to login in with only the username. I'm using the DefaultSecurityManager with only my custom realm and subject factory injected. Everything else should be default. As it is configured, everything worked fine for a while, but as the application ran a long time (not that long -