shiro

shiro中权限注解原理分析

感情迁移 提交于 2019-11-28 00:33:17
概述 前不久刚学会使用权限注解(),开始思索了一番。最开始猜测实现方式是注解@Aspect,具体实现方式类似如下所示(切面记录审计日志)。后来发现并非如此,所以特地分析一下源码。 @Component @Aspect public class AuditLogAspectConfig { @Pointcut("@annotation(com.ygsoft.ecp.mapp.basic.audit.annotation.AuditLog) || @annotation(com.ygsoft.ecp.mapp.basic.audit.annotation.AuditLogs)") public void pointcut() { } @After(value="pointcut()") public void after(JoinPoint joinPoint) { //执行的逻辑 } ... } 权限注解的源码分析 DefaultAdvisorAutoProxyCreator 这个类实现了 BeanProcessor 接口,当 ApplicationContext 读取所有的Bean配置信息后,这个类将扫描上下文,寻找所有的 Advistor (一个 Advisor 是一个切入点和一个通知的组成),将这些 Advisor 应用到所有符合切入点的Bean中。

shiro Apache 框架的学习之authentication 和authorization

耗尽温柔 提交于 2019-11-27 22:31:51
shiro 作为Apache的开源项目。该框架下的主要模块包含如下:     1, Subject     2, SecurityManager     3, Authenticator     4,Authorizer     5,Realm     6,SessionManager     7,SessionDao     8,CacheManager     9,Cryptography 源码下载链接: http://shiro.apache.org/download.html 详见官网。     如下以版本1.4学习为主。     shiro 作为java security framework, 其特点参考官网和百科。     如下以例子用户登录做authentication开篇介绍。     编写如下伪代码: //伪代码... class Controller{ ... ModelAndView login(Customer c){ Subject s = SecurityUtils.getSubject() UsenamePasswordToken token = new U...(c); try{s.login(token);} catche(..){..} .. } } 例子是个简单的login的Controller,使用SpringMVC的思想。

shiro 快速入门详解。

北慕城南 提交于 2019-11-27 21:14:27
package com.aaa.lee.shiro; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.*; import org.apache.shiro.config.IniSecurityManagerFactory; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.session.Session; import org.apache.shiro.subject.Subject; import org.apache.shiro.util.Factory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Simple Quickstart application showing how to use Shiro's API. * * @since 0.9 RC2 */ public class Quickstart { private static final transient Logger log = LoggerFactory.getLogger(Quickstart.class); public static void

Apache Shiro权限控制实战,权限控制SpringMVC + Mybatis + Shiro

时间秒杀一切 提交于 2019-11-27 20:43:37
Demo已经部署到线上,地址是 http://shiro.itboy.net , 管理员帐号:admin,密码:sojson.com 如果密码错误,请用sojson。 PS:你可以注册自己的帐号,然后用管理员赋权限给你自己的帐号,但是,每20分钟会把数据初始化一次。建议自己下载源码,让Demo跑起来,然后跑的更快,有问题加群解决。 Shiro Demo 源码下载 Shiro Demo 非Maven项目依赖包下载: 点我下载 Shiro Demo 源码下载下载: 点我(云端下载) Github下载: https://github.com/baichengzhou/SpringMVC-Mybatis-shiro Shiro Demo环境准备 开发工具: Eclipse 、 MyEclipse 、 Idea 等等。 依赖第三方: Mysql 5.0 以上、 Redis 。 需要的配置: jdbc.properties 中配置Mysql的信息、 spring-cache.xml 配置Redis 配置,如果是默认配置,就不用换, Redis Windows 安装: http://www.sojson.com/blog/110 。 注意 :请不要有端口8080,设置Tomcat端口为80,然后访问不要带项目路径访问。就好像生产环节一样:http://shiro.itboy.net 。

Freemarker-shiro的标签

跟風遠走 提交于 2019-11-27 19:27:48
一、引入依赖(已解决版本冲突) 复制代码 <!-- shiro-freemarker-tags start --> <dependency> <groupId>net.mingsoft</groupId> <artifactId>shiro-freemarker-tags</artifactId> <version>1.0</version> <exclusions> <exclusion> <groupId>org.apache.shiro</groupId> <artifactId>shiro-all</artifactId> </exclusion> <exclusion> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> </exclusion> </exclusions> </dependency> <!-- shiro-freemarker-tags end --> <!-- freemarker start --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.28</version> </dependency> <!--

springboot学习笔记3:重识shiro

♀尐吖头ヾ 提交于 2019-11-27 19:17:08
在之前ssm框架阶段,学习过shiro的一些基本使用,当时使用shiro是这样的: 1.配置shiro的配置文件,使用spring管理shiro 2.编辑登录的realm,并在内部实现登录方法 3.在controller层将用户名及密码封装成一个UsernamePasswordToken令牌,并实现登录方法,如图: 当时我们将封装令牌及登录方法写入了controller中,但是这种编辑方式是错误的,重新学习shiro后,对shiro有了新的认识: shiro的核心是过滤器,因此,如果没有登录的话, 应该直接拦截请求,而不是到后台在处理是否登录,在之前学习种,realm是这样写的: 这是之前的认证方法,当时认为是controller层调用登录方法后,然后再进入realm种,进行账号密码的比较,然后判断是否认证成功,当然 ,这是错误的理解 ,下面重新认识: 首先写一个控制器: @Controller public class LoginController { @RequestMapping("/login") public String login() { return "login"; } @RequestMapping("/") public String home() { return "index"; } } 可以看到又两个路径,/login路径返回登录页面,/返回主页面

Spring Boot整合Shiro

耗尽温柔 提交于 2019-11-27 19:14:45
概述 4A(认证Authentication、授权Authorization、账号Account、审计Audit)是现代任何IT系统中很基础但非常重要的部分,无论是传统管理信息系统还是互联网项目,出于保护业务数据和应用自身的安全,都会设计自己的登录和资源授权策略。最近项目中需要登录和权限相关的功能,项目为spring-boot工程,现在流行的权限验证框架有shiro和spring-security,shiro相对spring-security来说学习难度要低一点,也是比较成熟的产品,因此选择shiro作为项目的权限验证框架。 步骤 添加依赖 spring boot的版本为2.1.7.RELEASE。如果大量依赖spring的项目,可以用https://start.spring.io/ patchca是验证码部分 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.7.RELEASE</version> </parent> shiro-spring是用的最新的版本。patchca是用于验证码。 <dependencies> <dependency> <groupId>org

How to easily implement “who is online” in Grails or Java Application?

家住魔仙堡 提交于 2019-11-27 18:53:27
I am building a community website in grails (using Apache Shiro for security and authentication system) and I would like to implement the feature "who is online?". This url http://cksource.com/forums/viewonline.php (see snapshot below if you do not have acess to this Url) gives an example of what I would like to achieve. How can I do that in the most simple way? Is there any existing solution in Grails or in Java ? Thank you. Snapshot : Snapshot of Who is online page http://www.freeimagehosting.net/uploads/th.2de8468a86.png or see here : http://www.freeimagehosting.net/image.php?2de8468a86.png

GORM createCriteria and list do not return the same results : what can I do?

断了今生、忘了曾经 提交于 2019-11-27 18:23:37
问题 I am using Nimble and Shiro for my security frameworks and I've just come accross a GORM bug. Indeed : User.createCriteria().list { maxResults 10 } returns 10 users whereas User.list(max: 10) returns 9 users ! After further investigations, I found out that createCriteria returns twice the same user (admin) because admin has 2 roles !!! (I am not joking). It appears that any user with more than 1 role will be returned twice in the createCriteria call and User.list will return max-1 instances

Unable to @Inject my DAO in a Custom Apache Shiro AuthorizingRealm

感情迁移 提交于 2019-11-27 15:23:13
问题 I'm trying to inject my UserDAO inside my custom AuthorizingRealm that Apache Shiro is using but... I get null. What am I doing wrong? shiro.ini [main] user = demo.shiro.security.FacesAjaxAwareUserFilter realmA = demo.shiro.security.JpaRealm credentialsMatcher = org.apache.shiro.authc.credential.SimpleCredentialsMatcher realmA.credentialsMatcher = $credentialsMatcher securityManager.realms = $realmA user.loginUrl = /pages/public/login.xhtml [users] admin = admin user = user [urls] # public