| | |
| | | package com.doumee.config.shiro; |
| | | |
| | | import org.apache.coyote.http11.AbstractHttp11Protocol; |
| | | import org.apache.shiro.mgt.SecurityManager; |
| | | import org.apache.shiro.session.mgt.SessionManager; |
| | | import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; |
| | |
| | | import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer; |
| | | import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; |
| | | import org.springframework.boot.web.servlet.server.ServletWebServerFactory; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| | | |
| | | import javax.servlet.Filter; |
| | | import java.util.HashMap; |
| | | import java.io.Serializable; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Shiro配置 |
| | | * @author Eva.Caesar Liu |
| | | * @date 2023/02/14 11:14 |
| | | * @date 2023/04/17 12:11 |
| | | */ |
| | | @Configuration |
| | | public class ShiroConfig { |
| | |
| | | @Autowired |
| | | private ShiroRealm shiroRealm; |
| | | |
| | | @Bean("sessionRedisTemplate") |
| | | public RedisTemplate<Object, Serializable> sessionRedisTemplate(RedisConnectionFactory redisConnectionFactory) { |
| | | RedisTemplate<Object, Serializable> redisTemplate = new RedisTemplate<>(); |
| | | redisTemplate.setConnectionFactory(redisConnectionFactory); |
| | | // 默认序列化方式 |
| | | redisTemplate.setDefaultSerializer(new StringRedisSerializer()); |
| | | // 值序列化方式 |
| | | ShiroSessionSerializer serializer = new ShiroSessionSerializer(); |
| | | redisTemplate.setValueSerializer(serializer); |
| | | redisTemplate.setHashValueSerializer(serializer); |
| | | redisTemplate.afterPropertiesSet(); |
| | | return redisTemplate; |
| | | } |
| | | |
| | | @Bean |
| | | public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { |
| | | DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator(); |
| | |
| | | public SessionManager sessionManager() { |
| | | ShiroSessionManager sessionManager = new ShiroSessionManager(); |
| | | sessionManager.setSessionDAO(shiroSessionDAO); |
| | | sessionManager.setGlobalSessionTimeout(sessionExpireTime*1000); |
| | | // 删除失效的session |
| | | sessionManager.setDeleteInvalidSessions(true); |
| | | return sessionManager; |
| | | } |
| | | |
| | |
| | | ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); |
| | | shiroFilterFactoryBean.setSecurityManager(securityManager); |
| | | Map<String, String> map = new LinkedHashMap<>(); |
| | | // 路径拦截配置 |
| | | // 路径拦截配置 |
| | | map.put("/system/dictData/companyUserRules","anon"); |
| | | map.put("/system/login", "anon"); |
| | |
| | | public ShiroRealm getShiroRealm () { |
| | | shiroRealm.setCredentialsMatcher(shiroCredentialsMatcher); |
| | | return shiroRealm; |
| | | } |
| | | |
| | | private int maxUploadSizeInMb = 10 * 1024 * 1024; // 10 MB |
| | | |
| | | @Bean |
| | | public TomcatServletWebServerFactory tomcatEmbedded() { |
| | | |
| | | TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); |
| | | tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> { |
| | | // connector other settings... |
| | | // configure maxSwallowSize |
| | | if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) { |
| | | // -1 means unlimited, accept bytes |
| | | ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1); |
| | | } |
| | | }); |
| | | return tomcat; |
| | | } |
| | | } |