摘要:目前的控制臺(tái)依然存在阿里云的廣告,本文通過過濾器將廣告文本攔截。定位問題產(chǎn)生廣告的文件在。查看源碼可知是方法進(jìn)行植入,由方法調(diào)用。
目前druid-1.1.14的web控制臺(tái)依然存在阿里云的廣告,本文通過過濾器將廣告文本攔截。
定位問題產(chǎn)生廣告的JS文件在 druid-1.1.14.jar/support/http/resources/js/common.js。
查看源碼可知是buildFooter方法進(jìn)行植入,由init方法調(diào)用。
解決問題/** * Druid的配置類 * * @author BBF */ @Configuration @AutoConfigureAfter(DruidDataSourceAutoConfigure.class) public class DruidConfig { /** * 帶有廣告的common.js全路徑,druid-1.1.14 */ private static final String FILE_PATH = "support/http/resources/js/common.js"; /** * 原始腳本,觸發(fā)構(gòu)建廣告的語句 */ private static final String ORIGIN_JS = "this.buildFooter();"; /** * 替換后的腳本 */ private static final String NEW_JS = "http://this.buildFooter();"; /** * 去除Druid監(jiān)控頁面的廣告 * * @param properties DruidStatProperties屬性集合 * @return {@link org.springframework.boot.web.servlet.FilterRegistrationBean} */ @Bean @ConditionalOnWebApplication @ConditionalOnProperty(name = "spring.datasource.druid.stat-view-servlet.enabled", havingValue = "true") public FilterRegistrationBeanremoveDruidAdFilter( DruidStatProperties properties) throws IOException { // 獲取web監(jiān)控頁面的參數(shù) DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); // 提取common.js的配置路徑 String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*"; String commonJsPattern = pattern.replaceAll("*", "js/common.js"); // 獲取common.js String text = Utils.readFromResource(FILE_PATH); // 屏蔽 this.buildFooter(); 不構(gòu)建廣告 final String newJs = text.replace(ORIGIN_JS, NEW_JS); FilterRegistrationBean registration = new FilterRegistrationBean<>(); registration.setFilter(new RemoveAdFilter(newJs)); registration.addUrlPatterns(commonJsPattern); return registration; } /** * 刪除druid的廣告過濾器 * * @author BBF */ private class RemoveAdFilter implements Filter { private final String newJs; public RemoveAdFilter(String newJS) { this.newJs = newJS; } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { chain.doFilter(request, response); // 重置緩沖區(qū),響應(yīng)頭不會(huì)被重置 response.resetBuffer(); response.getWriter().write(newJs); } } }
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/73565.html
摘要:淘寶定制基于,是國內(nèi)第一個(gè)優(yōu)化定制且開源的服務(wù)器版虛擬機(jī)。數(shù)據(jù)庫開源數(shù)據(jù)庫是基于官方版本的一個(gè)分支,由阿里云數(shù)據(jù)庫團(tuán)隊(duì)維護(hù),目前也應(yīng)用于阿里巴巴集團(tuán)業(yè)務(wù)以及阿里云數(shù)據(jù)庫服務(wù)。淘寶服務(wù)器是由淘寶網(wǎng)發(fā)起的服務(wù)器項(xiàng)目。 Java JAVA 研發(fā)框架 SOFAStack SOFAStack(Scalable Open Financial Architecture Stack)是用于快速構(gòu)建金融...
摘要:不知道是不是今日頭條進(jìn)行了系統(tǒng)升級,標(biāo)題居然可以寫這么長一串文字對于一個(gè)想在阿里云服務(wù)器上搭建網(wǎng)站的小白解決環(huán)境配置成了首要問題,手把手教會(huì)環(huán)境配置不知道有沒有和我一樣,同在網(wǎng)站建設(shè)方面懷揣著一個(gè)小目標(biāo)的同路人。 不知道是不是今日頭條進(jìn)行了系統(tǒng)升級,標(biāo)題居然可以寫這么長一串文字:對于一個(gè)想在阿里云ECS服務(wù)器上搭建網(wǎng)站的小白?解決環(huán)境配置成了首要問題,手把手教會(huì)PHP環(huán)境配置! 不知道...
閱讀 1792·2023-04-26 01:41
閱讀 3090·2021-11-23 09:51
閱讀 2751·2021-10-09 09:43
閱讀 9073·2021-09-22 15:13
閱讀 2469·2021-09-07 09:59
閱讀 2638·2019-08-30 15:44
閱讀 1145·2019-08-30 12:45
閱讀 2630·2019-08-30 12:43