2023-01-06 15:17:37 +08:00
|
|
|
package com.ai.da.controller;
|
|
|
|
|
|
|
|
|
|
import com.ai.da.common.response.Response;
|
|
|
|
|
import com.ai.da.model.dto.*;
|
|
|
|
|
import com.ai.da.model.vo.AccountLoginVO;
|
|
|
|
|
import com.ai.da.service.AccountService;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2024-01-18 09:56:50 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2024-01-17 10:33:37 +08:00
|
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|
|
|
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
|
2023-12-06 15:58:57 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
2023-01-06 15:17:37 +08:00
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.validation.Valid;
|
2024-01-17 10:33:37 +08:00
|
|
|
import java.security.cert.X509Certificate;
|
2023-01-06 15:17:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@Api(tags = "Third Party Modules")
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/third/party")
|
|
|
|
|
public class ThirdPartyController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AccountService accountService;
|
|
|
|
|
|
2024-06-20 15:26:22 +08:00
|
|
|
/*@ApiOperation(value = "Add user information")
|
2023-01-06 15:17:37 +08:00
|
|
|
@PostMapping("/addUser")
|
|
|
|
|
public Response<Boolean> addUser(@Valid @RequestBody AccountAddDTO accountAddDTO) {
|
|
|
|
|
return Response.success(accountService.addUser(accountAddDTO));
|
2024-06-20 15:26:22 +08:00
|
|
|
}*/
|
2023-01-06 15:17:37 +08:00
|
|
|
|
|
|
|
|
@ApiOperation(value = "Edit user information")
|
|
|
|
|
@PostMapping("/editUser")
|
2023-10-20 14:47:18 +08:00
|
|
|
public Response<Boolean> editUser(@RequestBody AccountEditDTO accountEditDTO) {
|
2023-01-06 15:17:37 +08:00
|
|
|
return Response.success(accountService.editUser(accountEditDTO));
|
|
|
|
|
}
|
2023-09-06 14:28:20 +08:00
|
|
|
|
2023-12-06 16:31:20 +08:00
|
|
|
@CrossOrigin
|
2023-12-06 15:58:57 +08:00
|
|
|
@ApiOperation(value = "Add user information")
|
2023-12-11 10:02:05 +08:00
|
|
|
@PostMapping("/addTrialUser")
|
2024-04-02 10:15:35 +08:00
|
|
|
public Response<Boolean> addTrialUser(@RequestBody AccountTrialDTO accountTrialDTO, HttpServletRequest request) {
|
|
|
|
|
return Response.success(accountService.addTrialUser(accountTrialDTO, request));
|
2023-12-06 15:58:57 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-15 15:06:48 +08:00
|
|
|
@CrossOrigin
|
|
|
|
|
@ApiOperation(value = "add No Login Required")
|
|
|
|
|
@PostMapping("/addNoLoginRequired")
|
|
|
|
|
public Response<Boolean> addNoLoginRequired(@RequestBody NoLoginRequiredDTO noLoginRequiredDTO) {
|
|
|
|
|
return Response.success(accountService.addNoLoginRequired(noLoginRequiredDTO));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
@ApiOperation(value = "add No Login Required")
|
|
|
|
|
@PostMapping("/deleteNoLoginRequired")
|
|
|
|
|
public Response<Boolean> deleteNoLoginRequired(@RequestBody NoLoginRequiredDTO noLoginRequiredDTO) {
|
|
|
|
|
return Response.success(accountService.deleteNoLoginRequired(noLoginRequiredDTO));
|
|
|
|
|
}
|
2024-01-15 16:33:23 +08:00
|
|
|
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
@ApiOperation(value = "add No Login Required")
|
|
|
|
|
@PostMapping("/existNoLoginRequired")
|
2024-01-17 17:49:40 +08:00
|
|
|
public Response<Boolean> existNoLoginRequired(@RequestBody NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request) {
|
|
|
|
|
return Response.success(accountService.existNoLoginRequired(noLoginRequiredDTO, request));
|
2024-01-15 16:33:23 +08:00
|
|
|
}
|
2024-01-17 10:33:37 +08:00
|
|
|
|
|
|
|
|
@GetMapping("/your-secured-endpoint")
|
|
|
|
|
// @PreAuthorize("hasRole('ROLE_USER')")
|
|
|
|
|
public String securedEndpoint(HttpServletRequest request, @AuthenticationPrincipal PreAuthenticatedAuthenticationToken authenticationToken) {
|
|
|
|
|
// 从请求属性中获取证书
|
|
|
|
|
X509Certificate[] certificates = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
|
|
|
|
|
if (certificates != null && certificates.length > 0) {
|
|
|
|
|
X509Certificate clientCertificate = certificates[0];
|
|
|
|
|
// 可以从 clientCertificate 中获取证书信息,例如主题、颁发者等
|
|
|
|
|
String subject = clientCertificate.getSubjectX500Principal().getName();
|
|
|
|
|
String issuer = clientCertificate.getIssuerX500Principal().getName();
|
|
|
|
|
// 处理逻辑
|
|
|
|
|
return "Secured Endpoint. Client Subject: " + subject + ", Issuer: " + issuer;
|
|
|
|
|
} else {
|
|
|
|
|
// 证书不存在或获取失败
|
|
|
|
|
return "Failed to retrieve client certificate.";
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-17 17:49:40 +08:00
|
|
|
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
@ApiOperation(value = "add No Login Required")
|
|
|
|
|
@PostMapping("/addNoLoginRequiredNew")
|
|
|
|
|
public Response<String> addNoLoginRequiredNew(@RequestBody NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request) {
|
|
|
|
|
return Response.success(accountService.addNoLoginRequiredNew(noLoginRequiredDTO, request));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
@ApiOperation(value = "add No Login Required")
|
|
|
|
|
@PostMapping("/deleteNoLoginRequiredNew")
|
|
|
|
|
public Response<Boolean> deleteNoLoginRequiredNew(@RequestBody NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request) {
|
|
|
|
|
return Response.success(accountService.deleteNoLoginRequiredNew(noLoginRequiredDTO, request));
|
|
|
|
|
}
|
2024-01-18 09:56:50 +08:00
|
|
|
|
|
|
|
|
@Value("${redirect_url}")
|
|
|
|
|
private String REDIRECT_URL;
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
@ApiOperation(value = "add No Login Required")
|
|
|
|
|
@PostMapping("/getRedirectUrl")
|
|
|
|
|
public Response<String> getRedirectUrl() {
|
|
|
|
|
return Response.success(REDIRECT_URL);
|
|
|
|
|
}
|
2023-01-06 15:17:37 +08:00
|
|
|
}
|