shiro

org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code

末鹿安然 提交于 2019-12-25 04:07:49
问题 i have a junit test case that runs a code like: if (SecurityUtil.isAuthenticated()) { } and it gives an exception: org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration. My Test Class configuration is as follows: @RunWith(SpringJUnit4ClassRunner.class) @TestExecutionListeners({ WebContextTestExecutionListener.class

Shiro权限管理框架

北慕城南 提交于 2019-12-25 03:14:18
一、Shiro介绍   Apache Shiro 是Java 的一个安全框架。Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在JavaSE 环境,也可以用在JavaEE 环境。Shiro 可以帮助我们完成:认证、授权、加密、会话管理、与Web 集成、缓存等。   既然shiro将安全认证相关的功能抽取出来组成一个框架,使用shiro就可以非常快速的完成认证、授权等功能的开发,降低系统成本。 shiro使用广泛,shiro可以运行在web应用,非web应用,集群分布式应用中越来越多的用户开始使用shiro。 java领域中spring security(原名Acegi)也是一个开源的权限管理框架,但是spring security依赖spring运行,而shiro就相对独立,最主要是因为shiro使用简单、灵活,所以现在越来越多的用户选择shiro。 二、Shiro基本概念    Shiro 不会去维护用户、维护权限;这些需要我们自己去设计/提供;然后通过相应的接口注入给Shiro即可 1,Authentication   身份认证/登录,验证用户是不是拥有相应的身份。 2,Authorization   授权,即权限验证,验证某个已认证的用户是否拥有某个权限;即判断用户是否能做事情,常见的如:验证某个用户是否拥有某个角色

Apache Shiro系列一,概述 —— 初识

こ雲淡風輕ζ 提交于 2019-12-24 19:05:39
Shiro的设计目标就是让应用程序的安全管理更简单、更直观。 软件系统一般是基于用户故事来做设计。也就是我们会基于一个客户如何与这个软件系统交互来设计用户界面和服务接口。比如,你可能会说:“如果用户登录了我们的系统,我就给他们显示一个按钮,点击之后可以查看他自己的账户信息。如果没有登录,我就给他显示一个注册按钮。” 上述应用程序在很大程度上是为了满足用户的需求而编写的,即便这个“用户”不是人,而是一个其他的软件系统。你仍然是按照谁当前正在与你的系统交互的逻辑来编写你的逻辑代码。 Shiro的设计已经考虑到以上这些用户安全的概念。 总览 在最顶层,Shiro的架构有3个主要概念:Subject、SecurityManager和Realms。下图展示了这几个组件之间的交互,下面我们会逐一介绍这些概念: #,Subject,正如我们在 教程 中所说,Subject其实代表的就是当前正在执行操作的用户,只不过因为“User”一般指代人,但是一个“Subject”可以是人,也可以是任何的第三方系统,服务账号等任何其他正在和当前系统交互的第三方软件系统。 所有的Subject实例都被绑定到一个SecurityManager,如果你和一个Subject交互,所有的交互动作都会被转换成Subject与SecurityManager的交互。 #,SecurityManager

Shiro——MD5加密

混江龙づ霸主 提交于 2019-12-24 17:56:12
一、shiro默认密码的比对 通过 AuthenticatingRealm 的 credentialsMatcher 属性来进行的密码的比对 /**源码org.apache.shiro.realm.AuthenticatingRealm * Asserts that the submitted {@code AuthenticationToken}'s credentials match the stored account * {@code AuthenticationInfo}'s credentials, and if not, throws an {@link AuthenticationException}. * * @param token the submitted authentication token * @param info the AuthenticationInfo corresponding to the given {@code token} * @throws AuthenticationException if the token's credentials do not match the stored account credentials. */ protected void assertCredentialsMatch

How to load files/properties from WEB-INF directory?

别等时光非礼了梦想. 提交于 2019-12-24 17:48:50
问题 It seems that in my Tapestry app, I can't load ini files nor properties file from WEB-INF directory or class path. I tried several different methods which should load my file but non of them worked. ex realm.setResourcePath("/WEB-INF/auth.properties"); ex realm.setResourcePath("classpath:wip/pages/auth.properties"); I need to load properties/ini file in order to use tapestry-security module which is based on Shiro. Thanks for help ! 回答1: The root of the classpath is the way to go. Put your

Shiro in distributed environment - auto authenticating/white listing internal calls

我与影子孤独终老i 提交于 2019-12-24 14:47:03
问题 I am developing a distributed system with shiro for RBAC. I am not using shiro-web , but have custom filtering in my SecurityFilter attached to the Servlet. My question is, Is there a way to white-list(auto-authenticate) requests coming from certain nodes ( in my case, peers in the distributed system) without having to go through the entire authentication process. 回答1: We use an approach when we have some code that is started by the system, not a user and we use the idea of a system user

珠联璧合 | ServiceComb 集成 Shiro 实践

旧时模样 提交于 2019-12-24 11:41:36
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Shiro简介 Apache Shiro是一款功能强大、易用的轻量级开源Java安全框架,它主要提供认证、鉴权、加密和会话管理等功能。Spring Security可能是业界用的最广泛的安全框架,但是Spring Security和Spring耦合的太重,脱离了Spring框架就使用不了,所以一个轻量级的安全框架有时也是一个非常不错的选择。 Shiro主要通过安全API来提供四个方面使用: 认证 Authentication –提供用户身份,可以理解为登录验证。 授权 Authorization –访问控制,也就是通常所讲ACL(Access Control List)的RBAC(Role Base Access Control)或者ABAC(Attribute Base Access Control)。 加密 Cryptography –加密、保护数据,确保数据安全。 会话管理 Session Management –登录后的会话管理,Shiro有独立的会话管理机制,可以是J2EE的会话,也可以是普通Java应用的。 Shiro有几个关键的核心概念:Subject,SecurityManager和Realms,我们简单的介绍下这几个概念的含义: Subject 权限责任主体,主要是让系统识别要管理的对象

JSF 2 + Spring 3 + Shiro - Session Timeout doesn't redirect to login page

人盡茶涼 提交于 2019-12-24 10:59:35
问题 I have this JSF 2.0/Spring app that added Apache Shiro to and a redirect after session timeout never occurs when a user clicks on a command button or triggers an AJAX request. It does work when they refresh the browser. This is happening in all browsers. Here's my applicationContext.xml: <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <property name="securityManager" ref="securityManager" /> <property name="loginUrl" value="/index.faces"/> <property name=

How to stay logged in permanently using apache shiro

妖精的绣舞 提交于 2019-12-24 09:49:08
问题 A need to know how to stay logged in permanently in my Java EE application when the user logged in at first time using apache shiro Any Idea? 回答1: Shiro supports "Remember me" facility. Just provide a checkbox with name rememberMe in the login form: <input type="checkbox" name="rememberMe" value="true" /> If you want to use JSF <h:selectBooleanCheckbox> as follows, <h:form id="login"> <h:selectBooleanCheckbox id="rememberMe" /> Then you need to alter the shiro.ini to add the following entry

带你揭秘Shiro(一)

扶醉桌前 提交于 2019-12-24 07:01:35
提到Shiro,不得不先介绍RBAC介绍 RBAC介绍:   RBAC是基于角色的访问控制(Role-Based Access Control )在 RBAC 中,权限与角色相关联,用户通过成为适当角色的成员而得到这些角色的权限。这就极大地简化了权限的管理。这样管理都是层级相互依赖的,权限赋予给角色,而把角色又赋予用户,这样的权限设计很清楚,管理起来很方便。 在RBAC模型里面,有3个基础组成部分,分别是:用户、角色和权限。 RBAC通过定义角色的权限,并对用户授予某个角色从而来控制用户的权限,实现了用户和权限的逻辑分离,极大地方便了权限的管理,在讲解之前,先介绍一些名词: User(用户):每个用户都有唯一的UID识别,并被授予不同的角色 Role(角色):不同角色具有不同的权限 Permission(权限):访问权限 用户-角色映射:用户和角色之间的映射关系 角色-权限映射:角色和权限之间的映射 权限管理:(包含两部分:用户认证,用户授权)   只要有用户参与的管理系统一般都有权限管理,权限管理实现对用户访问系统的控制,按照安全规则实现用户可以访问自己被授权的资源。 用户认证: 关键对象: subject:主体,理解为用户,可能是程序,都要去访问系统的资源,系统需要对subject进行身份认证。 principal:身份信息,通常是唯一的,一个主体还有多个身份信息