mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
jmx support
This commit is contained in:
@@ -7,7 +7,7 @@ import java.util.Set;
|
||||
|
||||
import com.alibaba.druid.wall.spi.WallVisitorUtils;
|
||||
|
||||
public class WallConfig {
|
||||
public class WallConfig implements WallConfigMBean {
|
||||
|
||||
private boolean noneBaseStatementAllow = false;
|
||||
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.alibaba.druid.wall;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface WallConfigMBean {
|
||||
|
||||
boolean isInited();
|
||||
|
||||
String getDir();
|
||||
|
||||
void setDir(String dir);
|
||||
|
||||
void init();
|
||||
|
||||
void loadConfig(String dir);
|
||||
|
||||
boolean isNoneBaseStatementAllow();
|
||||
|
||||
void setNoneBaseStatementAllow(boolean noneBaseStatementAllow);
|
||||
|
||||
boolean isTruncateAllow();
|
||||
|
||||
void setTruncateAllow(boolean truncateAllow);
|
||||
|
||||
boolean isSelelctAllow();
|
||||
|
||||
void setSelelctAllow(boolean selelctAllow);
|
||||
|
||||
boolean isSelectIntoAllow();
|
||||
|
||||
void setSelectIntoAllow(boolean selectIntoAllow);
|
||||
|
||||
boolean isSelectIntoOutfileAllow();
|
||||
|
||||
void setSelectIntoOutfileAllow(boolean selectIntoOutfileAllow);
|
||||
|
||||
boolean isSelectUnionCheck();
|
||||
|
||||
void setSelectUnionCheck(boolean selectUnionCheck);
|
||||
|
||||
boolean isSelectWhereAlwayTrueCheck();
|
||||
|
||||
void setSelectWhereAlwayTrueCheck(boolean selectWhereAlwayTrueCheck);
|
||||
|
||||
boolean isSelectHavingAlwayTrueCheck();
|
||||
|
||||
void setSelectHavingAlwayTrueCheck(boolean selectHavingAlwayTrueCheck);
|
||||
|
||||
boolean isDeleteAllow();
|
||||
|
||||
void setDeleteAllow(boolean deleteAllow);
|
||||
|
||||
boolean isDeleteWhereAlwayTrueCheck();
|
||||
|
||||
void setDeleteWhereAlwayTrueCheck(boolean deleteWhereAlwayTrueCheck);
|
||||
|
||||
boolean isUpdateAllow();
|
||||
|
||||
void setUpdateAllow(boolean updateAllow);
|
||||
|
||||
boolean isUpdateWhereAlayTrueCheck();
|
||||
|
||||
void setUpdateWhereAlayTrueCheck(boolean updateWhereAlayTrueCheck);
|
||||
|
||||
boolean isInsertAllow();
|
||||
|
||||
void setInsertAllow(boolean insertAllow);
|
||||
|
||||
boolean isMergeAllow();
|
||||
|
||||
void setMergeAllow(boolean mergeAllow);
|
||||
|
||||
boolean isMultiStatementAllow();
|
||||
|
||||
void setMultiStatementAllow(boolean multiStatementAllow);
|
||||
|
||||
boolean isSchemaCheck();
|
||||
|
||||
void setSchemaCheck(boolean schemaCheck);
|
||||
|
||||
boolean isTableCheck();
|
||||
|
||||
void setTableCheck(boolean tableCheck);
|
||||
|
||||
boolean isFunctionCheck();
|
||||
|
||||
void setFunctionCheck(boolean functionCheck);
|
||||
|
||||
boolean isVariantCheck();
|
||||
|
||||
void setVariantCheck(boolean variantCheck);
|
||||
|
||||
boolean isObjectCheck();
|
||||
|
||||
void setObjectCheck(boolean objectCheck);
|
||||
|
||||
boolean isCommentAllow();
|
||||
|
||||
void setCommentAllow(boolean commentAllow);
|
||||
|
||||
Set<String> getPermitFunctions();
|
||||
|
||||
Set<String> getPermitTables();
|
||||
|
||||
Set<String> getPermitSchemas();
|
||||
|
||||
Set<String> getPermitVariants();
|
||||
|
||||
Set<String> getPermitObjects();
|
||||
|
||||
Set<String> getReadOnlyTables();
|
||||
|
||||
boolean isPermitObjects(String name);
|
||||
|
||||
boolean isPermitSchema(String name);
|
||||
|
||||
boolean isPermitFunction(String name);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.alibaba.druid.wall;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface WallFilterMBean {
|
||||
|
||||
String getDbType();
|
||||
@@ -15,4 +17,6 @@ public interface WallFilterMBean {
|
||||
boolean isInited();
|
||||
|
||||
void clearProviderCache();
|
||||
|
||||
Set<String> getProviderWhiteList();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@@ -35,6 +36,12 @@ public class SpringFilterTest extends TestCase {
|
||||
|
||||
DataSource dataSource = (DataSource) context.getBean("dataSource");
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("select 1");
|
||||
stmt.execute("select 2");
|
||||
stmt.execute("select 1");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
|
||||
TestFilter filter = (TestFilter) context.getBean("test-filter");
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2011 Alibaba.com All right reserved. This software is the
|
||||
* confidential and proprietary information of Alibaba.com ("Confidential
|
||||
* Information"). You shall not disclose such Confidential Information and shall
|
||||
* use it only in accordance with the terms of the license agreement you entered
|
||||
* into with Alibaba.com.
|
||||
*/
|
||||
package com.alibaba.druid.spring;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
public class MBeanServerFactoryBean implements FactoryBean {
|
||||
|
||||
public MBeanServer getObject() throws Exception {
|
||||
return ManagementFactory.getPlatformMBeanServer();
|
||||
}
|
||||
|
||||
public Class<?> getObjectType() {
|
||||
return ManagementFactory.getPlatformMBeanServer().getClass();
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,8 +22,8 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/
|
||||
<property name="config" ref="wall-filter-config" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
|
||||
destroy-method="close">
|
||||
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
|
||||
init-method="init" destroy-method="close">
|
||||
<property name="url">
|
||||
<value>jdbc:mock:</value>
|
||||
</property>
|
||||
@@ -42,4 +42,20 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="mbeanServer" class="com.alibaba.druid.spring.MBeanServerFactoryBean" />
|
||||
|
||||
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"
|
||||
lazy-init="false">
|
||||
<property name="beans">
|
||||
<map>
|
||||
<entry key="com.alibaba.druid.test:type=WallConfig"
|
||||
value-ref="wall-filter-config" />
|
||||
<entry key="com.alibaba.druid.test:type=WallFilter"
|
||||
value-ref="wall-filter" />
|
||||
<entry key="com.alibaba.druid.test:type=StatFilter"
|
||||
value-ref="stat-filter" />
|
||||
</map>
|
||||
</property>
|
||||
<property name="server" ref="mbeanServer" />
|
||||
</bean>
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user