From ec0518f7c180f058e55badf214e3a86db60c9c5b Mon Sep 17 00:00:00 2001 From: MaxKey Date: Fri, 20 Aug 2021 12:36:10 +0800 Subject: [PATCH] v 2.9.0 & maxkey-boot-monitor v 2.9.0 & maxkey-boot-monitor --- .../java/org/maxkey/entity/GroupMember.java | 2 +- maxkey-webs/maxkey-boot-monitor/build.gradle | 30 +++++++++++++ maxkey-webs/maxkey-boot-monitor/readme.txt | 7 +++ .../boot/monitor/MaxKeyBootMonitor.java | 31 +++++++++++++ .../monitor/MonitorSecurityConfigurer.java | 45 +++++++++++++++++++ .../src/main/resources/application.properties | 26 +++++++++++ .../src/main/resources/log4j2.xml | 32 +++++++++++++ 7 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 maxkey-webs/maxkey-boot-monitor/build.gradle create mode 100644 maxkey-webs/maxkey-boot-monitor/readme.txt create mode 100644 maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MaxKeyBootMonitor.java create mode 100644 maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MonitorSecurityConfigurer.java create mode 100644 maxkey-webs/maxkey-boot-monitor/src/main/resources/application.properties create mode 100644 maxkey-webs/maxkey-boot-monitor/src/main/resources/log4j2.xml diff --git a/maxkey-core/src/main/java/org/maxkey/entity/GroupMember.java b/maxkey-core/src/main/java/org/maxkey/entity/GroupMember.java index b0917d435..c64e3ca90 100644 --- a/maxkey-core/src/main/java/org/maxkey/entity/GroupMember.java +++ b/maxkey-core/src/main/java/org/maxkey/entity/GroupMember.java @@ -30,7 +30,7 @@ import javax.persistence.Table; /* ID varchar(40) not null, APPROLEID varchar(40) null, - UID varchar(40) null + USERID varchar(40) null constraint PK_ROLES primary key clustered (ID) */ @Entity diff --git a/maxkey-webs/maxkey-boot-monitor/build.gradle b/maxkey-webs/maxkey-boot-monitor/build.gradle new file mode 100644 index 000000000..04ca0bae8 --- /dev/null +++ b/maxkey-webs/maxkey-boot-monitor/build.gradle @@ -0,0 +1,30 @@ +description = "maxkey-boot-monitor" + +//add support for Java +apply plugin: 'java' + +dependencies { + implementation project(":maxkey-common") + + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: "${springBootVersion}" + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: "${springBootVersion}" + implementation group: 'org.springframework.security', name: 'spring-security-config', version: '5.5.1' + + implementation group: 'de.codecentric', name: 'spring-boot-admin-server', version: "${springbootadminVersion}" + implementation group: 'de.codecentric', name: 'spring-boot-admin-server-ui', version: "${springbootadminVersion}" + implementation group: 'de.codecentric', name: 'spring-boot-admin-starter-server', version: "${springbootadminVersion}" + + implementation group: 'org.thymeleaf', name: 'thymeleaf', version: "${thymeleafVersion}" + implementation group: 'org.thymeleaf', name: 'thymeleaf-spring5', version: "${thymeleafVersion}" + + implementation group: 'io.projectreactor.netty', name: 'reactor-netty', version: "${reactornettyVersion}" + implementation group: 'io.projectreactor.netty', name: 'reactor-netty-http', version: "${reactornettyVersion}" + implementation group: 'io.projectreactor.netty', name: 'reactor-netty-core', version: "${reactornettyVersion}" + implementation group: 'io.projectreactor.addons', name: 'reactor-extra', version: "${reactorextraVersion}" + + implementation group: 'io.netty', name: 'netty-all', version: "${nettyVersion}" + implementation group: 'com.hazelcast', name: 'hazelcast', version: "${hazelcastVersion}" + implementation group: 'jakarta.annotation', name: 'jakarta.annotation-api', version: "${jakartaannotationVersion}" + implementation group: 'org.attoparser', name: 'attoparser', version: "${attoparserVersion}" + implementation group: 'org.unbescape', name: 'unbescape', version: "${unbescapeVersion}" +} \ No newline at end of file diff --git a/maxkey-webs/maxkey-boot-monitor/readme.txt b/maxkey-webs/maxkey-boot-monitor/readme.txt new file mode 100644 index 000000000..ecef53460 --- /dev/null +++ b/maxkey-webs/maxkey-boot-monitor/readme.txt @@ -0,0 +1,7 @@ +maxkey monitor service + +spring-boot-admin-server +version 2.5.0 +Admin UI for administration of spring boot applications +https://github.com/codecentric/spring-boot-admin +Apache-2.0 License diff --git a/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MaxKeyBootMonitor.java b/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MaxKeyBootMonitor.java new file mode 100644 index 000000000..fb4a3491c --- /dev/null +++ b/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MaxKeyBootMonitor.java @@ -0,0 +1,31 @@ +package org.maxkey.boot.monitor; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.Configuration; + +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; + +import de.codecentric.boot.admin.server.config.EnableAdminServer; + +@Configuration +@EnableAdminServer +@SpringBootApplication( + exclude={ + RedisAutoConfiguration.class, + DruidDataSourceAutoConfigure.class, + DataSourceAutoConfiguration.class +}) +public class MaxKeyBootMonitor { + + private static final Logger _logger = LoggerFactory.getLogger(MaxKeyBootMonitor.class); + + public static void main(String[] args) { + _logger.info("Start MaxKeyBootMonitor ..."); + SpringApplication.run(MaxKeyBootMonitor.class, args); + } +} diff --git a/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MonitorSecurityConfigurer.java b/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MonitorSecurityConfigurer.java new file mode 100644 index 000000000..8b8e3902c --- /dev/null +++ b/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MonitorSecurityConfigurer.java @@ -0,0 +1,45 @@ +package org.maxkey.boot.monitor; + +import org.springframework.context.annotation.Configuration; +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; +import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; + +@Configuration +@EnableWebSecurity +public class MonitorSecurityConfigurer extends WebSecurityConfigurerAdapter { + + + @Override + protected void configure(HttpSecurity http) throws Exception { + // 登录成功处理类 + SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); + successHandler.setTargetUrlParameter("redirectTo"); + successHandler.setDefaultTargetUrl("/"); + + http.authorizeRequests() + //无需认证 + .antMatchers( + "/login", //登录页面 + "/assets/**", //静态文件允许访问 + "/actuator/**", //springboot-admin监控的请求 + "/instances/**" //springboot-admin监控的实例信息请求 + ).permitAll() + //其他所有请求需要登录 + .anyRequest().authenticated() + //登录 + .and().formLogin().loginPage("/login").successHandler(successHandler) + //登出 + .and().logout().logoutUrl("/logout").logoutSuccessUrl("/login") + .and().httpBasic() + .and().csrf() + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) + .ignoringAntMatchers( + "/instances", + "/actuator/**" + ); + + } +} diff --git a/maxkey-webs/maxkey-boot-monitor/src/main/resources/application.properties b/maxkey-webs/maxkey-boot-monitor/src/main/resources/application.properties new file mode 100644 index 000000000..f14b99b55 --- /dev/null +++ b/maxkey-webs/maxkey-boot-monitor/src/main/resources/application.properties @@ -0,0 +1,26 @@ +############################################################################ +# Copyright [2021] [MaxKey of copyright http://www.maxkey.top] +# +# 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. +############################################################################ +#MaxKey Title and Version # +############################################################################ +application.title=MaxKey +spring.application.name=maxkey-boot-admin-server +application.formatted-version=v2.9.0 GA + +server.port=9528 + +spring.security.user.name=monitor +spring.security.user.password=maxkey +spring.security.basic.enabled=false \ No newline at end of file diff --git a/maxkey-webs/maxkey-boot-monitor/src/main/resources/log4j2.xml b/maxkey-webs/maxkey-boot-monitor/src/main/resources/log4j2.xml new file mode 100644 index 000000000..8e87a7f77 --- /dev/null +++ b/maxkey-webs/maxkey-boot-monitor/src/main/resources/log4j2.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- GitLab