Search in sources :

Example 11 with StatViewServlet

use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.

the class StatViewSerlvetTest_allow method test_allow_3.

public void test_allow_3() throws Exception {
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_ALLOW, "128.242.127.2/24");
    StatViewServlet servlet = new StatViewServlet();
    servlet.init(servletConfig);
    for (int i = 1; i <= 255; ++i) {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setRemoteAddr("128.242.127." + i);
        Assert.assertTrue(servlet.isPermittedRequest(request));
    }
    Assert.assertFalse(servlet.isPermittedRequest("128.242.128.1"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Example 12 with StatViewServlet

use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.

the class StatViewSerlvetTest_allow method test_allow.

public void test_allow() throws Exception {
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_ALLOW, "128.242.127.2");
    StatViewServlet servlet = new StatViewServlet();
    servlet.init(servletConfig);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("128.242.127.2");
    Assert.assertTrue(servlet.isPermittedRequest(request));
    Assert.assertFalse(servlet.isPermittedRequest("128.242.127.3"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Example 13 with StatViewServlet

use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.

the class StatViewSerlvetTest_allow method test_allow_4.

public void test_allow_4() throws Exception {
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_ALLOW, "128.242.127.2/24");
    servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_DENY, "128.242.127.4");
    StatViewServlet servlet = new StatViewServlet();
    servlet.init(servletConfig);
    Assert.assertTrue(servlet.isPermittedRequest("128.242.127.1"));
    Assert.assertTrue(servlet.isPermittedRequest("128.242.127.2"));
    Assert.assertTrue(servlet.isPermittedRequest("128.242.127.3"));
    Assert.assertFalse(servlet.isPermittedRequest("128.242.127.4"));
    Assert.assertTrue(servlet.isPermittedRequest("128.242.127.5"));
}
Also used : MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Example 14 with StatViewServlet

use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.

the class StatViewSerlvetTest_allow method test_allow_2.

public void test_allow_2() throws Exception {
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_ALLOW, "128.242.127.2,,, ");
    StatViewServlet servlet = new StatViewServlet();
    servlet.init(servletConfig);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("128.242.127.2");
    Assert.assertTrue(servlet.isPermittedRequest(request));
    Assert.assertFalse(servlet.isPermittedRequest("128.242.127.3"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Example 15 with StatViewServlet

use of com.alibaba.druid.support.http.StatViewServlet in project benchmark by seelunzi.

the class DruidConfiguration method druidServlet.

@Bean
public ServletRegistrationBean druidServlet() {
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
    // 添加初始化参数:initParams
    // 白名单:
    // servletRegistrationBean.addInitParameter("allow","127.0.0.1");
    // IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.
    // servletRegistrationBean.addInitParameter("deny","192.168.1.73");
    // 登录查看信息的账号密码.
    servletRegistrationBean.addInitParameter("loginUsername", "admin");
    servletRegistrationBean.addInitParameter("loginPassword", "admin");
    // 是否能够重置数据.
    servletRegistrationBean.addInitParameter("resetEnable", "true");
    return servletRegistrationBean;
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

StatViewServlet (com.alibaba.druid.support.http.StatViewServlet)23 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)13 Bean (org.springframework.context.annotation.Bean)13 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)11 MockServletConfig (org.springframework.mock.web.MockServletConfig)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 HashMap (java.util.HashMap)2 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)2 DruidStatProperties (com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties)1 ServletListenerRegistrationBean (org.springframework.boot.web.servlet.ServletListenerRegistrationBean)1