This commit is contained in:
Mauve
2026-10-12 15:15:50 +08:00
parent 32945d7469
commit 3a8a438668
74 changed files with 1490 additions and 2221 deletions
@@ -0,0 +1,12 @@
package com.mgm.mcrm.common.annotation.security;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface VerifyPermission {
String[] permissionId() default {};
}
@@ -46,7 +46,16 @@ public class WebFilterConfig {
@Bean
public FilterRegistrationBean<ConfigHeaderFilter> registerHeaderFilter() {
FilterRegistrationBean<ConfigHeaderFilter> registration = new FilterRegistrationBean<ConfigHeaderFilter>();
registration.setFilter(new ConfigHeaderFilter());
ConfigHeaderFilter filer = new ConfigHeaderFilter();
List<String> ignoreOriginPatterns = Arrays.asList(
"/sso_callback/login",
"/sso_callback/logout",
"/api/app/sso/export_folder",
"/api/app/sso/import_folder",
"/api/third_party/get_access_token"
);
filer.setIgnoreOriginPatterns(ignoreOriginPatterns);
registration.setFilter(filer);
registration.addUrlPatterns("/*");
registration.setName("ConfigHeaderFilter");
registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
@@ -62,7 +71,10 @@ public class WebFilterConfig {
"/api/system/write_public_log",
"/api/system/sys_setting/get_public_login_settings",
"/api/app/sso/*",
"/sso_callback/login",
"/sso_callback/logout",
"/api/web/setting/get_public_setting_by_key",
"/api/third_party/get_access_token",
"/swagger*/*",
"/v3/**",
"/api-docs",
@@ -6,8 +6,10 @@ import com.auth0.jwt.interfaces.DecodedJWT;
import com.mgm.mcrm.appsetting.models.SysSetting;
import com.mgm.mcrm.authorization.dtos.LoginUserInfo;
import com.mgm.mcrm.authorization.models.SysUser;
import com.mgm.mcrm.authorization.services.MgmUserService;
import com.mgm.mcrm.booking.services.BookingService;
import com.mgm.mcrm.common.dtos.config.APIConfig;
import com.mgm.mcrm.common.dtos.BaseApiResponse;
import com.mgm.mcrm.common.dtos.mgm_api.UserInfoApiRecord;
import com.mgm.mcrm.common.dtos.msg.AppSettingMsgData;
import com.mgm.mcrm.common.dtos.msg.UpdateCfgItem;
import com.mgm.mcrm.common.dtos.system.AppServerState;
@@ -25,6 +27,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.servlet.support.RequestContextUtils;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
@@ -36,6 +39,7 @@ import java.util.*;
public class SysCommon {
public static String runtime_path = "";
public static String serverIp="";
public static String serverName="";
@@ -49,10 +53,6 @@ public class SysCommon {
public static int postTimeOut = 20;
//for stress test
public static int tokenExpMin = 5;
public static int refreshTokenExpDay = 30;
public static APIConfig apiConfig = new APIConfig();
private static Map<String,String> notifyTemplateMap = new HashMap<String,String>();
private static final Map<String,AppServerState> appServerStates = new HashMap<String,AppServerState>();
private static final List<String> allowOriginSource = new ArrayList<String>();
@Getter
@@ -85,7 +85,6 @@ public class SysCommon {
//--Server Info
serverIp = NetworkUtil.getInternalIp();
serverName = NetworkUtil.getServerName();
loadAPIConfig(props);
} catch (Exception e) {
isLoaded = false;
LogUtil.error(SysCommon.class, "Load configuration error:" + e.getMessage());
@@ -388,18 +387,6 @@ public class SysCommon {
SysCommon.runtime_path = runtime_path;
}
// Load API Config
public static void loadAPIConfig(Properties props) {
boolean isLoaded = true;
//SMS Config
SysCommon.apiConfig.setPort_SMTP(props.getProperty("mail_port", ""));
SysCommon.apiConfig.setHost_SMTP(props.getProperty("mail_smtp_host", ""));
SysCommon.apiConfig.setUsername_SMTP(props.getProperty("mail_sender", ""));
SysCommon.apiConfig.setPassword_SMTP(props.getProperty("mail_sender_password", ""));
SysCommon.apiConfig.setSend_to_SMTP(props.getProperty("mail_send_to", ""));
LogUtil.info(SysCommon.class, "Loaded API config.");
}
//-- Path Type 1= Class path 2=Application path 3=URI Path
public static String loadResFileContentByPath(String filePath, int pathType) {
@@ -503,6 +490,7 @@ public class SysCommon {
LoginUserInfo loginUser = null;
if(StringUtils.isNotBlank(tokenContent)) {
try {
LogUtil.info(SysCommon.class, "Parse Token content:"+tokenContent);
tokenContent = tokenContent.replace("Bearer ", "");
DecodedJWT decodeData = JWT.decode(tokenContent);
@@ -513,8 +501,14 @@ public class SysCommon {
}else {
loginUser.setId(-1L);
}
loginUser.setLoginId(decodeData.getClaim("login_id").asString());
loginUser.setGroupName(decodeData.getClaim("user_group").asString());
String loginId = decodeData.getClaim("login_id").asString();
if(loginId!=null) loginId = StringUtils.replace(loginId, "@mgm.mo", "");
loginUser.setLoginId(loginId);
loginUser.setGroupName(decodeData.getClaim("group_name").asString());
}catch(Exception err) {
LogUtil.error(SysCommon.class, "Parse Token failed:"+err.getMessage());
loginUser =null;
@@ -18,6 +18,7 @@ public class SysConstants {
public static final int CMS_TOKEN_TYPE=0;
public static final int MOBILE_TOKEN_TYPE=1;
public static final int THIRD_PARTY_TOKEN_TYPE=2;
public static final String PERMISSION_APP_VIEW_BOOKING="10001_01";
public static final String PERMISSION_APP_NEW_BOOKING="10001_02";
@@ -1,17 +0,0 @@
package com.mgm.mcrm.common.dtos.config;
import lombok.Data;
@Data
public class APIConfig {
private boolean isLoaded = false;
//SMTP Config
private String port_SMTP= "";
private String host_SMTP= "";
private String username_SMTP= "";
private String password_SMTP= "";
private String send_to_SMTP= "";
}
@@ -1,34 +0,0 @@
package com.mgm.mcrm.common.dtos.excel_export;
public class ColumnDefine {
private String columnHeader;
private String dataType;
private String attrName;
private int columnWidth=0;
public String getColumnHeader() {
return columnHeader;
}
public void setColumnHeader(String columnHeader) {
this.columnHeader = columnHeader;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public String getAttrName() {
return attrName;
}
public void setAttrName(String attrName) {
this.attrName = attrName;
}
public int getColumnWidth() {
return columnWidth;
}
public void setColumnWidth(int columnWidth) {
this.columnWidth = columnWidth;
}
}
@@ -1,85 +0,0 @@
package com.mgm.mcrm.common.dtos.excel_export;
import java.util.List;
public class DataElement {
private int offsetRow=0;
private int offsetCol=0;
private int elementType=0;
private boolean isShowHeader=false;
private String objClassName;
private String headerAlign="center";
private String headerColor="";
private String textAlign="left";
private String textColor="";
private List<ColumnDefine> columnDefs;
private List blockData;
public int getElementType() {
return elementType;
}
public void setElementType(int elementType) {
this.elementType = elementType;
}
public List<ColumnDefine> getColumnDefs() {
return columnDefs;
}
public void setColumnDefs(List<ColumnDefine> columnDefs) {
this.columnDefs = columnDefs;
}
public boolean isShowHeader() {
return isShowHeader;
}
public void setShowHeader(boolean isShowHeader) {
this.isShowHeader = isShowHeader;
}
public int getOffsetRow() {
return offsetRow;
}
public void setOffsetRow(int offsetRow) {
this.offsetRow = offsetRow;
}
public int getOffsetCol() {
return offsetCol;
}
public void setOffsetCol(int offsetCol) {
this.offsetCol = offsetCol;
}
public String getObjClassName() {
return objClassName;
}
public void setObjClassName(String objClassName) {
this.objClassName = objClassName;
}
public String getHeaderAlign() {
return headerAlign;
}
public void setHeaderAlign(String headerAlign) {
this.headerAlign = headerAlign;
}
public String getHeaderColor() {
return headerColor;
}
public void setHeaderColor(String headerColor) {
this.headerColor = headerColor;
}
public String getTextAlign() {
return textAlign;
}
public void setTextAlign(String textAlign) {
this.textAlign = textAlign;
}
public String getTextColor() {
return textColor;
}
public void setTextColor(String textColor) {
this.textColor = textColor;
}
public List getBlockData() {
return blockData;
}
public void setBlockData(List blockData) {
this.blockData = blockData;
}
}
@@ -1,24 +0,0 @@
package com.mgm.mcrm.common.dtos.excel_export;
import java.util.List;
public class ExportDefination {
private List<ExportSheet> exportPages;
private String exportFileName;
public List<ExportSheet> getExportPages() {
return exportPages;
}
public void setExportPages(List<ExportSheet> exportPages) {
this.exportPages = exportPages;
}
public String getExportFileName() {
return exportFileName;
}
public void setExportFileName(String exportFileName) {
this.exportFileName = exportFileName;
}
}
@@ -1,26 +0,0 @@
package com.mgm.mcrm.common.dtos.excel_export;
import java.util.List;
public class ExportSheet {
private String sheetName;
private List<DataElement> dataElements;
public ExportSheet() {
}
public String getSheetName() {
return sheetName;
}
public void setSheetName(String sheetName) {
this.sheetName = sheetName;
}
public List<DataElement> getDataElements() {
return dataElements;
}
public void setDataElements(List<DataElement> dataElements) {
this.dataElements = dataElements;
}
}
@@ -1,12 +0,0 @@
package com.mgm.mcrm.common.dtos.mgm_api;
import lombok.Data;
@Data
public class GetLimoAccessTokenRequest {
private String LoginId;
private String password;
}
@@ -1,11 +0,0 @@
package com.mgm.mcrm.common.dtos.mgm_api;
import lombok.Data;
@Data
public class GetLimoFlightDetailsRequest {
private String flightNo;
private String pickupDateTime;
private String pickupAirportCode;
private String dropOffAirportCode;
}
@@ -1,10 +0,0 @@
package com.mgm.mcrm.common.dtos.mgm_api;
import lombok.Data;
@Data
public class GetLimoOverriderRequest {
private String OverriderIdOrName;
}
@@ -1,10 +0,0 @@
package com.mgm.mcrm.common.dtos.mgm_api;
import lombok.Data;
@Data
public class GetLimoTotalAmountRequest {
private String pickupPOIId;
private String dropoffPOIIds;
private String singleTripPrices;
}
@@ -1,10 +0,0 @@
package com.mgm.mcrm.common.dtos.mgm_api;
import lombok.Data;
@Data
public class GetPlayerInfoRequest {
private String playerId;
}
@@ -1,15 +0,0 @@
package com.mgm.mcrm.common.dtos.mgm_api;
import lombok.Data;
@Data
public class GetSimpleLimoBookingQualificationStatusRequest {
private String playerId;
private String bookingType;
private String bookingDate;
}
@@ -1,150 +0,0 @@
package com.mgm.mcrm.common.dtos.mgm_api;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
public class InternalCreateLimoBookingRequest {
private int createNotConfirmBooking;
private String bookingType;
private String greetType;
private String otherGreetType;
private String guestType;
private String tripType;
private String playerId;
private String ranking;
private String overrideBy;
private String complexOverrider;
private String roomNo;
private String employeeId;
private String lastName;
private String salution;
private String chineseLastName;
private String bookerContact;
private String tripContact;
private int adHoc;
private LocalDateTime pickupDatetime;
private Long carTypeId;
private Integer passengerNo;
private Long pickupPOIID;
private String pickup;
private Long pickupTripPriceId;
private String pickupRegion;
private Long dropoffPOIID;
private String dropoff;
private Long dropoffTripPriceId;
private String dropoffRegion;
private Long extraDropoffPOIID1;
private String extraDropoff1;
private Long extraDropoffTripPriceID1;
private String extraDropoffRegion1;
private Long extraDropoffPOIID2;
private String extraDropoff2;
private Long extraDropoffTripPriceID2;
private String extraDropoffRegion2;
private Long extraDropoffPOIID3;
private String extraDropoff3;
private Long extraDropoffTripPriceID3;
private String extraDropoffRegion3;
private Long extraDropoffPOIID4;
private String extraDropoff4;
private Long extraDropoffTripPriceID4;
private String extraDropoffRegion4;
private Long extraDropoffPOIID5;
private String extraDropoff5;
private Long extraDropoffTripPriceID5;
private String extraDropoffRegion5;
private Long extraDropoffPOIID6;
private String extraDropoff6;
private Long extraDropoffTripPriceID6;
private String extraDropoffRegion6;
private Long extraDropoffPOIID7;
private String extraDropoff7;
private Long extraDropoffTripPriceID7;
private String extraDropoffRegion7;
private Long extraDropoffPOIID8;
private String extraDropoff8;
private Long extraDropoffTripPriceID8;
private String extraDropoffRegion8;
private Long extraDropoffPOIID9;
private String extraDropoff9;
private Long extraDropoffTripPriceID9;
private String extraDropoffRegion9;
private Long extraDropoffPOIID10;
private String extraDropoff10;
private Long extraDropoffTripPriceID10;
private String extraDropoffRegion10;
private BigDecimal singleTripPrice;
private BigDecimal defaultTripPrice;
private BigDecimal defaultPublishTripPrice;
private BigDecimal hourlyRate;
private BigDecimal hourlyWaitingFee;
private Integer hour;
private Integer hourlyWaiting;
private BigDecimal extraDropoffPrice1;
private BigDecimal extraDropoffPrice2;
private BigDecimal extraDropoffPrice3;
private BigDecimal extraDropoffPrice4;
private BigDecimal extraDropoffPrice5;
private BigDecimal extraDropoffPrice6;
private BigDecimal extraDropoffPrice7;
private BigDecimal extraDropoffPrice8;
private BigDecimal extraDropoffPrice9;
private BigDecimal extraDropoffPrice10;
private String otherPriceRemark;
private BigDecimal otherPrice;
private String paymentMethod;
private BigDecimal totalAmount;
private Boolean highImportance;
private Boolean tenOut;
private Boolean butlerGreet;
private String bookedBy;
private String approvedBy;
private String bookingRemark;
private String driverRemark;
private String limoInternalRemark;
private String systemRemark;
private Boolean limoGreet;
private Boolean hostGreet;
private Boolean vipMeetNGreet;
private String otherGreet;
private String flightDetails;
private String signage;
public int getCreateNotConfirmBooking() {
return createNotConfirmBooking;
}
}
@@ -1,148 +0,0 @@
package com.mgm.mcrm.common.dtos.mgm_api;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
public class InternalUpdateLimoBookingRequest {
private Long id;
private Boolean createNotConfirmBooking;
private String bookingType;
private String greetType;
private String otherGreetType;
private String guestType;
private String tripType;
private String playerId;
private String ranking;
private String overrideBy;
private String complexOverrider;
private String roomNo;
private String employeeId;
private String lastName;
private String salution;
private String chineseLastName;
private String bookerContact;
private String tripContact;
private String adHoc;
private LocalDateTime pickupDatetime;
private Long carTypeId;
private Integer passengerNo;
private Long pickupPOIID;
private String pickup;
private Long pickupTripPriceID;
private String pickupRegion;
private Long dropoffPOIID;
private String dropoff;
private Long dropoffTripPriceID;
private String dropoffRegion;
private Long extraDropoffPOIID1;
private String extraDropoff1;
private Long extraDropoffTripPriceID1;
private String extraDropoffRegion1;
private Long extraDropoffPOIID2;
private String extraDropoff2;
private Long extraDropoffTripPriceID2;
private String extraDropoffRegion2;
private Long extraDropoffPOIID3;
private String extraDropoff3;
private Long extraDropoffTripPriceID3;
private String extraDropoffRegion3;
private Long extraDropoffPOIID4;
private String extraDropoff4;
private Long extraDropoffTripPriceID4;
private String extraDropoffRegion4;
private Long extraDropoffPOIID5;
private String extraDropoff5;
private Long extraDropoffTripPriceID5;
private String extraDropoffRegion5;
private Long extraDropoffPOIID6;
private String extraDropoff6;
private Long extraDropoffTripPriceID6;
private String extraDropoffRegion6;
private Long extraDropoffPOIID7;
private String extraDropoff7;
private Long extraDropoffTripPriceID7;
private String extraDropoffRegion7;
private Long extraDropoffPOIID8;
private String extraDropoff8;
private Long extraDropoffTripPriceID8;
private String extraDropoffRegion8;
private Long extraDropoffPOIID9;
private String extraDropoff9;
private Long extraDropoffTripPriceID9;
private String extraDropoffRegion9;
private Long extraDropoffPOIID10;
private String extraDropoff10;
private Long extraDropoffTripPriceID10;
private String extraDropoffRegion10;
private BigDecimal singleTripPrice;
private BigDecimal defaultTripPrice;
private BigDecimal defaultPublishTripPrice;
private BigDecimal hourlyRate;
private BigDecimal hourlyWaitingFee;
private Integer hour;
private Integer hourlyWaiting;
private BigDecimal extraDropoffPrice1;
private BigDecimal extraDropoffPrice2;
private BigDecimal extraDropoffPrice3;
private BigDecimal extraDropoffPrice4;
private BigDecimal extraDropoffPrice5;
private BigDecimal extraDropoffPrice6;
private BigDecimal extraDropoffPrice7;
private BigDecimal extraDropoffPrice8;
private BigDecimal extraDropoffPrice9;
private BigDecimal extraDropoffPrice10;
private String otherPriceRemark;
private BigDecimal otherPrice;
private String paymentMethod;
private BigDecimal totalAmount;
private Boolean highImportance;
private Boolean tenOut;
private Boolean butlerGreet;
private String bookedBy;
private String approvedBy;
private String bookingRemark;
private String driverRemark;
private String limoInternalRemark;
private String systemRemark;
private Boolean limoGreet;
private Boolean hostGreet;
private Boolean vipMeetNGreet;
private String otherGreet;
private String flightDetails;
private String signage;
}
@@ -1,23 +0,0 @@
package com.mgm.mcrm.common.dtos.mgm_api;
public class ItemRecord {
private String ItemRecordDescription = null;
public ItemRecord() {
}
public String getItemRecordDescription() {
return ItemRecordDescription;
}
public void setItemRecordDescription(String itemRecordDescription) {
ItemRecordDescription = itemRecordDescription;
}
}
@@ -1,33 +0,0 @@
package com.mgm.mcrm.common.dtos.mgm_api;
import java.util.List;
public class NonMGMBookingApiResult {
private String statusCode;
private String statusDescription;
private List<NonMGMBookingRecord> records;
public String getStatusCode() {
return statusCode;
}
public void setStatusCode(String statusCode) {
this.statusCode = statusCode;
}
public String getStatusDescription() {
return statusDescription;
}
public void setStatusDescription(String statusDescription) {
this.statusDescription = statusDescription;
}
public List<NonMGMBookingRecord> getRecords() {
return records;
}
public void setRecords(List<NonMGMBookingRecord> records) {
this.records = records;
}
}
@@ -25,7 +25,8 @@ public enum EnumBookingStatus {
DUE_OUT_UNDERSCORE("DUE_OUT", "DUE_OUT"),
DUEOUT("DUEOUT", "DUE_OUT"),
CANCELED("CANCELED", "CANCELED"),
CANCELLED("CANCELLED", "CANCELED");
CANCELLED("CANCELLED", "CANCELED"),
NO_SHOW("No-Show", "NO_SHOW");
@Getter
private final String key;
@@ -6,13 +6,19 @@ import com.mgm.mcrm.common.utils.NetworkUtil;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.AntPathMatcher;
import java.io.IOException;
import java.util.List;
@Slf4j
public class ConfigHeaderFilter implements Filter {
private final AntPathMatcher pathMatcher = new AntPathMatcher();
@Setter
private List<String> ignoreOriginPatterns;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
@@ -23,30 +29,45 @@ public class ConfigHeaderFilter implements Filter {
}
private boolean isIgnoreOriginChecking(HttpServletRequest request){
if (ignoreOriginPatterns == null) {
return false;
}
return ignoreOriginPatterns.stream()
.anyMatch(pattern -> pathMatcher.match(pattern, request.getRequestURI()));
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
if (response instanceof HttpServletResponse httpServletResponse) {
if(httpServletResponse.getHeader("Server")!=null) {
httpServletResponse.setHeader("Server", "");
}
String origin = ((HttpServletRequest) request).getHeader("Origin");
String sanitizedOrigin = NetworkUtil.sanitizeCRLF(origin);
if (SysCommon.isAllowOriginSource(sanitizedOrigin) || "OPTIONS".equalsIgnoreCase(req.getMethod())) {
httpServletResponse.setHeader("Access-Control-Allow-Origin", sanitizedOrigin);
} else {
LogUtil.warn(ConfigHeaderFilter.class, "Origin of [" + sanitizedOrigin + "] is not allowed");
httpServletResponse.setHeader("Access-Control-Allow-Origin", "");
log.warn("Blocked request: method={}, uri={}, query={}, origin={}, referer={}, ip={}, xff={}, userAgent={}",
req.getMethod(),
req.getRequestURI(),
req.getQueryString(),
req.getHeader("Origin"),
req.getHeader("Referer"),
req.getRemoteAddr(),
req.getHeader("X-Forwarded-For"),
req.getHeader("User-Agent"));
return;
if(isIgnoreOriginChecking((HttpServletRequest)request) || "OPTIONS".equalsIgnoreCase(req.getMethod())){
httpServletResponse.setHeader("Access-Control-Allow-Origin",sanitizedOrigin);
}else{
if (SysCommon.isAllowOriginSource(sanitizedOrigin)) {
httpServletResponse.setHeader("Access-Control-Allow-Origin", sanitizedOrigin);
} else {
LogUtil.warn(ConfigHeaderFilter.class, "Origin of [" + sanitizedOrigin + "] is not allowed");
httpServletResponse.setHeader("Access-Control-Allow-Origin", "");
log.warn("Blocked request: method={}, uri={}, query={}, origin={}, referer={}, ip={}, xff={}, userAgent={}",
req.getMethod(),
req.getRequestURI(),
req.getQueryString(),
req.getHeader("Origin"),
req.getHeader("Referer"),
req.getRemoteAddr(),
req.getHeader("X-Forwarded-For"),
req.getHeader("User-Agent"));
return;
}
}
httpServletResponse.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
httpServletResponse.addHeader("Access-Control-Allow-Headers", "Content-Type,Authorization,ClientId,Refreshtoken");
@@ -55,8 +55,6 @@ public class HttpRequestOptions {
*/
private HttpContext context;
// private Map<String, Object> map;
/**
* 以json格式作为输入参数
*/
@@ -83,19 +81,19 @@ public class HttpRequestOptions {
private RequestConfig requestConfig;
/**
* 解决多线程下载时,strean被close的问题
* 当前请求的输出流
*/
private static final ThreadLocal<OutputStream> outs = new ThreadLocal<OutputStream>();
private OutputStream out;
/**
* 解决多线程处理时,url被覆盖问题
* 当前请求的 URL
*/
private static final ThreadLocal<String> urls = new ThreadLocal<String>();
private String url;
/**
* 解决多线程处理时,url被覆盖问题
* 当前请求的参数,随实例保存,避免线程复用时混入上一次请求的数据
*/
private static final ThreadLocal<Map<String,Object>> maps = new ThreadLocal<Map<String,Object>>();
private Map<String, Object> parameters;
/**
* @param client HttpClient对象
@@ -111,7 +109,7 @@ public class HttpRequestOptions {
* @return 返回当前对象
*/
public HttpRequestOptions url(String url) {
urls.set(url);
this.url = url;
return this;
}
@@ -169,20 +167,13 @@ public class HttpRequestOptions {
* @return 返回当前对象
*/
public HttpRequestOptions map(Map<String, Object> map) {
// synchronized (getClass()) {
// if(this.map==null || map==null){
// this.map = map;
// }else {
// this.map.putAll(map);;
// }
// }
Map<String, Object> m = maps.get();
if(m == null || map.isEmpty()){
m = map;
}else {
m.putAll(map);
if (map == null) {
parameters = null;
} else if (parameters == null || map.isEmpty()) {
parameters = new HashMap<>(map);
} else {
parameters.putAll(map);
}
maps.set(m);
return this;
}
@@ -192,9 +183,8 @@ public class HttpRequestOptions {
*/
public HttpRequestOptions json(String json) {
this.json = json;
Map<String, Object> map = new HashMap<String, Object>();
map.put(HttpEntityBuilder.ENTITY_JSON, json);
maps.set(map);
parameters = new HashMap<>();
parameters.put(HttpEntityBuilder.ENTITY_JSON, json);
return this;
}
@@ -222,23 +212,12 @@ public class HttpRequestOptions {
* @return 返回当前对象
*/
public HttpRequestOptions files(String[] filePaths, String inputName, boolean forceRemoveContentTypeChraset) {
// synchronized (getClass()) {
// if(this.map==null){
// this.map= new HashMap<String, Object>();
// }
// }
// map.put(Utils.ENTITY_MULTIPART, filePaths);
// map.put(Utils.ENTITY_MULTIPART+".name", inputName);
// map.put(Utils.ENTITY_MULTIPART+".rmCharset", forceRemoveContentTypeChraset);
Map<String, Object> m = maps.get();
if(m.isEmpty()){
m = new HashMap<String, Object>();
if (parameters == null) {
parameters = new HashMap<>();
}
m.put(HttpEntityBuilder.ENTITY_MULTIPART, filePaths);
m.put(HttpEntityBuilder.ENTITY_MULTIPART+".name", inputName);
m.put(HttpEntityBuilder.ENTITY_MULTIPART+".rmCharset", forceRemoveContentTypeChraset);
maps.set(m);
parameters.put(HttpEntityBuilder.ENTITY_MULTIPART, filePaths);
parameters.put(HttpEntityBuilder.ENTITY_MULTIPART+".name", inputName);
parameters.put(HttpEntityBuilder.ENTITY_MULTIPART+".rmCharset", forceRemoveContentTypeChraset);
return this;
}
@@ -273,7 +252,7 @@ public class HttpRequestOptions {
* @return 返回当前对象
*/
public HttpRequestOptions out(OutputStream out) {
outs.set(out);
this.out = out;
return this;
}
@@ -329,7 +308,7 @@ public class HttpRequestOptions {
}
public String url() {
return urls.get();
return url;
}
public HttpMethods method() {
@@ -345,8 +324,7 @@ public class HttpRequestOptions {
}
public Map<String, Object> map() {
// return map;
return maps.get();
return parameters;
}
public String json() {
@@ -366,7 +344,7 @@ public class HttpRequestOptions {
}
public OutputStream out() {
return outs.get();
return out;
}
public RequestConfig requestConfig() {
@@ -5,17 +5,10 @@ import com.mgm.mcrm.common.services.ConfigurableTrustHandler;
import lombok.Getter;
import lombok.Setter;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
import org.apache.hc.core5.ssl.SSLContexts;
import javax.net.ssl.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
/**
* SSL 工具类(基于 HttpClient 5)
@@ -105,33 +98,6 @@ public class HttpSslSupport {
}
}
/**
* 使用自定义证书(trustStore)初始化 SSLContext
*/
public HttpSslSupport customSSL(String keyStorePath, String keyStorepass) {
FileInputStream instream = null;
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
instream = new FileInputStream(new File(keyStorePath));
trustStore.load(instream, keyStorepass.toCharArray());
// 相信自己的 CA 和所有自签名证书
this.sc = SSLContexts.custom()
.loadTrustMaterial(trustStore, (chain, authType) -> true)
.build();
return this;
} catch (KeyManagementException | KeyStoreException |
NoSuchAlgorithmException | CertificateException | IOException e) {
throw new RuntimeException("初始化自定义 SSLContext 失败", e);
} finally {
if (instream != null) {
try {
instream.close();
} catch (IOException ignore) {
// ignore
}
}
}
}
/**
* 获取(或创建)指定协议版本的 {@link SSLContext}
@@ -77,6 +77,12 @@ public class BookingControlMsgConsumer {
Bookings.class
);
// booking.setApproveStatus("F");
// Integer tryTime = booking.getTryTime() != null ? booking.getTryTime() : 0;
// booking.setTryTime(tryTime + 1);
//
// bookingDao.save(booking);
bookingDao.updateProcessStatus(
booking.getId(),
0
@@ -162,16 +162,16 @@ public class ADFSUtil {
if(decodeData.getClaim("upn")!=null) {
result.setLoginId(decodeData.getClaim("upn").asString());
}
if(decodeData.getClaim("user_group")!=null) {
if(decodeData.getClaim("group_name")!=null) {
try {
List<String> groupNames = decodeData.getClaim("user_group").asList(String.class);
List<String> groupNames = decodeData.getClaim("group_name").asList(String.class);
String groupNameVal = "";
for(int i=0;i<groupNames.size();i++) {
groupNameVal += (i>0?";":"")+groupNames.get(i);
}
result.setGroupName(groupNameVal);
}catch(Exception err) {
result.setGroupName(decodeData.getClaim("user_group").asString());
result.setGroupName(decodeData.getClaim("group_name").asString());
}
}
}catch(Exception err) {
@@ -0,0 +1,36 @@
package com.mgm.mcrm.common.utils;
import java.util.Base64;
public class Base64Utils {
/**
* 使用Base64加密字符串
* @return 加密之后的字符串
*
*/
public static String encode(String data){
try {
return Base64.getEncoder().encodeToString(data.getBytes("utf8"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/**
* 使用Base64解密
* @return 解密之后的字符串
*
*/
public static String decode(String data){
try {
return new String(Base64.getDecoder().decode(data));
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
@@ -10,7 +10,6 @@ import com.mgm.mcrm.common.services.ConfigurableTrustHandler;
import jakarta.servlet.http.HttpServletRequest;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.apache.hc.client5.http.classic.methods.HttpDelete;
import org.apache.hc.client5.http.classic.methods.HttpGet;
@@ -27,16 +26,13 @@ import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
import org.apache.hc.client5.http.ssl.TrustAllStrategy;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.config.Registry;
import org.apache.hc.core5.http.config.RegistryBuilder;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.ssl.SSLContextBuilder;
import org.apache.hc.core5.util.Timeout;
import org.springframework.web.multipart.MultipartFile;
@@ -93,12 +89,13 @@ public class HttpUtil {
if(Strings.CI.startsWith(requestUrl, "https://")) {
SSLContext sslContext = null;
try {
sslContext = SSLContextBuilder.create().loadTrustMaterial(TrustAllStrategy.INSTANCE).build();
//sslContext = SSLContextBuilder.create().loadTrustMaterial(TrustAllStrategy.INSTANCE).build();
sslContext = getSSLContext();
} catch (Exception e) {
e.printStackTrace();
}
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE ))
.register("https", new SSLConnectionSocketFactory(sslContext, getTrustHandler()))
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
@@ -37,6 +37,11 @@ public class LogUtil {
getLogger(callClass).error(message);
}
public static void error(Class callClass,String message, Throwable e) {
if(SysCommon.appDebugLog == true)
getLogger(callClass).error(message, e);
}
public static String getObjectAttr(Object srcObj, String[] attrNames) {
StringBuilder attrText = new StringBuilder();
if(srcObj!=null && attrNames!=null) {
@@ -88,8 +88,8 @@ public class NetworkUtil {
private static String getIpFromHeaders(HttpServletRequest request) {
String[] headerNames = {
"X-Forwarded-For",
"X-Real-IP",
"X-Forwarded-For",
"Proxy-Client-IP",
"WL-Proxy-Client-IP",
"HTTP_CLIENT_IP",
@@ -100,7 +100,7 @@ public class NetworkUtil {
String headerValue = request.getHeader(headerName);
if (headerValue != null && !headerValue.isEmpty()) {
isContainForwardHeader=true;
LogUtil.info(NetworkUtil.class,"Check header["+headerName+"] of value["+headerValue+"]");
LogUtil.info(NetworkUtil.class,"Check Forward header["+headerName+"] of value["+headerValue+"]");
String ip = extractValidIp(headerValue);
if (ip != null) {
return ip;
File diff suppressed because it is too large Load Diff