2019/9/6 spring实战第二章,shiro权限加密,授权

《spring实战》第二章:

装配bean的三种方式:

  • 隐式bean发现机制和自动装配
  • xml显示装配
  • java中显示装配

 

shiro权限登录次数限制

ehcache中,配置登录次数的限制

继承HashedCredentialsMatcher,重写凭证匹配方法。在该方法中,检验ehcache缓存中的登录错误次数,并记录数据库或者记录缓存

 

shiro授权角色权限

1.需要在shiroconfiguration里面注册入两个bean,启用注解授权验证

    @Bean
    public static LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
        return new LifecycleBeanPostProcessor();
    }

    @Bean
    public static DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator(){
        return new DefaultAdvisorAutoProxyCreator();
    }

2.在realm中重写doGetAuthorizationInfo方法,加入authorizationInfo的相关角色和权限

 authorizationInfo.addRole("Admin");
 authorizationInfo.addStringPermission("/login/view");

3.权限已经加入相关的authorizationInfo,即可在相关的方法中用注解方式验证授权

    @RequiresRoles("Admin")
    @RequiresPermissions("/login/view")
    public String loginUser(User user){
    //TODO
    }
原文地址:https://www.cnblogs.com/xiaotianblog/p/11477183.html