Shiro 标签在layui页面不生效 附上ShiroConfig整体的代码 ShiroConfig配置需要增加
@Bean public ShiroDialect shiroDialect(){ return new ShiroDialect(); }
package com.system.config; import at.pollux.thymeleaf.shiro.dialect.ShiroDialect; import com.qh.system.shiro.ShiroLoginFilter; import com.qh.system.shiro.UserRealm; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.session.SessionListener; import org.apache.shiro.session.mgt.SessionManager; import org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator; import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; import org.apache.shiro.spring.web.ShiroFilterFactoryBean; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; import org.apache.shiro.web.servlet.SimpleCookie; import org.apache.shiro.web.session.mgt.DefaultWebSessionManager; import org.crazycake.shiro.RedisCacheManager; import org.crazycake.shiro.RedisManager; import org.crazycake.shiro.RedisSessionDAO; import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.servlet.Filter; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; /** * @description:shiro配置 */ @Configuration public class ShiroConfig { @Autowired private RedisProperties redisProperties; /** * Filter工厂,设置对应的过滤条件和跳转条件 * @return ShiroFilterFactoryBean */ @Bean public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager); Map<String, Filter> filtersMap = new LinkedHashMap<>(); filtersMap.put("shiroLoginFilter", shiroLoginFilter()); shiroFilterFactoryBean.setFilters(filtersMap); shiroFilterFactoryBean.setLoginUrl("/login"); shiroFilterFactoryBean.setSuccessUrl("/index"); shiroFilterFactoryBean.setUnauthorizedUrl("/403"); LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilterFactoryBean; } @Bean("shiroLoginFilter") public ShiroLoginFilter shiroLoginFilter(){ return new ShiroLoginFilter(); } @Bean public ShiroDialect shiroDialect(){ return new ShiroDialect(); } /** * 将自己的验证方式加入容器 * @return MyShiroRealm */ @Bean public UserRealm userRealm(){ return new UserRealm(); } /** * RedisSessionDAO shiro sessionDao层的实现 通过redis, 使用的是shiro-redis开源插件 * @return RedisSessionDAO */ @Bean public RedisSessionDAO redisSessionDAO() { RedisSessionDAO redisSessionDAO = new RedisSessionDAO(); redisSessionDAO.setRedisManager(redisManager()); redisSessionDAO.setSessionIdGenerator(sessionIdGenerator()); redisSessionDAO.setExpire(1800); return redisSessionDAO; } /** * Session ID 生成器 * @return JavaUuidSessionIdGenerator */ @Bean public JavaUuidSessionIdGenerator sessionIdGenerator() { return new JavaUuidSessionIdGenerator(); } /** * 自定义sessionManager * @return SessionManager */ @Bean public SessionManager sessionManager() { DefaultWebSessionManager sessionManager = new DefaultWebSessionManager(); Collection<SessionListener> listeners = new ArrayList<SessionListener>(); listeners.add(new BDSessionListener()); sessionManager.setSessionListeners(listeners); sessionManager.setSessionDAO(redisSessionDAO()); //去掉地址栏中的sessionId sessionManager.setSessionIdUrlRewritingEnabled(false); return sessionManager; } /** * 配置shiro redisManager, 使用的是shiro-redis开源插件 * @return RedisManager */ private RedisManager redisManager() { RedisManager redisManager = new RedisManager(); String hostProt=redisProperties.getHost()+":"+redisProperties.getPort(); String password=redisProperties.getPassword(); redisManager.setHost(hostProt); // redisManager.setPort(6379); // redisManager.setExpire(1800);// 配置缓存过期时间 redisManager.setTimeout(18000); if(StringUtils.isNotBlank(password)){ redisManager.setPassword(password); } return redisManager; } /** * cacheManager 缓存 redis实现, 使用的是shiro-redis开源插件 * @return RedisCacheManager */ @Bean public RedisCacheManager rediscacheManager() { RedisCacheManager redisCacheManager = new RedisCacheManager(); redisCacheManager.setRedisManager(redisManager()); // 必须要设置主键名称,shiro-redis 插件用过这个缓存用户信息 redisCacheManager.setPrincipalIdFieldName("userId"); return redisCacheManager; } /** * description: 权限管理,配置主要是Realm的管理认证 * * @return SecurityManager */ @Bean public SecurityManager securityManager() { DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); securityManager.setRealm(userRealm()); // 自定义session管理 使用redis securityManager.setSessionManager(sessionManager()); // 自定义缓存实现 使用redis securityManager.setCacheManager(rediscacheManager()); return securityManager; } /* * 开启Shiro的注解(如@RequiresRoles,@RequiresPermissions),需借助SpringAOP扫描使用Shiro注解的类,并在必要时进行安全逻辑验证 * 配置以下两个bean(DefaultAdvisorAutoProxyCreator(可选)和AuthorizationAttributeSourceAdvisor)即可实现此功能 */ @Bean public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() { DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); advisorAutoProxyCreator.setProxyTargetClass(true); return advisorAutoProxyCreator; } @Bean public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor(); authorizationAttributeSourceAdvisor.setSecurityManager(securityManager); return authorizationAttributeSourceAdvisor; } @Bean public SimpleCookie cookie() { // cookie的name,对应的默认是 JSESSIONID SimpleCookie cookie = new SimpleCookie("SHARE_JSESSIONID"); cookie.setHttpOnly(true); // path为 / 用于多个系统共享 JSESSIONID cookie.setPath("/"); return cookie; } public static final LinkedHashMap<String,String> filterChainDefinitionMap = new LinkedHashMap<>(); public static final String anon = "anon"; //免登录资源 public static final String logout = "logout"; public static final String authc = "authc"; //定义拦截链 static{ filterChainDefinitionMap.put("/favicon.ico", anon); filterChainDefinitionMap.put("/css/**", anon); filterChainDefinitionMap.put("/js/**", anon); filterChainDefinitionMap.put("/fonts/**", anon); filterChainDefinitionMap.put("/images/**", anon); filterChainDefinitionMap.put("/lib/**", anon); filterChainDefinitionMap.put("/druid/**", anon); filterChainDefinitionMap.put("/upload/**", anon); filterChainDefinitionMap.put("/files/**", anon); filterChainDefinitionMap.put("/test", anon); //测试用 filterChainDefinitionMap.put("/test1", anon); //测试用 filterChainDefinitionMap.put("/**", authc); } /* 此项目使用 shiro 场景为前后端分离项目,这里先注释掉,统一异常处理已在 GlobalExceptionHand.java 中实现 */ /** * create by: leigq * description: 异常处理, 详见:https://www.cnblogs.com/libra0920/p/6289848.html * create time: 2019/7/1 10:28 * @return SimpleMappingExceptionResolver */ // @Bean(name = "simpleMappingExceptionResolver") // public SimpleMappingExceptionResolver createSimpleMappingExceptionResolver() { // SimpleMappingExceptionResolver r = new SimpleMappingExceptionResolver(); // Properties mappings = new Properties(); // mappings.setProperty("DatabaseException", "databaseError");//数据库异常处理 // mappings.setProperty("UnauthorizedException", "/user/403"); // r.setExceptionMappings(mappings); // None by default // r.setDefaultErrorView("error"); // No default // r.setExceptionAttribute("exception"); // Default is "exception" // //r.setWarnLogCategory("example.MvcLogger"); // No default // return r; // } }
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算