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"));
}
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"));
}
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"));
}
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"));
}
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;
}
Aggregations