diff --git a/README.md b/README.md index 58f6b2b..cd0f891 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ db.url=jdbc:mysql://:/monitor?prepStmtCacheSize=51 db.username=root db.password=root db.maxActive=500 + +####System Manager +manager.username=admin +manager.password=admin ``` `第三步`:打包运行项目 @@ -42,7 +46,7 @@ db.maxActive=500 target文件夹下生成的dubbo-monitor.war即为项目部署文件,将其放置到对应服务器目录下,启动服务器即可。例如:tomcat的webapps文件夹下。 `第四步`:访问项目 -启动web服务器后,访问地址:http://IP:[port]/dubbo-moniotor +启动web服务器后,访问地址:http://IP:[port]/dubbo-moniotor,采用配置文件中manager.username和manager.password设置值进行登录。 ## 服务提供端配置 diff --git a/pom.xml b/pom.xml index a2510b4..5f84059 100644 --- a/pom.xml +++ b/pom.xml @@ -210,6 +210,16 @@ spring-webmvc ${spring.version} + + org.springframework.security + spring-security-web + 3.2.8.RELEASE + + + org.springframework.security + spring-security-config + 3.2.8.RELEASE + org.apache.zookeeper zookeeper diff --git a/src/main/java/com/handu/open/dubbo/monitor/config/MonitorConfig.java b/src/main/java/com/handu/open/dubbo/monitor/config/MonitorConfig.java index 1e531f6..42303f5 100644 --- a/src/main/java/com/handu/open/dubbo/monitor/config/MonitorConfig.java +++ b/src/main/java/com/handu/open/dubbo/monitor/config/MonitorConfig.java @@ -28,7 +28,7 @@ */ @Configuration @ComponentScan(basePackages = {"com.handu.open.dubbo.monitor"}, includeFilters = {@ComponentScan.Filter(value = Service.class)}) -@Import({WebConfig.class, DubboConfig.class, MyBatisConfig.class}) +@Import({WebConfig.class, DubboConfig.class, MyBatisConfig.class, Security.class}) @PropertySource("classpath:/application.properties") public class MonitorConfig { } diff --git a/src/main/java/com/handu/open/dubbo/monitor/config/Security.java b/src/main/java/com/handu/open/dubbo/monitor/config/Security.java new file mode 100644 index 0000000..3408b86 --- /dev/null +++ b/src/main/java/com/handu/open/dubbo/monitor/config/Security.java @@ -0,0 +1,49 @@ +/** + * Copyright 2006-2015 handu.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.handu.open.dubbo.monitor.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + + +@Configuration +@EnableWebSecurity +public class Security extends WebSecurityConfigurerAdapter { + + @Autowired + Environment env; + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth.inMemoryAuthentication() + .withUser(env.getProperty("manager.username", "root")) + .password(env.getProperty("manager.password", "password")) + .roles("MANAGER"); + } + + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable() + .authorizeRequests() + .anyRequest().authenticated() + .and() + .httpBasic(); + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2879128..1d6c49e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -21,4 +21,8 @@ dubbo.protocol.port=6060 db.url=jdbc:mysql://127.0.0.1:3306/monitor?prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8 db.username=root db.password=root -db.maxActive=500 \ No newline at end of file +db.maxActive=500 + +# System Manager +manager.username=admin +manager.password=admin \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index b71edf9..fffd129 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -1,43 +1,53 @@ - Dubbo monitor - - - log4jConfigLocation - classpath:log4j.xml - - - org.springframework.web.util.Log4jConfigListener - - - - contextClass - - org.springframework.web.context.support.AnnotationConfigWebApplicationContext - - - - - contextConfigLocation - com.handu.open.dubbo.monitor.config.MonitorConfig - - - - org.springframework.web.context.ContextLoaderListener - - - - springServlet - org.springframework.web.servlet.DispatcherServlet - - contextConfigLocation - - - 1 - - - - springServlet - / - + Dubbo monitor + + + log4jConfigLocation + classpath:log4j.xml + + + org.springframework.web.util.Log4jConfigListener + + + + contextClass + + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + + contextConfigLocation + com.handu.open.dubbo.monitor.config.MonitorConfig + + + + org.springframework.web.context.ContextLoaderListener + + + + springServlet + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + + + 1 + + + + springServlet + / + + + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + + springSecurityFilterChain + /* + \ No newline at end of file