Git Product home page Git Product logo

shiro-project's Introduction

"用户"不直接和"权限"产生关系,而是通过"角色"作为桥梁。 因为"用户"具有了一些"角色","角色"上绑定了"权限","用户"才具有"权限"。

集成 Spring 的步骤 1、引入依赖 shiro-spring; 2、在 web.xml 把原来的过滤器和监听器改成代理; 3、添加 shiro-web.xml 的配置; 4、把 shiro-web.xml 这个配置文件添加到 Spring 的监听器中去; 5、把原来 Realm 中使用 InitServelt 加载的 UserService 组件改换成使用依赖注入。

配置 Shiro 默认的缓存(使用 Ehcache 实现) 小技巧:查找类 Command + O 1、添加 shiro-ehcache 接口依赖 2、添加 ehcache 实现依赖 3、在 Spring 的配置文件中声明 EhcacheManager

4、在 classpath 下添加 ehcache 配置文件

5、在 Realm 中配置开启认证缓存和授权缓存,并且指定使用的缓存的名称. (1)在 securityManager 中配置 cacheManager (2)在 realm 中配置是否开启缓存

配置了上面的步骤以后,我们发现是有问题的,在使用 <shiro:principal property="nickname"/> 标签的时候, 我们发现认证缓存在退出登录的时候控制台打印如下。

2016-09-21 09:27:27,244 [qtp1501513951-23] INFO [com.liwei.shiro.realm.MyRealm] - 清除认证时候的缓存 2016-09-21 09:27:27,244 [qtp1501513951-23] INFO [com.liwei.shiro.realm.MyRealm] - liwei , User{id=1, username='liwei', password='be78263da332dc2c7005f7551d7e57cd', nickname='李威888888', status=1} 2016-09-21 09:27:27,244 [qtp1501513951-23] INFO [com.liwei.shiro.realm.MyRealm] - 清除授权时候的缓存 2016-09-21 09:27:27,244 [qtp1501513951-23] INFO [com.liwei.shiro.realm.MyRealm] - User{id=1, username='liwei', password='be78263da332dc2c7005f7551d7e57cd', nickname='李威888888', status=1} , org.apache.shiro.authz.SimpleAuthorizationInfo@616d8742

我们可以看出:

授权时候的 key 值是一个对象 认证时候的 key 值是用户名

aop:aspectj-autoproxy/ 的作用和 @EnableAspectJAutoProxy 是一样的。

上面我们仅仅只是对 Realm 中的认证和授权方法使用了缓存技术。 下面,我们让 UserService 这个实现类通过 Spring AOP 的方式实现缓存,避免同样的数据多次访问数据库。。 目标:查询列表的方法添加了缓存。

添加了缓存以后,相应的增加、删除、修改的方法要清空缓存。

Spring MVC 使用 AOP 拦截控制器层须要注意的事项: http://blog.csdn.net/pyxly1314/article/details/47152827

System.out.println("------ 方法签名 ------ " + pjp.getSignature()); System.out.println("------ 方法参数 ------ " + Arrays.toString(pjp.getArgs())); System.out.println("------ 方法名 ------ " + pjp.getSignature().getName()); System.out.println("------ 方法所在的类的全类名 ------ " + pjp.getSignature().getDeclaringTypeName());

为本项目添加事务支持,此时已经产生了抛出了异常,但是数据一致性没有保证。

shiro-project's People

Contributors

liweiwei1419 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.