Merge remote-tracking branch 'origin/master' into haskafka

This commit is contained in:
Hao Miao
2024-04-06 21:32:00 +08:00
8 changed files with 79 additions and 16 deletions

View File

@@ -0,0 +1,22 @@
package com.realtime.protection.configuration.auth;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author Yixiang Zhao (@seriouszyx)
**/
@SpringBootApplication
@EnableCaching
public class Application implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
// InterceptorRegistration ir = registry.addInterceptor(new LoginInterceptor());
// ir.addPathPatterns("/**");
// ir.excludePathPatterns("/js/**", "/html/**", "/image/**", "/css/**", "/api/**");
}
}

View File

@@ -0,0 +1,31 @@
package com.realtime.protection.configuration.auth;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequestInterceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;
import com.realtime.protection.configuration.entity.user.User;
import com.realtime.protection.configuration.response.ResponseResult;
/**
* @author Yixiang Zhao
**/
@Component
public class LoginInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
if (user != null) {
return true;
}
// 未登录
throw new Exception("not login");
}
}

View File

@@ -22,7 +22,6 @@ public class Template {
private String sourceSystem;
@JsonProperty("description")
@NotNull(message = "source_system字段不能为空。")
@Schema(description = "对策略模板的文字描述。方便用户使用", example = "zd防护对象的全流量")
private String description;

View File

@@ -97,7 +97,7 @@ public class TaskCommandInfo {
@Schema(description = "防御策略模板ID", accessMode = Schema.AccessMode.READ_ONLY)
private Integer templateId;
@Schema(description = "防护等级", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "防护等级,1代表low、2代表medium、3代表high", accessMode = Schema.AccessMode.READ_ONLY)
private Integer protectLevel;
@Schema(description = "指令所属任务的运行状态", accessMode = Schema.AccessMode.READ_ONLY)

View File

@@ -158,6 +158,7 @@ public class AlertMessageService {
}
CommunicateObject protectObject;
CommunicateObject peer;
//0代表命中防护对象在告警信息的源ip
if (protectIsSrcOrDst == 0) {
protectObject = new CommunicateObject(
fiveTupleWithMask.getSourceIP(),
@@ -211,8 +212,8 @@ public class AlertMessageService {
command1.setMaskSourcePort(peer.getMaskPort());
command1.setDestinationIP(protectObject.getIP());
command1.setMaskDestinationIP(protectObject.getMaskIP());
command1.setSourcePort(protectObject.getPort());
command1.setMaskSourcePort(protectObject.getMaskPort());
command1.setDestinationPort(protectObject.getPort());
command1.setMaskDestinationPort(protectObject.getMaskPort());
if (templateProtectLevel.getHasProtocol()){
command1.setProtocol(fiveTupleWithMask.getProtocol());
command1.setProtocol(fiveTupleWithMask.getMaskProtocol());
@@ -229,8 +230,8 @@ public class AlertMessageService {
command2.setDestinationIP(peer.getIP());
command2.setMaskDestinationIP(peer.getMaskIP());
command2.setSourcePort(peer.getPort());
command2.setMaskSourcePort(peer.getMaskPort());
command2.setDestinationPort(peer.getPort());
command2.setMaskDestinationPort(peer.getMaskPort());
if (templateProtectLevel.getHasProtocol()){
command2.setProtocol(fiveTupleWithMask.getProtocol());
command2.setProtocol(fiveTupleWithMask.getMaskProtocol());

View File

@@ -2,10 +2,7 @@ package com.realtime.protection.server.user.login;
import com.realtime.protection.configuration.entity.user.User;
import com.realtime.protection.configuration.response.ResponseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.security.auth.login.LoginException;
@@ -36,4 +33,13 @@ public class LoginController {
.setData("userId", userId)
.setData("success", true);
}
@PostMapping("/auth")
public ResponseResult auth(@RequestParam("sessionData") String sessionData,
@RequestParam("accessToken") String accessToken,
@RequestParam(value = "scopes", required = false) String scopes) {
return ResponseResult.ok().setMessage("success")
.setData("success", true);
}
}