shiro

shiro的使用

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 17:01:05
Subject(主体) 通过安全管理器进行 认证 和授权 SecurityMannager 安全管理器 SecurityMannager 是shiro框架的核心 Authenticator 认证器 对主体进行认证 Authorizer 授权器 用户通过认证器认证通过,在访问功能时通过授权器判断用户是否有此功能的操作权限 Realm SecurityMannager 进行安全认证需要通过Realm湖区用户权限数据 Realm 也是一个接口 Realm: 从配置文件或者数据库等读取用户的权限信息 多实现: 1.将用户的权限信息存储到配置文件 2.将用户的权限信息存储到数据库 SessionManager 会话管理器 shiro框架有一套自己的session容器 shiro可以使用到非wevb项目上的,也可以实现单点登录 SessionDao 是对session会话操作的一套接口,比如要将会话信息存储到redis数据库 CacheManager 缓存管理器(提高性能)缓存第三方 防止用户每次或是重复登陆,都需要在数据库获取一次权限信息,所以存放在缓存中 对于用户反复查询访问自身那个权限的这种操作,便提供了缓存管理器 第一次访问后将信息放入缓存管理器,在接下来的操作中,直接从缓存中获取用户权限 Cryptography 密码管理器,shiro提供了一套加密/解密的组件,方便开发

How to redirect already authenticated user from login page to home page

落爺英雄遲暮 提交于 2019-12-09 12:06:33
问题 I'm developing JSF application with Apache Shiro. I autenticate the user with Shiro and redirect her to home page there is no problem with that. After the authentication when I try to access login page, it doesn't redirect me the homepage. I can login again even when there is already loggedin user. I'm doing Programmatic Login as BalusC mentioned in his blog post. [main] credentialsMatcher = org.apache.shiro.authc.credential.PasswordMatcher myRealm = com.example.security.myRealm myRealm

shiro中MessageDigest根据盐值计算md5

