init
This commit is contained in:
		| @ -0,0 +1,64 @@ | ||||
| package com.aizuda.snailjob.server.starter.filter; | ||||
|  | ||||
| import jakarta.servlet.*; | ||||
| import jakarta.servlet.http.HttpServletRequest; | ||||
| import jakarta.servlet.http.HttpServletResponse; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.nio.charset.StandardCharsets; | ||||
| import java.util.Base64; | ||||
|  | ||||
| public class ActuatorAuthFilter implements Filter { | ||||
|  | ||||
|     private final String username; | ||||
|     private final String password; | ||||
|  | ||||
|     public ActuatorAuthFilter(String username, String password) { | ||||
|         this.username = username; | ||||
|         this.password = password; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { | ||||
|         HttpServletRequest request = (HttpServletRequest) servletRequest; | ||||
|         HttpServletResponse response = (HttpServletResponse) servletResponse; | ||||
|  | ||||
|         // 获取 Authorization 头 | ||||
|         String authHeader = request.getHeader("Authorization"); | ||||
|  | ||||
|         if (authHeader == null || !authHeader.startsWith("Basic ")) { | ||||
|             // 如果没有提供 Authorization 或者格式不对,则返回 401 | ||||
|             response.setHeader("WWW-Authenticate", "Basic realm=\"realm\""); | ||||
|             response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         // 解码 Base64 编码的用户名和密码 | ||||
|         String base64Credentials = authHeader.substring("Basic ".length()); | ||||
|         byte[] credDecoded = Base64.getDecoder().decode(base64Credentials); | ||||
|         String credentials = new String(credDecoded, StandardCharsets.UTF_8); | ||||
|         String[] split = credentials.split(":"); | ||||
|         if (split.length != 2) { | ||||
|             response.setHeader("WWW-Authenticate", "Basic realm=\"realm\""); | ||||
|             response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); | ||||
|             return; | ||||
|         } | ||||
|         // 验证用户名和密码 | ||||
|         if (!username.equals(split[0]) && password.equals(split[1])) { | ||||
|             response.setHeader("WWW-Authenticate", "Basic realm=\"realm\""); | ||||
|             response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); | ||||
|             return; | ||||
|         } | ||||
|         // 如果认证成功,继续处理请求 | ||||
|         filterChain.doFilter(request, response); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void init(FilterConfig filterConfig) { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void destroy() { | ||||
|     } | ||||
|  | ||||
| } | ||||
| @ -0,0 +1,29 @@ | ||||
| package com.aizuda.snailjob.server.starter.filter; | ||||
|  | ||||
| import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
|  | ||||
| /** | ||||
|  * 权限安全配置 | ||||
|  * | ||||
|  * @author Lion Li | ||||
|  */ | ||||
| @Configuration | ||||
| public class SecurityConfig { | ||||
|  | ||||
|     @Value("${spring.boot.admin.client.username}") | ||||
|     private String username; | ||||
|     @Value("${spring.boot.admin.client.password}") | ||||
|     private String password; | ||||
|  | ||||
|     @Bean | ||||
|     public FilterRegistrationBean<ActuatorAuthFilter> actuatorFilterRegistrationBean() { | ||||
|         FilterRegistrationBean<ActuatorAuthFilter> registrationBean = new FilterRegistrationBean<>(); | ||||
|         registrationBean.setFilter(new ActuatorAuthFilter(username, password)); | ||||
|         registrationBean.addUrlPatterns("/actuator", "/actuator/*"); | ||||
|         return registrationBean; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @ -0,0 +1,19 @@ | ||||
| package org.dromara.snailjob; | ||||
|  | ||||
| import org.springframework.boot.SpringApplication; | ||||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||
|  | ||||
| /** | ||||
|  * SnailJob Server 启动程序 | ||||
|  * | ||||
|  * @author opensnail | ||||
|  * @date 2024-05-17 | ||||
|  */ | ||||
| @SpringBootApplication | ||||
| public class SnailJobServerApplication { | ||||
|  | ||||
|     public static void main(String[] args) { | ||||
|         SpringApplication.run(com.aizuda.snailjob.server.SnailJobServerApplication.class, args); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @ -0,0 +1,53 @@ | ||||
| spring: | ||||
|   datasource: | ||||
|     type: com.zaxxer.hikari.HikariDataSource | ||||
|     driver-class-name: com.mysql.cj.jdbc.Driver | ||||
|     url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true | ||||
|     username: root | ||||
|     password: root | ||||
|     hikari: | ||||
|       connection-timeout: 30000 | ||||
|       validation-timeout: 5000 | ||||
|       minimum-idle: 10 | ||||
|       maximum-pool-size: 20 | ||||
|       idle-timeout: 600000 | ||||
|       max-lifetime: 900000 | ||||
|       keepaliveTime: 30000 | ||||
|  | ||||
| --- # snail-job 服务端配置 | ||||
| snail-job: | ||||
|   # 拉取重试数据的每批次的大小 | ||||
|   retry-pull-page-size: 1000 | ||||
|   # 拉取重试数据的每批次的大小 | ||||
|   job-pull-page-size: 1000 | ||||
|   # 服务器端口 | ||||
|   server-port: 17888 | ||||
|   # 一个客户端每秒最多接收的重试数量指令 | ||||
|   limiter: 1000 | ||||
|   # 号段模式下步长配置 | ||||
|   step: 100 | ||||
|   # 日志保存时间(单位: day) | ||||
|   log-storage: 90 | ||||
|   # 回调配置 | ||||
|   callback: | ||||
|     #回调最大执行次数 | ||||
|     max-count: 288 | ||||
|     #间隔时间 | ||||
|     trigger-interval: 900 | ||||
|   # 重试每次拉取的次数 | ||||
|   retry-max-pull-count: 10 | ||||
|   # RPC通讯类型: netty,grpc | ||||
|   rpc-type: grpc | ||||
|  | ||||
| --- # 监控中心配置 | ||||
| spring.boot.admin.client: | ||||
|   # 增加客户端开关 | ||||
|   enabled: true | ||||
|   url: http://localhost:9090/admin | ||||
|   instance: | ||||
|     service-host-type: IP | ||||
|     metadata: | ||||
|       username: ${spring.boot.admin.client.username} | ||||
|       userpassword: ${spring.boot.admin.client.password} | ||||
|   username: @monitor.username@ | ||||
|   password: @monitor.password@ | ||||
| @ -0,0 +1,53 @@ | ||||
| spring: | ||||
|   datasource: | ||||
|     type: com.zaxxer.hikari.HikariDataSource | ||||
|     driver-class-name: com.mysql.cj.jdbc.Driver | ||||
|     url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true | ||||
|     username: root | ||||
|     password: root | ||||
|     hikari: | ||||
|       connection-timeout: 30000 | ||||
|       validation-timeout: 5000 | ||||
|       minimum-idle: 10 | ||||
|       maximum-pool-size: 20 | ||||
|       idle-timeout: 600000 | ||||
|       max-lifetime: 900000 | ||||
|       keepaliveTime: 30000 | ||||
|  | ||||
| --- # snail-job 服务端配置 | ||||
| snail-job: | ||||
|   # 拉取重试数据的每批次的大小 | ||||
|   retry-pull-page-size: 1000 | ||||
|   # 拉取重试数据的每批次的大小 | ||||
|   job-pull-page-size: 1000 | ||||
|   # 服务器端口 | ||||
|   server-port: 17888 | ||||
|   # 一个客户端每秒最多接收的重试数量指令 | ||||
|   limiter: 1000 | ||||
|   # 号段模式下步长配置 | ||||
|   step: 100 | ||||
|   # 日志保存时间(单位: day) | ||||
|   log-storage: 90 | ||||
|   # 回调配置 | ||||
|   callback: | ||||
|     #回调最大执行次数 | ||||
|     max-count: 288 | ||||
|     #间隔时间 | ||||
|     trigger-interval: 900 | ||||
|   # 重试每次拉取的次数 | ||||
|   retry-max-pull-count: 10 | ||||
|   # RPC通讯类型: netty,grpc | ||||
|   rpc-type: grpc | ||||
|  | ||||
| --- # 监控中心配置 | ||||
| spring.boot.admin.client: | ||||
|   # 增加客户端开关 | ||||
|   enabled: true | ||||
|   url: http://localhost:9090/admin | ||||
|   instance: | ||||
|     service-host-type: IP | ||||
|     metadata: | ||||
|       username: ${spring.boot.admin.client.username} | ||||
|       userpassword: ${spring.boot.admin.client.password} | ||||
|   username: @monitor.username@ | ||||
|   password: @monitor.password@ | ||||
| @ -0,0 +1,39 @@ | ||||
| server: | ||||
|   port: 8800 | ||||
|   servlet: | ||||
|     context-path: /snail-job | ||||
|  | ||||
| spring: | ||||
|   application: | ||||
|     name: ruoyi-snailjob-server | ||||
|   profiles: | ||||
|     active: @profiles.active@ | ||||
|   web: | ||||
|     resources: | ||||
|       static-locations: classpath:admin/ | ||||
|  | ||||
| mybatis-plus: | ||||
|   typeAliasesPackage: com.aizuda.snailjob.template.datasource.persistence.po | ||||
|   global-config: | ||||
|     db-config: | ||||
|       where-strategy: NOT_EMPTY | ||||
|       capital-mode: false | ||||
|       logic-delete-value: 1 | ||||
|       logic-not-delete-value: 0 | ||||
|   configuration: | ||||
|     map-underscore-to-camel-case: true | ||||
|     cache-enabled: true | ||||
|  | ||||
| logging: | ||||
|   config: classpath:logback-plus.xml | ||||
|  | ||||
| management: | ||||
|   endpoints: | ||||
|     web: | ||||
|       exposure: | ||||
|         include: '*' | ||||
|   endpoint: | ||||
|     health: | ||||
|       show-details: ALWAYS | ||||
|     logfile: | ||||
|       external-file: ./logs/ruoyi-snailjob-server/console.log | ||||
| @ -0,0 +1,11 @@ | ||||
| Application Version: ${revision} | ||||
| Spring Boot Version: ${spring-boot.version} | ||||
|                  _ _ _       _ | ||||
|                 (_) (_)     | | | ||||
|  ___ _ __   __ _ _| |_  ___ | |__ ______ ___  ___ _ ____   _____ _ __ | ||||
| / __| '_ \ / _` | | | |/ _ \| '_ \______/ __|/ _ \ '__\ \ / / _ \ '__| | ||||
| \__ \ | | | (_| | | | | (_) | |_) |     \__ \  __/ |   \ V /  __/ | | ||||
| |___/_| |_|\__,_|_|_| |\___/|_.__/      |___/\___|_|    \_/ \___|_| | ||||
|                    _/ | | ||||
|                   |__/ | ||||
|  | ||||
| @ -0,0 +1,92 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <configuration> | ||||
|     <property name="log.path" value="./logs/ruoyi-snailjob-server" /> | ||||
|     <property name="console.log.pattern" | ||||
|               value="%cyan(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}%n) - %msg%n"/> | ||||
|     <property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"/> | ||||
|  | ||||
|  | ||||
|     <!-- 控制台输出 --> | ||||
|     <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> | ||||
|         <encoder> | ||||
|             <pattern>${console.log.pattern}</pattern> | ||||
|             <charset>utf-8</charset> | ||||
|         </encoder> | ||||
|     </appender> | ||||
|  | ||||
|     <!-- 控制台输出 --> | ||||
|     <appender name="file_console" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||||
|         <file>${log.path}/console.log</file> | ||||
|         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||||
|             <!-- 日志文件名格式 --> | ||||
|             <fileNamePattern>${log.path}/console.%d{yyyy-MM-dd}.log</fileNamePattern> | ||||
|             <!-- 日志最大 1天 --> | ||||
|             <maxHistory>1</maxHistory> | ||||
|         </rollingPolicy> | ||||
|         <encoder> | ||||
|             <pattern>${log.pattern}</pattern> | ||||
|             <charset>utf-8</charset> | ||||
|         </encoder> | ||||
|         <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | ||||
|             <!-- 过滤的级别 --> | ||||
|             <level>INFO</level> | ||||
|         </filter> | ||||
|     </appender> | ||||
|  | ||||
|     <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||||
|         <file>${log.path}/info.log</file> | ||||
|         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||||
|             <FileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</FileNamePattern> | ||||
|             <MaxHistory>60</MaxHistory> | ||||
|         </rollingPolicy> | ||||
|         <encoder> | ||||
|             <pattern>${log.pattern}</pattern> | ||||
|         </encoder> | ||||
|         <filter class="ch.qos.logback.classic.filter.LevelFilter"> | ||||
|             <level>INFO</level> | ||||
|             <onMatch>ACCEPT</onMatch> | ||||
|             <onMismatch>DENY</onMismatch> | ||||
|         </filter> | ||||
|     </appender> | ||||
|  | ||||
|     <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||||
|         <file>${log.path}/error.log</file> | ||||
|         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||||
|             <FileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log | ||||
|             </FileNamePattern> | ||||
|             <MaxHistory>60</MaxHistory> | ||||
|         </rollingPolicy> | ||||
|         <encoder> | ||||
|             <pattern>${log.pattern}</pattern> | ||||
|         </encoder> | ||||
|         <filter class="ch.qos.logback.classic.filter.LevelFilter"> | ||||
|             <level>ERROR</level> | ||||
|             <onMatch>ACCEPT</onMatch> | ||||
|             <onMismatch>DENY</onMismatch> | ||||
|         </filter> | ||||
|     </appender> | ||||
|  | ||||
|     <appender name ="async_info" class= "ch.qos.logback.classic.AsyncAppender"> | ||||
|         <discardingThreshold >100</discardingThreshold> | ||||
|         <queueSize>1024</queueSize> | ||||
|         <appender-ref ref ="file_info"/> | ||||
|     </appender> | ||||
|  | ||||
|     <appender name ="async_error" class= "ch.qos.logback.classic.AsyncAppender"> | ||||
|         <discardingThreshold >100</discardingThreshold> | ||||
|         <queueSize>1024</queueSize> | ||||
|         <appender-ref ref ="file_error"/> | ||||
|     </appender> | ||||
|  | ||||
|     <!-- SnailJob appender --> | ||||
|     <appender name="snail_log_server_appender" class="com.aizuda.snailjob.server.common.appender.SnailJobServerLogbackAppender"> | ||||
|     </appender> | ||||
|  | ||||
|     <!-- 控制台输出日志级别 --> | ||||
|     <root level="info"> | ||||
|         <appender-ref ref="console" /> | ||||
|         <appender-ref ref="async_info" /> | ||||
|         <appender-ref ref="async_error" /> | ||||
|         <appender-ref ref="snail_log_server_appender" /> | ||||
|     </root> | ||||
| </configuration> | ||||
		Reference in New Issue
	
	Block a user