代码优化

This commit is contained in:
shimingxy
2025-12-26 10:35:26 +08:00
parent acafd86829
commit f5eebc195d
15 changed files with 51 additions and 74 deletions

View File

@@ -26,6 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.fasterxml.jackson.core.exc.StreamWriteException;
@@ -40,7 +41,7 @@ import jakarta.servlet.http.HttpServletResponse;
public class UnauthorizedEntryPoint {
private static final Logger _logger = LoggerFactory.getLogger(UnauthorizedEntryPoint.class);
@RequestMapping(value={"/entrypoint"})
@GetMapping({"/entrypoint"})
public void entryPoint(
HttpServletRequest request, HttpServletResponse response)
throws StreamWriteException, DatabindException, IOException {

View File

@@ -36,8 +36,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.v3.oas.annotations.Operation;
@@ -59,7 +59,7 @@ public class FormBasedAuthorizeEndpoint extends AuthorizeBaseEndpoint{
FormBasedDefaultAdapter defaultFormBasedAdapter=new FormBasedDefaultAdapter();
@Operation(summary = "FormBased认证地址接口", description = "参数应用ID",method="GET")
@RequestMapping("/authz/formbased/{id}")
@GetMapping("/authz/formbased/{id}")
public ModelAndView authorize(
HttpServletRequest request,
@PathVariable String id,

View File

@@ -49,8 +49,8 @@ import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import io.swagger.v3.oas.annotations.Operation;
@@ -90,11 +90,10 @@ public class TokenEndpoint extends AbstractEndpoint {
* @throws HttpRequestMethodNotSupportedException
*/
@Operation(summary = "OAuth 2.0 获取AccessToken接口", description = "传递参数token等",method="GET")
@RequestMapping(value = {
@GetMapping({
OAuth2Constants.ENDPOINT.ENDPOINT_TOKEN,
OAuth2Constants.ENDPOINT.ENDPOINT_TENCENT_IOA_TOKEN
},
method=RequestMethod.GET)
})
public ResponseEntity<OAuth2AccessToken> getAccessToken(@RequestParam
Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {
if (!allowedRequestMethods.contains(HttpMethod.GET)) {
@@ -104,11 +103,10 @@ public class TokenEndpoint extends AbstractEndpoint {
}
@Operation(summary = "OAuth 2.0 获取AccessToken接口", description = "传递参数token等",method="POST")
@RequestMapping(value = {
@PostMapping({
OAuth2Constants.ENDPOINT.ENDPOINT_TOKEN,
OAuth2Constants.ENDPOINT.ENDPOINT_TENCENT_IOA_TOKEN
},
method=RequestMethod.POST)
})
public ResponseEntity<OAuth2AccessToken> postAccessToken(@RequestParam
Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {
// TokenEndpointAuthenticationFilter

View File

@@ -39,8 +39,7 @@ import org.dromara.maxkey.authz.oauth2.provider.token.store.JwtAccessTokenConver
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
@@ -70,7 +69,7 @@ public class TokenKeyEndpoint {
* @param principal the currently authenticated user if there is one
* @return the key used to verify tokens
*/
@RequestMapping(value = OAuth2Constants.ENDPOINT.ENDPOINT_TOKEN_KEY, method = RequestMethod.GET)
@GetMapping(OAuth2Constants.ENDPOINT.ENDPOINT_TOKEN_KEY)
@ResponseBody
public Map<String, String> getKey(Principal principal) {
if ((principal == null || principal instanceof AnonymousAuthenticationToken) && !converter.isPublic()) {

View File

@@ -37,8 +37,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.v3.oas.annotations.Operation;
@@ -63,7 +63,7 @@ public class TokenBasedAuthorizeEndpoint extends AuthorizeBaseEndpoint{
ApplicationConfig applicationConfig;
@Operation(summary = "TokenBased认证接口", description = "传递参数应用ID",method="GET")
@RequestMapping("/authz/tokenbased/{id}")
@GetMapping("/authz/tokenbased/{id}")
public ModelAndView authorize(
HttpServletRequest request,
HttpServletResponse response,

View File

@@ -120,7 +120,7 @@ public class AuthFeishu2Request extends AuthDefaultRequest {
}
@Override
public AuthResponse refresh(AuthToken authToken) {
public AuthResponse<Object> refresh(AuthToken authToken) {
JSONObject requestObject = new JSONObject();
requestObject.put("app_access_token", this.getAppAccessToken());
requestObject.put("grant_type", "refresh_token");

View File

@@ -107,7 +107,7 @@ public class AuthHuaweiWeLinkRequest extends AuthDefaultRequest {
* @return AuthResponse
*/
@Override
public AuthResponse refresh(AuthToken authToken) {
public AuthResponse<Object> refresh(AuthToken authToken) {
Map<String, String> form = new HashMap<>(7);
form.put("client_id", config.getClientId());
form.put("client_secret", config.getClientSecret());

View File

@@ -160,7 +160,7 @@ public class LoginEntryPoint {
}
@RequestMapping(value={"/sendotp/{mobile}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(value={"/sendotp/{mobile}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<AuthJwt> produceOtp(@PathVariable String mobile) {
UserInfo userInfo=userInfoService.findByEmailMobile(mobile);
if(userInfo != null) {

View File

@@ -28,6 +28,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -44,7 +45,7 @@ public class SafeController {
@Autowired
UserInfoService userInfoService;
@RequestMapping(value="/forward/setting")
@GetMapping("/forward/setting")
public ModelAndView fowardSetting(@CurrentUser UserInfo currentUser) {
ModelAndView modelAndView=new ModelAndView("safe/setting");
modelAndView.addObject("model", currentUser);
@@ -52,7 +53,7 @@ public class SafeController {
}
@ResponseBody
@RequestMapping(value="/setting")
@GetMapping("/setting")
public Message<?> setting(
HttpServletRequest request,
HttpServletResponse response,

View File

@@ -30,9 +30,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
@Controller
@@ -43,7 +41,7 @@ public class SocialSignOnListController {
@Autowired
SocialsAssociatesService socialsAssociatesService;
@RequestMapping(value={"/fetch"})
@GetMapping({"/fetch"})
@ResponseBody
public Message<?> fetch(@CurrentUser UserInfo currentUser){
@@ -54,7 +52,7 @@ public class SocialSignOnListController {
}
@ResponseBody
@RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@DeleteMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> delete(@RequestParam List<String> ids,@CurrentUser UserInfo currentUser) {
logger.debug("-delete ids : {} " , ids);
if (socialsAssociatesService.deleteBatch(ids)) {

View File

@@ -32,10 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
/**
* 单点登录日志查询
@@ -56,7 +53,7 @@ public class LoginAppsHistoryController {
* @param loginAppsHistory
* @return
*/
@RequestMapping(value={"/loginAppsHistory/fetch"})
@GetMapping({"/loginAppsHistory/fetch"})
@ResponseBody
public Message<?> fetch(
@ModelAttribute HistoryLoginApps historyLoginApp,

View File

@@ -32,10 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
/**
* 登录日志查询
@@ -56,7 +53,7 @@ public class LoginHistoryController {
* @param HistoryLogin
* @return
*/
@RequestMapping(value={"/loginHistory/fetch"})
@GetMapping({"/loginHistory/fetch"})
@ResponseBody
public Message<?> fetch(
@ModelAttribute HistoryLogin historyLogin,

View File

@@ -32,12 +32,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RestController
@@ -48,7 +43,7 @@ public class TokenBasedDetailsController extends BaseAppContorller {
@Autowired
AppsTokenBasedDetailsService tokenBasedDetailsService;
@RequestMapping(value = { "/init" }, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(value = { "/init" }, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> init() {
AppsTokenBasedDetails tokenBasedDetails =new AppsTokenBasedDetails();
tokenBasedDetails.setId(tokenBasedDetails.generateId());
@@ -59,7 +54,7 @@ public class TokenBasedDetailsController extends BaseAppContorller {
return new Message<AppsTokenBasedDetails>(tokenBasedDetails);
}
@RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> get(@PathVariable String id) {
AppsTokenBasedDetails tokenBasedDetails=tokenBasedDetailsService.getAppDetails(id , false);
decoderSecret(tokenBasedDetails);
@@ -70,7 +65,7 @@ public class TokenBasedDetailsController extends BaseAppContorller {
}
@ResponseBody
@RequestMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@PostMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> add(
@RequestBody AppsTokenBasedDetails tokenBasedDetails,
@CurrentUser UserInfo currentUser) {
@@ -89,7 +84,7 @@ public class TokenBasedDetailsController extends BaseAppContorller {
}
@ResponseBody
@RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@PutMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> update(
@RequestBody AppsTokenBasedDetails tokenBasedDetails,
@CurrentUser UserInfo currentUser) {
@@ -106,7 +101,7 @@ public class TokenBasedDetailsController extends BaseAppContorller {
}
@ResponseBody
@RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@DeleteMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> delete(
@RequestParam List<String> ids,
@CurrentUser UserInfo currentUser) {

View File

@@ -58,9 +58,9 @@ public class CnfPasswordPolicyController {
}
}
public Message validate(BindingResult result,CnfPasswordPolicy passwordPolicy) {
public Message<BindingResult> validate(BindingResult result,CnfPasswordPolicy passwordPolicy) {
if (result.hasErrors()) {
return new Message(result);
return new Message<>(result);
}
if(passwordPolicy.getMinLength() < 3) {
FieldError fe = new FieldError("passwordPolicy", "minLength",
@@ -68,7 +68,7 @@ public class CnfPasswordPolicyController {
new String[]{"ui.passwordpolicy.xe00000001"},//密码最小长度不能小于3位字符
null, null);
result.addError(fe);
return new Message(result);
return new Message<>(result);
}
if(passwordPolicy.getMinLength() > passwordPolicy.getMaxLength()) {
FieldError fe = new FieldError("passwordPolicy", "maxLength",
@@ -76,7 +76,7 @@ public class CnfPasswordPolicyController {
new String[]{"ui.passwordpolicy.xe00000002"},//密码最大长度不能小于最小长度
null, null);
result.addError(fe);
return new Message(result);
return new Message<>(result);
}
if(passwordPolicy.getDigits() + passwordPolicy.getLowerCase() + passwordPolicy.getUpperCase() + passwordPolicy.getSpecialChar() < 2) {
@@ -85,7 +85,7 @@ public class CnfPasswordPolicyController {
new String[]{"ui.passwordpolicy.xe00000003"},//密码包含小写字母、大写字母、数字、特殊字符的个数不能小于2
null, null);
result.addError(fe);
return new Message(result);
return new Message<>(result);
}
if(passwordPolicy.getDigits() + passwordPolicy.getLowerCase() + passwordPolicy.getUpperCase() + passwordPolicy.getSpecialChar() > passwordPolicy.getMaxLength()) {
@@ -94,7 +94,7 @@ public class CnfPasswordPolicyController {
new String[]{"ui.passwordpolicy.xe00000004"},//密码包含小写字母、大写字母、数字、特殊字符的个数不能大于密码的最大长度
null, null);
result.addError(fe);
return new Message(result);
return new Message<>(result);
}
return null;
}

View File

@@ -56,16 +56,7 @@ import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.http.MediaType;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.google.common.collect.Lists;
/**
@@ -86,7 +77,7 @@ public class UserInfoController {
@Autowired
HistorySystemLogsService systemLog;
@RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public Message<?> fetch(@ModelAttribute UserInfo userInfo,@CurrentUser UserInfo currentUser) {
logger.debug(""+userInfo);
@@ -96,7 +87,7 @@ public class UserInfoController {
}
@ResponseBody
@RequestMapping(value={"/query"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(value={"/query"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> query(@ModelAttribute UserInfo userInfo,@CurrentUser UserInfo currentUser) {
logger.debug("-query :" + userInfo);
if (userInfoService.query(userInfo)!=null) {
@@ -106,14 +97,14 @@ public class UserInfoController {
}
}
@RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> get(@PathVariable String id) {
UserInfo userInfo=userInfoService.get(id);
userInfo.trans();
return new Message<UserInfo>(userInfo);
}
@RequestMapping(value = { "/getByUsername/{username}" }, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(value = { "/getByUsername/{username}" }, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> getByUsername(@PathVariable String username) {
UserInfo userInfo=userInfoService.findByUsername(username);
userInfo.trans();
@@ -121,7 +112,7 @@ public class UserInfoController {
}
@ResponseBody
@RequestMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@PostMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> insert(@RequestBody UserInfo userInfo,@CurrentUser UserInfo currentUser) {
logger.debug("-Add :" + userInfo);
userInfo.setId(WebContext.genId());
@@ -144,7 +135,7 @@ public class UserInfoController {
}
@ResponseBody
@RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@PutMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> update(@RequestBody UserInfo userInfo,@CurrentUser UserInfo currentUser) {
logger.debug("-update :" + userInfo);
logger.info(userInfo.getExtraAttributeName());
@@ -172,7 +163,7 @@ public class UserInfoController {
}
@ResponseBody
@RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@DeleteMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> delete(@RequestParam List<String> ids,@CurrentUser UserInfo currentUser) {
logger.debug("-delete ids : {} " , ids);
@@ -191,7 +182,7 @@ public class UserInfoController {
@ResponseBody
@RequestMapping(value = "/randomPassword", produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(value = "/randomPassword", produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> randomPassword() {
return new Message<Object>(
Message.SUCCESS,
@@ -215,7 +206,7 @@ public class UserInfoController {
@ResponseBody
@RequestMapping(value="/changePassword", produces = {MediaType.APPLICATION_JSON_VALUE})
@PostMapping(value="/changePassword", produces = {MediaType.APPLICATION_JSON_VALUE})
public Message<?> changePassword(
@RequestBody ChangePassword changePassword,
@CurrentUser UserInfo currentUser) {
@@ -234,7 +225,7 @@ public class UserInfoController {
}
}
@RequestMapping(value = { "/updateStatus" }, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(value = { "/updateStatus" }, produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public Message<?> updateStatus(@ModelAttribute UserInfo userInfo,@CurrentUser UserInfo currentUser) {
logger.debug(""+userInfo);
@@ -271,7 +262,7 @@ public class UserInfoController {
return new Message<>(Message.FAIL);
}
@RequestMapping(value = "/import")
@PostMapping("/import")
public Message<?> importingUsers(
@ModelAttribute ExcelImport excelImportFile,
@CurrentUser UserInfo currentUser) {