jiangping
2023-08-29 1812198cdb63b5b9da27c20e5606343b7ba73091
server/src/main/java/doumeemes/config/shiro/ShiroConfig.java
@@ -1,26 +1,29 @@
package doumeemes.config.shiro;
import doumeemes.task.ScheduleTool;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.mgt.SessionManager;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.util.ThreadContext;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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 2022/04/18 18:12
 * @date 2023/04/17 12:11
 */
@Configuration
public class ShiroConfig {
@@ -39,6 +42,20 @@
    @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() {
@@ -60,7 +77,6 @@
        securityManager.setRealm(shiroRealm);
        securityManager.setSessionManager(this.sessionManager());
        securityManager.setCacheManager(shiroCacheManager);
        ThreadContext.bind(securityManager);
        return securityManager;
    }
@@ -70,24 +86,17 @@
        shiroFilterFactoryBean.setSecurityManager(securityManager);
        Map<String, String> map = new LinkedHashMap<>();
        // 路径拦截配置
        map.put("/web/user/login", "anon");
        map.put("/public/uploadRichText", "anon");
        map.put("/system/login", "anon");
        map.put("/system/wxLogin", "anon");
        map.put("/system/wxAccountLogin", "anon");
        map.put("/system/initCompany", "anon");
        map.put("/system/logout", "anon");
        map.put("/common/captcha", "anon");
        map.put("/dingding/push", "anon");
//        map.put("/ext/workorderExt/freshStatistics", "anon");
        map.put("/dingding/jsapiTicket", "anon");
        map.put("/dingding/ddLogin", "anon");
        map.put("/dingding/getDingdingCorpId", "anon");
        map.put("/lingyang/login", "anon");
        map.put("/lingyang/loginDemo", "anon");
        map.put("/edgp/**", "anon");
        //放行 scratch 接口
        map.put("/web/scratch/**", "anon");
        // - 放行swagger
        map.put("/doc.html", "anon");
        map.put("/webjars/**", "anon");
        map.put("/template/**", "anon");
        map.put("/swagger-resources/**", "anon");
        map.put("/v2/api-docs/**", "anon");
        // - 其他接口统一拦截