fix(通用模块):登录手机号获取异常逻辑优化,无效http请求异常处理
This commit is contained in:
+3
-2
@@ -121,9 +121,10 @@ public class SysUserController {
|
||||
*
|
||||
* @param openId openId
|
||||
*/
|
||||
@GetMapping(value = "/users-anon/wxOpenId", params = {"openId","mobile"})
|
||||
@GetMapping(value = "/users-anon/wxOpenId")
|
||||
@Operation(summary = "根据WxOpenId查询用户")
|
||||
public SysUser findByWxOpenId(String openId,String mobile) throws Exception {
|
||||
public SysUser findByWxOpenId(@RequestParam("openId") String openId,
|
||||
@RequestParam(required = false) String mobile) throws Exception {
|
||||
return appUserService.findByWxOpenid(openId,mobile);
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -73,6 +73,9 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
@Override
|
||||
public SysUser findByWxOpenid(String wxOpenid,String mobile) throws Exception {
|
||||
SysUser sysUser = this.selectByOpenId(wxOpenid);
|
||||
if (ObjectUtils.isNotEmpty(sysUser) && StringUtils.isNotEmpty(sysUser.getMobile())) {
|
||||
return sysUser;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(sysUser)) {
|
||||
sysUser = new SysUser();
|
||||
sysUser.setOpenId(wxOpenid);
|
||||
@@ -81,6 +84,8 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
sysUser.setPassword(wxOpenid);
|
||||
sysUser.setEnabled(Boolean.TRUE);
|
||||
sysUser.setMobile(mobile);
|
||||
}else if (ObjectUtils.isEmpty(sysUser.getMobile()) && StringUtils.isNotEmpty(mobile)) {
|
||||
sysUser.setMobile(mobile);
|
||||
}
|
||||
String username = sysUser.getUsername();
|
||||
boolean result = super.saveOrUpdateIdempotency(sysUser, lock
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ public class LoginUserFilter extends OncePerRequestFilter {
|
||||
FilterChain filterChain) throws IOException, ServletException {
|
||||
try {
|
||||
LoginAppUser user = LoginUserUtils.getCurrentUser(request, false);
|
||||
logger.debug(request.toString());
|
||||
LoginUserContextHolder.setUser(user);
|
||||
filterChain.doFilter(request, response);
|
||||
} finally {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.central.gateway.filter;
|
||||
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 不合法请求过滤器
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2025/03/11
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class RequestFilter implements GlobalFilter {
|
||||
|
||||
private boolean isValidMethod(String method) {
|
||||
// 简单的方法名验证,只允许常见的 HTTP 方法
|
||||
return method.matches("^(GET|POST|PUT|DELETE|HEAD|OPTIONS|TRACE)$");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
ServerHttpRequest httpRequest = exchange.getRequest();
|
||||
String method = httpRequest.getMethod().toString();
|
||||
if (isValidMethod(method)) {
|
||||
return chain.filter(exchange);
|
||||
} else {
|
||||
return exchange.getResponse().setComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
@@ -9,6 +9,7 @@ import com.central.oauth2.common.token.TencentAuthenticationToken;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -41,6 +42,7 @@ import java.util.Map;
|
||||
* Blog: http://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Slf4j
|
||||
@Setter
|
||||
@Getter
|
||||
public class TencentAuthenticationProvider extends BaseAuthenticationProvider {
|
||||
|
||||
Reference in New Issue
Block a user