[+] 优化
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.acgist.taoyao.config;
|
||||
package com.acgist.taoyao.configuration;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -7,9 +7,11 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.acgist.taoyao.interceptor.SecurityInterceptor;
|
||||
import com.acgist.taoyao.interceptor.SlowInterceptor;
|
||||
import com.acgist.taoyao.signal.service.SecurityService;
|
||||
import com.acgist.taoyao.signal.service.impl.SecurityServiceImpl;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
* 自动配置
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@@ -22,6 +24,12 @@ public class TaoyaoAutoConfiguration {
|
||||
return new SlowInterceptor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SecurityService securityService() {
|
||||
return new SecurityServiceImpl();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "taoyao.security", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnMissingBean
|
||||
@@ -18,28 +18,26 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 安全拦截
|
||||
* 安全拦截器
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
public class SecurityInterceptor extends InterceptorAdapter {
|
||||
|
||||
/**
|
||||
* Basic认证
|
||||
*/
|
||||
private static final String BASIC = "Basic";
|
||||
|
||||
private AntPathMatcher matcher = new AntPathMatcher();
|
||||
|
||||
@Autowired
|
||||
private SecurityService securityService;
|
||||
@Autowired
|
||||
private SecurityProperties securityProperties;
|
||||
|
||||
/**
|
||||
* 地址匹配
|
||||
*/
|
||||
private final AntPathMatcher matcher = new AntPathMatcher();
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "安全拦截";
|
||||
return "安全拦截器";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,12 +92,13 @@ public class SecurityInterceptor extends InterceptorAdapter {
|
||||
if(StringUtils.isEmpty(authorization)) {
|
||||
return false;
|
||||
}
|
||||
if(!StringUtils.startsWithIgnoreCase(authorization, BASIC)) {
|
||||
return false;
|
||||
int index = authorization.indexOf(' ');
|
||||
if(index < 0) {
|
||||
return false;
|
||||
}
|
||||
authorization = authorization.substring(BASIC.length()).strip();
|
||||
authorization = new String(Base64.getDecoder().decode(authorization));
|
||||
final int index = authorization.indexOf(':');
|
||||
authorization = authorization.substring(index + 1).strip();
|
||||
authorization = new String(Base64.getMimeDecoder().decode(authorization));
|
||||
index = authorization.indexOf(':');
|
||||
if(index < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -10,24 +10,24 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 过慢请求统计拦截
|
||||
* 过慢请求拦截器
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
public class SlowInterceptor extends InterceptorAdapter {
|
||||
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
private ThreadLocal<Long> local = new ThreadLocal<>();
|
||||
|
||||
@Autowired
|
||||
private TaoyaoProperties taoyaoProperties;
|
||||
|
||||
/**
|
||||
* 请求开始时间
|
||||
*/
|
||||
private final ThreadLocal<Long> local = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "过慢请求统计拦截";
|
||||
return "过慢请求拦截器";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
taoyao:
|
||||
media:
|
||||
media-server-list:
|
||||
- name: media-local-a
|
||||
- media-id: media-local-a
|
||||
enabled: true
|
||||
host: 192.168.8.110
|
||||
port: 4443
|
||||
port: 9443
|
||||
schema: wss
|
||||
username: taoyao
|
||||
password: taoyao
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
taoyao:
|
||||
media:
|
||||
media-server-list:
|
||||
- name: media-local-a
|
||||
- media-id: media-local-a
|
||||
enabled: false
|
||||
host: 192.168.1.110
|
||||
port: 4443
|
||||
port: 9443
|
||||
schema: wss
|
||||
username: taoyao
|
||||
password: taoyao
|
||||
|
||||
@@ -103,19 +103,17 @@ taoyao:
|
||||
- media-id: media-local-a
|
||||
enabled: true
|
||||
host: localhost
|
||||
port: 4443
|
||||
port: 9443
|
||||
schema: wss
|
||||
username: taoyao
|
||||
password: taoyao
|
||||
- media-id: media-local-z
|
||||
enabled: true
|
||||
host: localhost
|
||||
port: 4443
|
||||
port: 9443
|
||||
schema: wss
|
||||
username: taoyao
|
||||
password: taoyao
|
||||
# 录像配置
|
||||
record-storage-path: /data/record
|
||||
# Socket信令
|
||||
socket:
|
||||
enabled: true
|
||||
@@ -123,8 +121,8 @@ taoyao:
|
||||
port: 9999
|
||||
timeout: ${taoyao.timeout}
|
||||
queue-size: 100000
|
||||
thread-min: 4
|
||||
thread-max: 128
|
||||
min-thread: 4
|
||||
max-thread: 128
|
||||
thread-name-prefix: ${spring.application.name}-signal-
|
||||
keep-alive-time: 60000
|
||||
buffer-size: 2048
|
||||
|
||||
Reference in New Issue
Block a user