增加ctxPath参数,当映射根路径不同的时候使用

This commit is contained in:
thinkgem
2024-05-28 14:39:15 +08:00
parent 5c09f28266
commit d3de1eb957
13 changed files with 72 additions and 85 deletions

View File

@@ -38,7 +38,6 @@ public class CmsUtils {
private static final SiteService siteService = SpringUtils.getBean(SiteService.class);
private static final CategoryService categoryService = SpringUtils.getBean(CategoryService.class);
private static final ArticleService articleService = SpringUtils.getBean(ArticleService.class);
private static final ServletContext context = SpringUtils.getBean(ServletContext.class);
}
/**
@@ -243,7 +242,7 @@ public class CmsUtils {
*/
public static String getUrlDynamic(Article article) {
StringBuilder str = new StringBuilder();
str.append(Static.context.getContextPath());
str.append(Global.getCtxPath());
if (StringUtils.isNotBlank(article.getHref())) {
if (article.getHref().contains("://")) {
return article.getHref();
@@ -265,7 +264,7 @@ public class CmsUtils {
*/
public static String getUrlDynamic(Category category) {
StringBuilder str = new StringBuilder();
str.append(Static.context.getContextPath()).append(Global.getFrontPath());
str.append(Global.getCtxPath()).append(Global.getFrontPath());
if (StringUtils.isNotBlank(category.getHref())) {
if (category.getHref().contains("://")) {
return category.getHref();
@@ -285,7 +284,7 @@ public class CmsUtils {
*/
public static String getUrlDynamic(Site site) {
StringBuilder str = new StringBuilder();
str.append(Static.context.getContextPath()).append(Global.getFrontPath());
str.append(Global.getCtxPath()).append(Global.getFrontPath());
if (StringUtils.isNotBlank(site.getDomain())) {
if (site.getDomain().contains("://")) {
return site.getDomain();
@@ -305,7 +304,7 @@ public class CmsUtils {
*/
public static String getAdminUrlDynamic(Category category) {
StringBuilder str = new StringBuilder();
str.append(Static.context.getContextPath()).append(Global.getAdminPath());
str.append(Global.getCtxPath()).append(Global.getAdminPath());
String adminUrlParam = null; // 管理地址的参数
// 如果试图配置里配置了管理路径,则使用视图中的管理路径
if (StringUtils.isNotBlank(category.getViewConfig())) {
@@ -389,8 +388,8 @@ public class CmsUtils {
if (StringUtils.isBlank(src)) {
return src;
}
if (src.startsWith(Static.context.getContextPath() + "/userfiles")) {
return src.substring(Static.context.getContextPath().length());
if (src.startsWith(Global.getCtxPath() + "/userfiles")) {
return src.substring(Global.getCtxPath().length());
} else {
return src;
}
@@ -405,10 +404,10 @@ public class CmsUtils {
if (StringUtils.isBlank(src)) {
return src;
}
if (src.startsWith(Static.context.getContextPath() + "/userfiles")) {
if (src.startsWith(Global.getCtxPath() + "/userfiles")) {
return src;
} else {
return Static.context.getContextPath() + src;
return Global.getCtxPath() + src;
}
}
@@ -494,10 +493,6 @@ public class CmsUtils {
return Static.articleService;
}
public static ServletContext getServletContext() {
return Static.context;
}
public static <V> V getCache(String key) {
return CacheUtils.get(CMS_CACHE, key);
}

View File

@@ -105,8 +105,9 @@ public class FrontController extends BaseController {
// 如果设置了外部链接,则跳转到指定链接
if (StringUtils.isNotBlank(category.getHref())) {
if (category.getHref().startsWith(request.getContextPath())) {
category.setHref(category.getHref().replaceFirst(request.getContextPath(), ""));
String ctxPath = Global.getCtxPath();
if (category.getHref().startsWith(ctxPath)) {
category.setHref(category.getHref().replaceFirst(ctxPath, StringUtils.EMPTY));
}
return REDIRECT + category.getHref();
}
@@ -266,8 +267,9 @@ public class FrontController extends BaseController {
// 如果设置了外部链接,则跳转到指定链接
if (StringUtils.isNotBlank(article.getHref())) {
if (article.getHref().startsWith(request.getContextPath())) {
article.setHref(article.getHref().replaceFirst(request.getContextPath(), ""));
String ctxPath = Global.getCtxPath();
if (article.getHref().startsWith(ctxPath)) {
article.setHref(article.getHref().replaceFirst(ctxPath, StringUtils.EMPTY));
}
return REDIRECT + article.getHref();
}

View File

@@ -4,23 +4,21 @@
*/
package com.jeesite.common.shiro.filter;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.UnauthorizedException;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.util.WebUtils;
import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.config.Global;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.web.http.ServletUtils;
import com.jeesite.common.web.http.wrapper.GetHttpServletRequestWrapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.UnauthorizedException;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.util.WebUtils;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
/**
* 权限字符串过滤器
@@ -65,7 +63,8 @@ public class PermissionsFilter extends org.apache.shiro.web.filter.authz.Permiss
// AJAX不支持Redirect改用Forward
String loginUrl = Global.getProperty("shiro.defaultPath");
HttpServletRequest req = ((HttpServletRequest) request);
if (StringUtils.equals(req.getContextPath()+loginUrl, req.getRequestURI())){
if (StringUtils.equals(Global.getCtxPath() + loginUrl, req.getRequestURI())){
loginUrl = Global.getProperty("shiro.loginUrl");
}
if (ServletUtils.isAjaxRequest(req)) {

View File

@@ -1,9 +1,5 @@
package com.jeesite.common.ueditor;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.jeesite.common.config.Global;
import com.jeesite.common.ueditor.define.ActionMap;
import com.jeesite.common.ueditor.define.AppInfo;
@@ -12,6 +8,9 @@ import com.jeesite.common.ueditor.define.State;
import com.jeesite.common.ueditor.hunter.FileManager;
import com.jeesite.common.ueditor.hunter.ImageHunter;
import com.jeesite.common.ueditor.upload.Uploader;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
public class ActionEnter {
@@ -32,7 +31,7 @@ public class ActionEnter {
this.request = request;
this.rootPath = rootPath;
this.actionType = actionType;
this.contextPath = request.getContextPath();
this.contextPath = Global.getCtxPath();
this.configManager = ConfigManager.getInstance(this.rootPath, this.contextPath, request.getRequestURI());
}

View File

@@ -1,19 +1,18 @@
package com.jeesite.common.ueditor.hunter;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import com.jeesite.common.config.Global;
import com.jeesite.common.ueditor.PathFormat;
import com.jeesite.common.ueditor.define.AppInfo;
import com.jeesite.common.ueditor.define.BaseState;
import com.jeesite.common.ueditor.define.MultiState;
import com.jeesite.common.ueditor.define.State;
import org.apache.commons.io.FileUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
public class FileManager {
@@ -70,7 +69,7 @@ public class FileManager {
if (index >= 0) {
url = url.substring(index + USERFILES_BASE_URL.length());
}
fileState.putInfo("url", request.getContextPath() + USERFILES_BASE_URL + url);
fileState.putInfo("url", Global.getCtxPath() + USERFILES_BASE_URL + url);
state.addState(fileState);
}
return state;

View File

@@ -1,5 +1,12 @@
package com.jeesite.common.ueditor.hunter;
import com.jeesite.common.config.Global;
import com.jeesite.common.ueditor.PathFormat;
import com.jeesite.common.ueditor.define.*;
import com.jeesite.common.ueditor.upload.StorageManager;
import org.apache.commons.io.IOUtils;
import javax.servlet.http.HttpServletRequest;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URL;
@@ -8,18 +15,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.IOUtils;
import com.jeesite.common.ueditor.PathFormat;
import com.jeesite.common.ueditor.define.AppInfo;
import com.jeesite.common.ueditor.define.BaseState;
import com.jeesite.common.ueditor.define.MIMEType;
import com.jeesite.common.ueditor.define.MultiState;
import com.jeesite.common.ueditor.define.State;
import com.jeesite.common.ueditor.upload.StorageManager;
/**
* 图片抓取器
*
@@ -80,7 +75,7 @@ public class ImageHunter {
String physicalPath = this.rootPath + savePath;
State state = StorageManager.saveFileByInputStream(connection.getInputStream(), physicalPath);
if (state.isSuccess()) {
state.putInfo("url", request.getContextPath() + PathFormat.format(savePath));
state.putInfo("url", Global.getCtxPath() + PathFormat.format(savePath));
state.putInfo("source", urlStr);
}
return state;

View File

@@ -1,16 +1,15 @@
package com.jeesite.common.ueditor.upload;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.codec.binary.Base64;
import com.jeesite.common.config.Global;
import com.jeesite.common.ueditor.PathFormat;
import com.jeesite.common.ueditor.define.AppInfo;
import com.jeesite.common.ueditor.define.BaseState;
import com.jeesite.common.ueditor.define.FileType;
import com.jeesite.common.ueditor.define.State;
import org.apache.commons.codec.binary.Base64;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
public final class Base64Uploader {
@@ -27,8 +26,8 @@ public final class Base64Uploader {
String physicalPath = (String) conf.get("rootPath") + savePath;
State storageState = StorageManager.saveBinaryFile(data, physicalPath);
if (storageState.isSuccess()) {
String ctx = request.getContextPath(); // ThinkGem 修正上传图片后返回无contextpath问题
storageState.putInfo("url", ctx + PathFormat.format(savePath));
String ctxPath = Global.getCtxPath(); // ThinkGem 修正上传图片后返回无contextpath问题
storageState.putInfo("url", ctxPath + PathFormat.format(savePath));
storageState.putInfo("type", suffix);
storageState.putInfo("original", "");

View File

@@ -1,5 +1,6 @@
package com.jeesite.common.ueditor.upload;
import com.jeesite.common.config.Global;
import com.jeesite.common.image.ImageUtils;
import com.jeesite.common.io.FileUtils;
import com.jeesite.common.media.VideoUtils;
@@ -73,7 +74,7 @@ public class BinaryUploader {
if (storageState != null && storageState.isSuccess()) {
int actionCode = ((Integer) conf.get("actionCode")).intValue();
String ctx = request.getContextPath(); // ThinkGem 修正上传图片后返回无contextpath问题
String ctxPath = Global.getCtxPath(); // ThinkGem 修正上传图片后返回无contextpath问题
// 上传图片后,进行图片压缩
if (actionCode == ActionMap.UPLOAD_IMAGE) {
@@ -105,7 +106,7 @@ public class BinaryUploader {
};
thread.setDaemon(true);
thread.start();
storageState.putInfo("url", ctx + PathFormat.format(savePath) + "." + v.getOutputFileExtension());
storageState.putInfo("url", ctxPath + PathFormat.format(savePath) + "." + v.getOutputFileExtension());
storageState.putInfo("type", "." + v.getOutputFileExtension());
storageState.putInfo("original", originFileName + "." + v.getInputFileExtension());
@@ -115,7 +116,7 @@ public class BinaryUploader {
return storageState;
}
}
storageState.putInfo("url", ctx + PathFormat.format(savePath));
storageState.putInfo("url", ctxPath + PathFormat.format(savePath));
storageState.putInfo("type", suffix);
storageState.putInfo("original", originFileName + suffix);

View File

@@ -8,10 +8,8 @@ import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.ueditor.define.AppInfo;
import com.jeesite.common.ueditor.define.BaseState;
import com.jeesite.common.ueditor.define.State;
import com.jeesite.common.web.http.ServletUtils;
import com.jeesite.modules.file.utils.FileUploadUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
public class StorageManager {
@@ -204,8 +202,7 @@ public class StorageManager {
String url = FileUploadUtils.ossFileUpload(file, StringUtils.substringAfter(
FileUtils.path(file.getAbsolutePath()), Global.USERFILES_BASE_URL));
if (!StringUtils.contains(url, "://")) {
HttpServletRequest request = ServletUtils.getRequest();
url = FileUtils.path((request != null ? request.getContextPath() : StringUtils.EMPTY) + url);
url = FileUtils.path(Global.getCtxPath() + url);
}
storageState.putInfo("url", url);
}

View File

@@ -117,8 +117,7 @@ public class LogUtils {
Object targetData = request.getAttribute(WebDataBinder.class.getName()+".TARGET");
// 异步保存日志
logThreadPool.submit(new SaveLogThread(log, handler, request.getContextPath(),
throwable, sourceData, targetData));
logThreadPool.submit(new SaveLogThread(log, handler, Global.getCtxPath(), throwable, sourceData, targetData));
}
/**
* 保存日志线程

View File

@@ -230,10 +230,11 @@ public class LoginController extends BaseController{
successUrl = (String)request.getAttribute("__url");
}
if (StringUtils.contains(successUrl, "://")){
String ctxPath = Global.getCtxPath();
String domain = ServletUtils.getRequestDomain(successUrl);
successUrl = StringUtils.substring(successUrl, domain.length());
if (StringUtils.startsWith(successUrl, request.getContextPath())) {
successUrl = StringUtils.substringAfter(successUrl, request.getContextPath());
if (StringUtils.startsWith(successUrl, ctxPath)) {
successUrl = StringUtils.substringAfter(successUrl, ctxPath);
}
}
if (StringUtils.isBlank(successUrl)){
@@ -251,7 +252,7 @@ public class LoginController extends BaseController{
}
model.addAttribute("sessionid", (String)session.getId());
if (!StringUtils.contains(successUrl, "://")){
successUrl = request.getContextPath() + successUrl;
successUrl = Global.getCtxPath() + successUrl;
}
model.addAttribute("__url", successUrl); // 告诉浏览器登录后跳转的页面
// 初始密码策略和密码修改策略验证0关闭1提醒用户2强制修改初始或旧密码