首页 > 其他分享 >Shiro配置类

Shiro配置类

时间:2023-01-31 19:11:38浏览次数:33  
标签:配置 hashedCredentialsMatcher org put import filterChainDefinitionMap shiroFilterF

import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.LinkedHashMap;
import java.util.Map;

@Configuration
public class ShiroConfig {

    @Bean
    public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
        shiroFilterFactoryBean.setSecurityManager(securityManager);
        shiroFilterFactoryBean.setLoginUrl("/login");
        shiroFilterFactoryBean.setSuccessUrl("/index");
        shiroFilterFactoryBean.setUnauthorizedUrl("/403");
        Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
        filterChainDefinitionMap.put("/css/**", "anon");
        filterChainDefinitionMap.put("/js/**", "anon");
        filterChainDefinitionMap.put("/fonts/**", "anon");
        filterChainDefinitionMap.put("/img/**", "anon");
        filterChainDefinitionMap.put("/druid/**", "anon");
        filterChainDefinitionMap.put("/logout", "logout");
        filterChainDefinitionMap.put("/", "anon");
        filterChainDefinitionMap.put("/**", "authc");
        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
        return shiroFilterFactoryBean;
    }

    @Bean
    public SecurityManager securityManager() {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        securityManager.setRealm(myShiroRealm());
        return securityManager;
    }

    @Bean
    public MyShiroRealm myShiroRealm() {
        MyShiroRealm myShiroRealm = new MyShiroRealm();
        myShiroRealm.setCredentialsMatcher(hashedCredentialsMatcher());
        return myShiroRealm;
    }

    @Bean
    public HashedCredentialsMatcher hashedCredentialsMatcher() {
        HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
        hashedCredentialsMatcher.setHashAlgorithmName("md5");
        hashedCredentialsMatcher.setHashIterations(2);
        return hashedCredentialsMatcher;
    }
}

写个

标签:配置,hashedCredentialsMatcher,org,put,import,filterChainDefinitionMap,shiroFilterF
From: https://www.cnblogs.com/stepforeward/p/17080223.html

相关文章

  • Ranger概述及安装配置
    0.前序希望拥有一个框架,可以管理大多数框架的授权,包括:hdfs的目录读写权限各种大数据框架中的标的权限,列级(字段)权限,甚至行级权限,函数权限(UDF)等相关资源的权限是否能帮......
  • Redis配置文件中各个配置项含义
    redis是一款开源的、高性能的键-值存储(key-valuestore),和memcached类似,redis常被称作是一款key-value内存存储系统或者内存数据库,同时由于它支持丰富的数据结构,又被称为一......
  • Jmeter学习:JDBC链接池配置
    功能:通过该元件,我们可以给数据源配置不同的连接池,供后续JDBC采样器使用。使用场景:该元件配置通常与JDBC采样器一同使用。Jmeter默认采用DBCP连接池。1.下载驱......
  • 配置之映射器说明
       ......
  • VS code 的 rust 开发环境配置
    本人在VScode环境中进行rust学习的编辑器配置。插件:  CodeSpellChecker  单词拼写检查    CodeLLDB  Debug工具  ErrorLens  行内错误提示......
  • 配置之别名优化
      ......
  • vite配置别名
    vite.config.tsimport{resolve}from"path";exportdefaultdefineConfig({resolve:{alias:{"@":resolve(__dirname,"./src"),//......
  • vue 不同路由模式,部署时,nginx的不同配置
    hash模式路由配置如下:location/{rootfont;indexindex.htmlindex.htm;}history模式路由配置如下:location/{rootfont;index......
  • spring 定时任务的 时间配置cron表达式
    单纯针对时间的设置规则org.springframework.scheduling.quartz.CronTriggerBean允许你更精确地控制任务的运行时间,只需要设置其cronExpression属性。一个cronExpression......
  • 002.前端项目发布(Nginx静态网站配置)
    1.在/root目录下增加web文件放置前端静态文件2.添加配置文件(/etc/nginx/conf.d/)web.confserver{listen80;#server_nameip;//ip就是公网ipserver_name域......