血红的双手。 提交于 2019-12-09 05:31:54
MessageDigest简介    java.security.MessageDigest 类用于为应用程序提供信息摘要算法的功能,如 MD5 或 SHA 算法。简单点说就是用于生成散列码。信息摘要是安全的单向哈希函数,它接收任意大小的数据,输出固定长度的哈希值。 源码示例   在下面的示例中,抽取的是 shiro 中的 SimpleHash 类源码使用的是 shiro 中的 MessageDigest ,通过对名为 admin 的 username 进行盐值计算,然后依据此盐值对密码 123456 进行 md5 计算。   源码如下: @Slf4j public class MessageDigestTest { /** * 盐值计算 * @param username 用户名 * @return byte[] 盐值byte数组 */ public byte [ ] getSalt ( String username ) { // 计算盐值 ByteSource byteSource = ByteSource . Util . bytes ( username ) ; return byteSource . getBytes ( ) ; } /** * 将字符串转换成byte数组 * @param str 输入字符串 * @return byte[] */ private

js报Uncaught SyntaxError: Unexpected token <错误 解决方法

為{幸葍}努か 提交于 2019-12-08 20:26:27
js报Uncaught SyntaxError: Unexpected token <错误 解决方法 错因 js被shiro的拦截器拦下,访问不了 #shiro的配置 shiro: hash-algorithm-name: md5 hash-iterations: 2 anon-urls: - /index.html* - /sys/toLogin* - /login/login* - /layuicms2.0/** login-url: /index.html log-out-url: /login/logout* authc-ulrs: - /** 解决方法 放行layuicms2.0下的静态资源文件 来源: https://www.cnblogs.com/senup/p/12007012.html

Ajax Session Time Out FullAjaxExceptionHandlerFactory not working with shiro

◇◆丶佛笑我妖孽 提交于 2019-12-08 13:39:30
问题 Details of the code that i have added for using Ajax Session time out, as described by BaluC Faces-Config.xml <factory> <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory> </factory> Web.xml <error-page> <exception-type>javax.faces.application.ViewExpiredException</exception-type> <location>/expired.xhtml</location> </error-page> application-config.xml <bean id="shiroFilter" class="org.apache.shiro.spring.web

Correct way to use Apache Shiro on distributed system using RMI? [duplicate]

怎甘沉沦 提交于 2019-12-08 07:51:28
问题 This question already has answers here : How to organize RMI Client-Server architecture (2 answers) Closed 6 years ago . I'm looking for some guidelines/tips on how to implement Apache Shiro as a part of a distributed system (client-server) using Java RMI. I've looked at the answer to this thread : How to organize RMI Client-Server architecture and I'm thinking of using something similar. What I have planned is a remote object (possibly a Singleton?) that handles the authentication when the

netbeans 8.0.1 cant find shiro.ini

淺唱寂寞╮ 提交于 2019-12-08 05:30:19
问题 I added this shir.ini under web pages under WEB-INF: [main] # Objects and their properties are defined here, # Such as the securityManager, Realms and anything # else needed to build the SecurityManager shiro.loginUrl = /index.jsp [users] root = 12345,admin guest = 12345,guest [roles] admin = * [urls] /index.xhtml = authc /login.xhtml = authc /info.xhtml = anon /logout = logout /admin/** = authc, roles[admin] but in glassfish server 4.1 window, I got this error: SEVERE: [admin-listener(5)]

springboot shiro

不问归期 提交于 2019-12-07 20:33:40
最近研究后端的权限管理,一般两个选择shiro和spring security,都说shiro相对简单,就先用他,后面在去研究spring security。 具体的内容介绍不多介绍了,找了两个大佬写的博客,讲的挺不错,链接贴上 https://segmentfault.com/a/1190000011918957 https://www.cnblogs.com/ll409546297/p/7815409.html 然后比葫芦画瓢自己写的代码也贴上来看看,相关地方都已加上注释 ShiroConfiguration文件的内容 package com.example.web.controller; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; import org.apache.shiro.spring.web.ShiroFilterFactoryBean; import org.springframework.context.annotation

Spring与Shiro整合 静态注解授权

夙愿已清 提交于 2019-12-07 18:55:32
Spring与Shiro整合 静态注解授权 作者 : Stanley 罗昊 【转载请注明出处和署名,谢谢!】 使用Shiro的种类 首先,Shiro的授权方式共有三种; 1.编程式授权(不推荐) 2.注解式授权(普遍使用【力荐】) 注:第一个始于基于角色控制权限,就是你这个用户拥有那些权限; 第二个基于权限控制,判断你这个角色是否拥有这项权限,如果有给放行,如果没有被拦截;这个一般是判断数据库User表中会有一个权限列; 3.Jsp式授权(一般前端UI有对应解决方案) 注:jsp标签方式只是表面上不将此功能显示,但是如果有恶意用户绕过,直接输入ip地址+接口名称即可访问,所以必须配合后端一起使用; 了解授权(注解方式) 首先,我们在jsp页面上编写几个a标签: 我们看到了分别有增、改、删,这也就对应我们后台控制器(Conteoller)中mapping内的Url拦截地址: 我们现在开始将以上操作纳入Shiro管理;这一步,仅仅就是让这些Url纳入并被Shiro管理在Conteoller中声明;, 将Url交给Shiro管理 纳入很简单,只需要在这个接口上加上注解即可: 注:第一个始于基于角色控制权限,就是你这个用户拥有那些权限; 第二个基于权限控制,判断你这个角色是否拥有这项权限,如果有给放行,如果没有被拦截;这个一般是判断数据库User表中会有一个权限列【推荐】;

SpringBoot 整合Shiro框架

天涯浪子 提交于 2019-12-07 16:22:24
1. 引入Maven依赖 <!-- shiro-spring --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>1.4.0</version> </dependency> 2. 用户认证和授权   A. 定义一个ShiroConfig配置类,然后配置安全管理器Bean(SecurityManager),用于管理Subject;   B. 在ShiroConfig中配置过滤器工厂Bean(ShiroFilterFactoryBean),依赖于SecurityManager;   C. 自定义Realms实现类,重写doGetAuthenticationInfo()和doGetAuthorizationInfo()方法; 来源: https://www.cnblogs.com/ruhuanxingyun/p/12002117.html