commit
e166e442cd
10 changed files with 1125 additions and 0 deletions
@ -0,0 +1,6 @@ |
|||||||
|
# open-JSD-10048 |
||||||
|
|
||||||
|
JSD-10048 防盗链并让一部分模板直接放行\ |
||||||
|
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||||
|
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||||
|
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 |
@ -0,0 +1,20 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||||
|
<id>com.eco.plugin.xx.cjccfilter</id> |
||||||
|
<name><![CDATA[防盗链验证]]></name> |
||||||
|
<active>yes</active> |
||||||
|
<version>1.0.4</version> |
||||||
|
<env-version>10.0</env-version> |
||||||
|
<jartime>2018-07-31</jartime> |
||||||
|
<vendor>fr.open</vendor> |
||||||
|
<description><![CDATA[防盗链验证]]></description> |
||||||
|
<change-notes><![CDATA[ |
||||||
|
]]></change-notes> |
||||||
|
<main-package>com.eco.plugin.xx.cjccfilter</main-package> |
||||||
|
<lifecycle-monitor class="com.eco.plugin.xx.cjccfilter.config.InitializeMonitor"/> |
||||||
|
|
||||||
|
<extra-decision> |
||||||
|
<GlobalRequestFilterProvider class="com.eco.plugin.xx.cjccfilter.login.SSOFilter"/> |
||||||
|
</extra-decision> |
||||||
|
|
||||||
|
<function-recorder class="com.eco.plugin.xx.cjccfilter.config.PluginSimpleConfig"/> |
||||||
|
</plugin> |
@ -0,0 +1,21 @@ |
|||||||
|
package com.eco.plugin.xx.cjccfilter.config; |
||||||
|
|
||||||
|
import com.fr.plugin.context.PluginContext; |
||||||
|
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author xx |
||||||
|
* @version 10.0 |
||||||
|
* Created by xx on 2021-12-03 |
||||||
|
*/ |
||||||
|
public class InitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||||
|
@Override |
||||||
|
public void afterRun(PluginContext pluginContext) { |
||||||
|
PluginSimpleConfig.getInstance(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void beforeStop(PluginContext pluginContext) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
package com.eco.plugin.xx.cjccfilter.config; |
||||||
|
|
||||||
|
import com.fr.config.*; |
||||||
|
import com.fr.config.holder.Conf; |
||||||
|
import com.fr.config.holder.factory.Holders; |
||||||
|
import com.fr.intelli.record.Focus; |
||||||
|
import com.fr.intelli.record.Original; |
||||||
|
import com.fr.record.analyzer.EnableMetrics; |
||||||
|
|
||||||
|
@Visualization(category = "防盗链白名单配置") |
||||||
|
@EnableMetrics |
||||||
|
public class PluginSimpleConfig extends DefaultConfiguration { |
||||||
|
|
||||||
|
private static volatile PluginSimpleConfig config = null; |
||||||
|
|
||||||
|
@Focus(id="com.eco.plugin.xx.cjccfilter.config", text = "防盗链白名单配置", source = Original.PLUGIN) |
||||||
|
public static PluginSimpleConfig getInstance() { |
||||||
|
if (config == null) { |
||||||
|
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); |
||||||
|
} |
||||||
|
return config; |
||||||
|
} |
||||||
|
|
||||||
|
// @Identifier(value = "white", name = "白名单", description = "多个用英文逗号分隔", status = Status.SHOW)
|
||||||
|
// private Conf<String> white = Holders.simple("");
|
||||||
|
|
||||||
|
@Identifier(value = "errorpage", name = "错误页面地址", description = "错误页面地址", status = Status.SHOW) |
||||||
|
private Conf<String> errorpage = Holders.simple(""); |
||||||
|
|
||||||
|
// public String getWhite() {
|
||||||
|
// return white.get();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setWhite(String url) {
|
||||||
|
// this.white.set(url);
|
||||||
|
// }
|
||||||
|
|
||||||
|
public String getErrorpage() { |
||||||
|
return errorpage.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setErrorpage(String url) { |
||||||
|
this.errorpage.set(url); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object clone() throws CloneNotSupportedException { |
||||||
|
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone(); |
||||||
|
// cloned.text = (Conf<String>) text.clone();
|
||||||
|
// cloned.count = (Conf<Integer>) count.clone();
|
||||||
|
// cloned.price = (Conf<Double>) price.clone();
|
||||||
|
// cloned.time = (Conf<Long>) time.clone();
|
||||||
|
// cloned.student = (Conf<Boolean>) student.clone();
|
||||||
|
return cloned; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,124 @@ |
|||||||
|
package com.eco.plugin.xx.cjccfilter.login; |
||||||
|
|
||||||
|
import com.eco.plugin.xx.cjccfilter.config.PluginSimpleConfig; |
||||||
|
import com.eco.plugin.xx.cjccfilter.utils.FRUtils; |
||||||
|
import com.eco.plugin.xx.cjccfilter.utils.IOUtils; |
||||||
|
import com.eco.plugin.xx.cjccfilter.utils.ResponseUtils; |
||||||
|
import com.eco.plugin.xx.cjccfilter.utils.Utils; |
||||||
|
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||||
|
import com.fr.io.utils.ResourceIOUtils; |
||||||
|
import com.fr.plugin.context.PluginContexts; |
||||||
|
import com.fr.record.analyzer.EnableMetrics; |
||||||
|
import com.fr.stable.fun.Authorize; |
||||||
|
|
||||||
|
import javax.servlet.FilterChain; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
|
||||||
|
@EnableMetrics |
||||||
|
@Authorize(callSignKey = "com.eco.plugin.xx.cjccfilter") |
||||||
|
public class SSOFilter extends AbstractGlobalRequestFilterProvider { |
||||||
|
@Override |
||||||
|
public String filterName() { |
||||||
|
return "cjccFilter"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String[] urlPatterns() { |
||||||
|
return new String[]{"/*"}; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){ |
||||||
|
|
||||||
|
if(PluginContexts.currentContext().isAvailable()){ |
||||||
|
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||||
|
String url = FRUtils.getAllUrl(req); |
||||||
|
String refer = req.getHeader("Referer"); |
||||||
|
|
||||||
|
//不是模板链接放行
|
||||||
|
// if(!((url.contains("view/report") && url.contains(".cpt")) || (url.contains("view/form") && url.contains(".frm")))){
|
||||||
|
// release(req,res,chain);
|
||||||
|
// return ;
|
||||||
|
// }
|
||||||
|
if(url.contains("error.html")){ |
||||||
|
release(req,res,chain); |
||||||
|
return ; |
||||||
|
} |
||||||
|
FRUtils.FRLogInfo("refer:"+refer); |
||||||
|
// FRUtils.FRLogInfo("white:"+psc.getWhite());
|
||||||
|
//请求头为空跳转错误页面
|
||||||
|
// String refer = req.getParameter("refer");
|
||||||
|
if(Utils.isNullStr(refer)){ |
||||||
|
redirect(psc,res); |
||||||
|
return ; |
||||||
|
} |
||||||
|
|
||||||
|
//非白名单跳转错误页面
|
||||||
|
boolean inwhite = inWhite(psc,refer,url); |
||||||
|
if(!inwhite){ |
||||||
|
redirect(psc,res); |
||||||
|
return ; |
||||||
|
} |
||||||
|
}else{ |
||||||
|
ResponseUtils.failedResponse(res,"插件授权失效,请联系管理员!"); |
||||||
|
return ; |
||||||
|
} |
||||||
|
|
||||||
|
release(req,res,chain); |
||||||
|
} |
||||||
|
|
||||||
|
private static boolean inWhite(PluginSimpleConfig psc,String refer,String url) { |
||||||
|
// String[] urls = url.split("/webroot/decision");
|
||||||
|
// String frdomain = urls[0];
|
||||||
|
//
|
||||||
|
// //是否是帆软内部调用
|
||||||
|
// if(refer.startsWith(frdomain)){
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
InputStream is = ResourceIOUtils.read("/resources/config.txt"); |
||||||
|
String str = IOUtils.inputStreamToStr(is); |
||||||
|
String[] whites = str.replaceAll("\r","").split("\n"); |
||||||
|
try { |
||||||
|
is.close(); |
||||||
|
} catch (IOException e) { |
||||||
|
FRUtils.FRLogInfo("io关闭异常:"+e.getMessage()); |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
boolean isWhite = false; |
||||||
|
|
||||||
|
for(int i = 0;i< whites.length;i++){ |
||||||
|
String white = whites[i]; |
||||||
|
if(refer.startsWith(white)){ |
||||||
|
isWhite = true; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return isWhite; |
||||||
|
} |
||||||
|
|
||||||
|
//跳转认证中心
|
||||||
|
private void redirect(PluginSimpleConfig pluginSimpleConfig,HttpServletResponse res) { |
||||||
|
|
||||||
|
try { |
||||||
|
res.sendRedirect(pluginSimpleConfig.getErrorpage()); |
||||||
|
} catch (IOException e) { |
||||||
|
FRUtils.FRLogInfo("跳转错误页面异常:"+e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//放行拦截器
|
||||||
|
private void release(HttpServletRequest req, HttpServletResponse res, FilterChain chain) { |
||||||
|
try{ |
||||||
|
chain.doFilter(req,res); |
||||||
|
}catch (Exception e){ |
||||||
|
FRUtils.FRLogInfo("拦截失败"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,320 @@ |
|||||||
|
package com.eco.plugin.xx.cjccfilter.utils; |
||||||
|
|
||||||
|
import com.fr.base.ServerConfig; |
||||||
|
import com.fr.base.TableData; |
||||||
|
import com.fr.base.TemplateUtils; |
||||||
|
import com.fr.decision.authority.AuthorityContext; |
||||||
|
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType; |
||||||
|
import com.fr.decision.authority.data.User; |
||||||
|
import com.fr.decision.base.util.UUIDUtil; |
||||||
|
import com.fr.decision.privilege.encrpt.PasswordValidator; |
||||||
|
import com.fr.decision.webservice.bean.authentication.OriginUrlResponseBean; |
||||||
|
import com.fr.decision.webservice.interceptor.handler.ReportTemplateRequestChecker; |
||||||
|
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||||
|
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||||
|
import com.fr.decision.webservice.utils.DecisionStatusService; |
||||||
|
import com.fr.decision.webservice.utils.UserSourceFactory; |
||||||
|
import com.fr.decision.webservice.v10.login.LoginService; |
||||||
|
import com.fr.decision.webservice.v10.login.event.LogInOutEvent; |
||||||
|
import com.fr.decision.webservice.v10.user.UserService; |
||||||
|
import com.fr.event.EventDispatcher; |
||||||
|
import com.fr.file.TableDataConfig; |
||||||
|
import com.fr.general.data.DataModel; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.script.Calculator; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.stable.query.QueryFactory; |
||||||
|
import com.fr.stable.query.restriction.RestrictionFactory; |
||||||
|
import com.fr.third.springframework.web.method.HandlerMethod; |
||||||
|
import com.fr.web.controller.ReportRequestService; |
||||||
|
import com.fr.web.utils.WebUtils; |
||||||
|
|
||||||
|
import javax.servlet.http.Cookie; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import javax.servlet.http.HttpSession; |
||||||
|
import java.io.IOException; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class FRUtils { |
||||||
|
/** |
||||||
|
* 判断用户是否存在 |
||||||
|
* @param userName |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isUserExist(String userName){ |
||||||
|
if (StringUtils.isEmpty(userName)) { |
||||||
|
return false; |
||||||
|
} else { |
||||||
|
try { |
||||||
|
List param1 = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
||||||
|
return param1 != null && !param1.isEmpty(); |
||||||
|
} catch (Exception param2) { |
||||||
|
FineLoggerFactory.getLogger().error(param2.getMessage()); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否登录FR |
||||||
|
* @param req |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isLogin(HttpServletRequest req){ |
||||||
|
return LoginService.getInstance().isLogged(req); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 帆软登录 |
||||||
|
* @param httpServletRequest |
||||||
|
* @param httpServletResponse |
||||||
|
* @param userName |
||||||
|
* @param url |
||||||
|
*/ |
||||||
|
public static void login(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String userName,String url){ |
||||||
|
|
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:用户名:"+userName); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||||
|
|
||||||
|
|
||||||
|
//判断用户名是否为空
|
||||||
|
if(!Utils.isNullStr(userName)){ |
||||||
|
if(isUserExist(userName)){ |
||||||
|
String FRToken = ""; |
||||||
|
|
||||||
|
try { |
||||||
|
//HttpSession session = httpServletRequest.getSession(true);
|
||||||
|
|
||||||
|
FRToken = LoginService.getInstance().login(httpServletRequest, httpServletResponse, userName); |
||||||
|
|
||||||
|
//httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,FRToken);
|
||||||
|
|
||||||
|
//session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, FRToken);
|
||||||
|
EventDispatcher.fire(LogInOutEvent.LOGIN,new LogInOutResultInfo(httpServletRequest,httpServletResponse,userName,true)); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:登陆成功!"); |
||||||
|
|
||||||
|
if(!Utils.isNullStr(url)){ |
||||||
|
httpServletResponse.sendRedirect(url); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"登录异常,请联系管理员!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:登录异常,请联系管理员!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||||
|
} |
||||||
|
}else{ |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"用户在报表系统中不存在!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:用户在报表系统中不存在!"); |
||||||
|
} |
||||||
|
}else{ |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"用户名不能为空!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:用户名不能为空!"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 帆软登录 |
||||||
|
* @param httpServletRequest |
||||||
|
* @param httpServletResponse |
||||||
|
* @param token |
||||||
|
* @param url |
||||||
|
*/ |
||||||
|
public static void loginByToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String token,String url){ |
||||||
|
|
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:token:"+token); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||||
|
|
||||||
|
|
||||||
|
//判断用户名是否为空
|
||||||
|
if(!Utils.isNullStr(token)){ |
||||||
|
writeToken2Cookie(httpServletResponse,token,-1); |
||||||
|
|
||||||
|
HttpSession session = httpServletRequest.getSession(true); |
||||||
|
|
||||||
|
httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,token); |
||||||
|
|
||||||
|
session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, token); |
||||||
|
|
||||||
|
if(!Utils.isNullStr(url)){ |
||||||
|
try { |
||||||
|
httpServletResponse.sendRedirect(url); |
||||||
|
} catch (IOException e) { |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"跳转异常!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:跳转异常!"); |
||||||
|
} |
||||||
|
} |
||||||
|
}else{ |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"token不能为空!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:token不能为空!"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取token |
||||||
|
* @param httpServletRequest |
||||||
|
* @param httpServletResponse |
||||||
|
* @param username |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String username){ |
||||||
|
String token = ""; |
||||||
|
try { |
||||||
|
token = LoginService.getInstance().login(httpServletRequest, httpServletResponse, username); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:获取token失败"+e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
return token; |
||||||
|
} |
||||||
|
|
||||||
|
private static void writeToken2Cookie(HttpServletResponse param1, String param2, int param3) { |
||||||
|
try { |
||||||
|
if (StringUtils.isNotEmpty(param2)) { |
||||||
|
Cookie param4 = new Cookie("fine_auth_token", param2); |
||||||
|
long param5 = param3 == -2 ? 1209600000L : (long)param3; |
||||||
|
param4.setMaxAge((int)param5); |
||||||
|
param4.setPath(ServerConfig.getInstance().getCookiePath()); |
||||||
|
param1.addCookie(param4); |
||||||
|
Cookie param7 = new Cookie("fine_remember_login", String.valueOf(param3 == -2 ? -2 : -1)); |
||||||
|
param7.setMaxAge((int)param5); |
||||||
|
param7.setPath(ServerConfig.getInstance().getCookiePath()); |
||||||
|
param1.addCookie(param7); |
||||||
|
} else { |
||||||
|
FineLoggerFactory.getLogger().error("empty token cannot save."); |
||||||
|
} |
||||||
|
} catch (Exception param8) { |
||||||
|
FineLoggerFactory.getLogger().error(param8.getMessage(), param8); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param httpServletRequest |
||||||
|
* @param httpServletResponse |
||||||
|
*/ |
||||||
|
public static void logout(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) |
||||||
|
{ |
||||||
|
if(!isLogin(httpServletRequest)){ |
||||||
|
return ; |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
LoginService.getInstance().logout(httpServletRequest,httpServletResponse); |
||||||
|
} catch (Exception e) { |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"登出异常,请联系管理员!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:登出异常,请联系管理员!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 打印FR日志 |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void FRLogInfo(String message){ |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:"+message); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 打印FR日志-error |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void FRLogError(String message){ |
||||||
|
FineLoggerFactory.getLogger().error("FRLOG:"+message); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 根据用户名获取用户信息 |
||||||
|
* @param userName |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static User getFRUserByUserName(String userName){ |
||||||
|
try { |
||||||
|
return UserService.getInstance().getUserByUserName(userName); |
||||||
|
} catch (Exception e) { |
||||||
|
FRLogInfo("获取用户信息异常:"+e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 解密FR密码 |
||||||
|
* @param password |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
// public static String decryptFRPsd(String password){
|
||||||
|
// FRLogInfo("解密密码:"+password);
|
||||||
|
// return TransmissionTool.decrypt(password);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/** |
||||||
|
* 根据明文密码生成数据库中的密码,用户密码校验用 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getDBPsd(String username,String password){ |
||||||
|
PasswordValidator pv = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator(); |
||||||
|
String uuid = UUIDUtil.generate(); |
||||||
|
|
||||||
|
return pv.encode(username, password, uuid); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取带参数的访问链接 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getAllUrl(HttpServletRequest httpServletRequest){ |
||||||
|
return WebUtils.getOriginalURL(httpServletRequest); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据originKey获取源链接 |
||||||
|
* @param originKey |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static String getOriginUrl(String originKey) throws Exception { |
||||||
|
if (StringUtils.isNotEmpty(originKey)) { |
||||||
|
OriginUrlResponseBean originUrlResponseBean = (OriginUrlResponseBean) DecisionStatusService.originUrlStatusService().get(originKey); |
||||||
|
DecisionStatusService.originUrlStatusService().delete(originKey); |
||||||
|
if (originUrlResponseBean != null) { |
||||||
|
return originUrlResponseBean.getOriginUrl(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return new OriginUrlResponseBean(TemplateUtils.render("${fineServletURL}")).getOriginUrl(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否开启模板认证 |
||||||
|
* @param |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static boolean isTempAuth(HttpServletRequest req,HttpServletResponse res) throws Exception { |
||||||
|
ReportTemplateRequestChecker checker = new ReportTemplateRequestChecker(); |
||||||
|
HandlerMethod hm = new HandlerMethod(new ReportRequestService(),ReportRequestService.class.getMethod("preview", HttpServletRequest.class, HttpServletResponse.class, String.class)); |
||||||
|
return checker.checkRequest(req,res,hm); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取数据集数据 |
||||||
|
* @param serverDataSetName |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static DataModel getTableData(String serverDataSetName){ |
||||||
|
TableData userInfo = TableDataConfig.getInstance().getTableData(serverDataSetName); |
||||||
|
DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator()); |
||||||
|
// userInfoDM.getRowCount();
|
||||||
|
// userInfoDM.getColumnIndex();
|
||||||
|
// userInfoDM.getValueAt()
|
||||||
|
return userInfoDM; |
||||||
|
} |
||||||
|
|
||||||
|
public static String getIndex(HttpServletRequest req){ |
||||||
|
String url = req.getScheme()+"://"+req.getServerName()+":"+String.valueOf(req.getServerPort())+req.getRequestURI(); |
||||||
|
return url; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,100 @@ |
|||||||
|
package com.eco.plugin.xx.cjccfilter.utils; |
||||||
|
|
||||||
|
import java.io.*; |
||||||
|
|
||||||
|
public class IOUtils { |
||||||
|
|
||||||
|
/** |
||||||
|
* 将inputStream写入本地文件 |
||||||
|
* @param url |
||||||
|
* @param inputStream |
||||||
|
*/ |
||||||
|
public static void writeFile(String url, InputStream inputStream){ |
||||||
|
int index; |
||||||
|
byte[] bytes = new byte[1024]; |
||||||
|
FileOutputStream downloadFile = null ; |
||||||
|
try { |
||||||
|
downloadFile = new FileOutputStream(url); |
||||||
|
while ((index = inputStream.read(bytes)) != -1) { |
||||||
|
downloadFile.write(bytes, 0, index); |
||||||
|
downloadFile.flush(); |
||||||
|
} |
||||||
|
}catch(Exception e){ |
||||||
|
FRUtils.FRLogInfo("Exception:writeFile:"+e.getMessage()); |
||||||
|
}finally { |
||||||
|
try { |
||||||
|
inputStream.close(); |
||||||
|
downloadFile.close(); |
||||||
|
} |
||||||
|
catch (Exception e){ |
||||||
|
FRUtils.FRLogInfo("Exception:writeFile:finally"+e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 字符串转输入流 |
||||||
|
* @param str |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static InputStream strToInputStream(String str){ |
||||||
|
try { |
||||||
|
return new ByteArrayInputStream(str.getBytes("UTF-8")); |
||||||
|
} catch (UnsupportedEncodingException e) { |
||||||
|
FRUtils.FRLogInfo("IOUtils-strToInputStream:exception:"+e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static String inputStreamToStr(InputStream inputStream) { |
||||||
|
StringBuffer stringBuffer = new StringBuffer(); |
||||||
|
byte[] byt = new byte[4096]; |
||||||
|
|
||||||
|
try { |
||||||
|
for (int i; (i = inputStream.read(byt)) != -1; ) { |
||||||
|
stringBuffer.append(new String(byt, 0, i)); |
||||||
|
} |
||||||
|
}catch(Exception e){ |
||||||
|
FRUtils.FRLogInfo("Exception:inputStreamToStr:"+e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
return stringBuffer.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 读取txt文件 |
||||||
|
* @param file |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String readTxtFile(File file){ |
||||||
|
if(file == null || !file.isFile() || !file.exists()){ |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
String result = ""; |
||||||
|
BufferedReader br = null; |
||||||
|
try{ |
||||||
|
br = new BufferedReader(new FileReader(file)); |
||||||
|
String line = ""; |
||||||
|
while((line = br.readLine()) != null){ |
||||||
|
result += "\n"+line; |
||||||
|
} |
||||||
|
|
||||||
|
br.close(); |
||||||
|
}catch(Exception e){ |
||||||
|
FRUtils.FRLogError("读取txt文件异常!"); |
||||||
|
}finally { |
||||||
|
if(br != null){ |
||||||
|
try { |
||||||
|
br.close(); |
||||||
|
} catch (IOException e) { |
||||||
|
FRUtils.FRLogError("BufferedReader关闭异常"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
package com.eco.plugin.xx.cjccfilter.utils; |
||||||
|
|
||||||
|
import com.fr.io.utils.ResourceIOUtils; |
||||||
|
|
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.io.InputStreamReader; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
public class PropertiesUtils { |
||||||
|
// private static final String RESOURCES_PATH = "config";
|
||||||
|
// private static ResourceBundle bundle = null;
|
||||||
|
//
|
||||||
|
// static {
|
||||||
|
// bundle = ResourceBundle.getBundle(RESOURCES_PATH);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static String getProperties(String key){
|
||||||
|
// return bundle.getString(key);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取web-info下的配置文件 |
||||||
|
* @param path /resources/wz.properties |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Properties getProperties(String path){ |
||||||
|
Properties p = new Properties(); |
||||||
|
|
||||||
|
try{ |
||||||
|
InputStream is = ResourceIOUtils.read(path); |
||||||
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); |
||||||
|
p.load(bufferedReader); |
||||||
|
}catch(Exception e){ |
||||||
|
FRUtils.FRLogInfo("获取配置文件异常"); |
||||||
|
} |
||||||
|
|
||||||
|
return p; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,108 @@ |
|||||||
|
package com.eco.plugin.xx.cjccfilter.utils; |
||||||
|
|
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.web.utils.WebUtils; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.PrintWriter; |
||||||
|
|
||||||
|
public class ResponseUtils { |
||||||
|
private static final int SUCCESS = 200; |
||||||
|
private static final int FAILED = -1; |
||||||
|
|
||||||
|
public static void successResponse(HttpServletResponse res, String body) { |
||||||
|
response(res, body, SUCCESS); |
||||||
|
} |
||||||
|
|
||||||
|
public static void failedResponse(HttpServletResponse res, String body) { |
||||||
|
response(res, body, FAILED); |
||||||
|
} |
||||||
|
|
||||||
|
private static void response(HttpServletResponse res, String body, int code) { |
||||||
|
JSONObject object = new JSONObject(); |
||||||
|
PrintWriter pw; |
||||||
|
try { |
||||||
|
object.put("code", code); |
||||||
|
object.put("data", body); |
||||||
|
pw = WebUtils.createPrintWriter(res); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||||
|
return; |
||||||
|
} |
||||||
|
res.setContentType("application/json;charset=utf-8"); |
||||||
|
String result = object.toString(); |
||||||
|
pw.println(result); |
||||||
|
pw.flush(); |
||||||
|
pw.close(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void response(HttpServletResponse res,JSONObject json){ |
||||||
|
PrintWriter pw; |
||||||
|
try { |
||||||
|
pw = WebUtils.createPrintWriter(res); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||||
|
return; |
||||||
|
} |
||||||
|
res.setContentType("application/json;charset=utf-8"); |
||||||
|
String result = json.toString(); |
||||||
|
pw.println(result); |
||||||
|
pw.flush(); |
||||||
|
pw.close(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void responseText(HttpServletResponse res,String text){ |
||||||
|
PrintWriter pw; |
||||||
|
try { |
||||||
|
pw = WebUtils.createPrintWriter(res); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||||
|
return; |
||||||
|
} |
||||||
|
res.setContentType("text/html;charset=utf-8"); |
||||||
|
pw.println(text); |
||||||
|
pw.flush(); |
||||||
|
pw.close(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void responseXml(HttpServletResponse res,String xml){ |
||||||
|
PrintWriter pw; |
||||||
|
try { |
||||||
|
pw = WebUtils.createPrintWriter(res); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||||
|
return; |
||||||
|
} |
||||||
|
res.setContentType("text/xml;charset=utf-8"); |
||||||
|
pw.println(xml); |
||||||
|
pw.flush(); |
||||||
|
pw.close(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void setCSRFHeader(HttpServletResponse httpServletResponse){ |
||||||
|
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); |
||||||
|
httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,HEAD,PUT,PATCH"); |
||||||
|
httpServletResponse.setHeader("Access-Control-Max-Age", "36000"); |
||||||
|
httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization,authorization"); |
||||||
|
} |
||||||
|
|
||||||
|
public static void responseJsonp(HttpServletRequest req, HttpServletResponse res, JSONObject json){ |
||||||
|
PrintWriter pw; |
||||||
|
try { |
||||||
|
pw = WebUtils.createPrintWriter(res); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||||
|
return; |
||||||
|
} |
||||||
|
res.setContentType("text/javascript;charset=utf-8;charset=utf-8"); |
||||||
|
String result = json.toString(); |
||||||
|
|
||||||
|
String jsonp=req.getParameter("callback"); |
||||||
|
|
||||||
|
pw.println(jsonp+"("+result+")"); |
||||||
|
pw.flush(); |
||||||
|
pw.close(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,329 @@ |
|||||||
|
package com.eco.plugin.xx.cjccfilter.utils; |
||||||
|
|
||||||
|
import com.fr.base.TemplateUtils; |
||||||
|
import com.fr.data.NetworkHelper; |
||||||
|
import com.fr.decision.webservice.v10.user.UserService; |
||||||
|
import com.fr.io.utils.ResourceIOUtils; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.stable.CodeUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||||
|
import com.fr.web.utils.WebUtils; |
||||||
|
|
||||||
|
import javax.servlet.http.Cookie; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.net.URLEncoder; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.UUID; |
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
public class Utils { |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断字符串是否为空 |
||||||
|
* @param str |
||||||
|
* @return true 空字符串 false 非空字符串 |
||||||
|
*/ |
||||||
|
public static boolean isNullStr(String str){ |
||||||
|
return !(str != null && !str.isEmpty() && !"null".equals(str)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断字符串是否非空 |
||||||
|
* @param str |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isNotNullStr(String str){ |
||||||
|
return !isNullStr(str); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* MD5加密 |
||||||
|
* @param str |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getMd5Str(String str) |
||||||
|
{ |
||||||
|
return DigestUtils.md5Hex(str); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 帆软shaEncode加密 |
||||||
|
*/ |
||||||
|
|
||||||
|
public static String shaEncode(String str){ |
||||||
|
return CodeUtils.sha256Encode(str); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取uuid |
||||||
|
*/ |
||||||
|
public static String uuid(){ |
||||||
|
return UUID.randomUUID().toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 替换空字符串 |
||||||
|
* @param str |
||||||
|
* @param replace |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String replaceNullStr(String str,String replace){ |
||||||
|
if(isNullStr(str)){ |
||||||
|
return replace; |
||||||
|
} |
||||||
|
|
||||||
|
return str; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取请求体 |
||||||
|
* @param req |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static JSONObject getRequestBody(HttpServletRequest req){ |
||||||
|
StringBuffer sb = new StringBuffer(); |
||||||
|
String line = null; |
||||||
|
try { |
||||||
|
BufferedReader reader = req.getReader(); |
||||||
|
while ((line = reader.readLine()) != null) |
||||||
|
sb.append(line); |
||||||
|
} catch (Exception e) { |
||||||
|
FRUtils.FRLogInfo("getRequestBody:exception:"+e.getMessage()); |
||||||
|
} |
||||||
|
//将空格和换行符替换掉避免使用反序列化工具解析对象时失败
|
||||||
|
String jsonString = sb.toString().replaceAll("\\s","").replaceAll("\n",""); |
||||||
|
|
||||||
|
JSONObject json = new JSONObject(jsonString); |
||||||
|
|
||||||
|
return json; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取ip |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getIp(HttpServletRequest req){ |
||||||
|
String realIp = req.getHeader("X-Real-IP"); |
||||||
|
String fw = req.getHeader("X-Forwarded-For"); |
||||||
|
if (StringUtils.isNotEmpty(fw) && !"unKnown".equalsIgnoreCase(fw)) { |
||||||
|
int param3 = fw.indexOf(","); |
||||||
|
return param3 != -1 ? fw.substring(0, param3) : fw; |
||||||
|
} else { |
||||||
|
fw = realIp; |
||||||
|
if (StringUtils.isNotEmpty(realIp) && !"unKnown".equalsIgnoreCase(realIp)) { |
||||||
|
return realIp; |
||||||
|
} else { |
||||||
|
if (StringUtils.isBlank(realIp) || "unknown".equalsIgnoreCase(realIp)) { |
||||||
|
fw = req.getHeader("Proxy-Client-IP"); |
||||||
|
} |
||||||
|
|
||||||
|
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||||
|
fw = req.getHeader("WL-Proxy-Client-IP"); |
||||||
|
} |
||||||
|
|
||||||
|
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||||
|
fw = req.getHeader("HTTP_CLIENT_IP"); |
||||||
|
} |
||||||
|
|
||||||
|
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||||
|
fw = req.getHeader("HTTP_X_FORWARDED_FOR"); |
||||||
|
} |
||||||
|
|
||||||
|
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||||
|
fw = req.getRemoteAddr(); |
||||||
|
} |
||||||
|
|
||||||
|
return fw; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据key获取cookie |
||||||
|
* @param req |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getCookieByKey(HttpServletRequest req,String key){ |
||||||
|
Cookie[] cookies = req.getCookies(); |
||||||
|
String cookie = ""; |
||||||
|
|
||||||
|
if(cookies == null || cookies.length <=0){ |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
for(int i = 0; i < cookies.length; i++) { |
||||||
|
Cookie item = cookies[i]; |
||||||
|
if (item.getName().equalsIgnoreCase(key)) { |
||||||
|
cookie = item.getValue(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
FRUtils.FRLogInfo("cookie:"+cookie); |
||||||
|
|
||||||
|
return cookie; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否是手机端的链接 |
||||||
|
* @param req |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isMobile(HttpServletRequest req) { |
||||||
|
String[] mobileArray = {"iPhone", "iPad", "android", "windows phone", "xiaomi"}; |
||||||
|
String userAgent = req.getHeader("user-agent"); |
||||||
|
if (userAgent != null && userAgent.toUpperCase().contains("MOBILE")) { |
||||||
|
for(String mobile : mobileArray) { |
||||||
|
if(userAgent.toUpperCase().contains(mobile.toUpperCase())) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return NetworkHelper.getDevice(req).isMobile(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 只编码中文 |
||||||
|
* @param url |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String encodeCH(String url ){ |
||||||
|
Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(url); |
||||||
|
|
||||||
|
while(matcher.find()){ |
||||||
|
String chn = matcher.group(); |
||||||
|
url = url.replaceAll(chn, URLEncoder.encode(chn)); |
||||||
|
} |
||||||
|
|
||||||
|
return url; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取web-inf文件夹下的文件 |
||||||
|
* filename /resources/ip4enc.properties |
||||||
|
*/ |
||||||
|
public static InputStream getResourcesFile(String filename){ |
||||||
|
return ResourceIOUtils.read(filename); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param res |
||||||
|
* @param path /com/fr/plugin/loginAuth/html/getMac.html |
||||||
|
* @param parameterMap |
||||||
|
*/ |
||||||
|
public static void toErrorPage(HttpServletResponse res,String path,Map<String, String> parameterMap){ |
||||||
|
if(parameterMap == null){ |
||||||
|
parameterMap = new HashMap<String, String>(); |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
String macPage = TemplateUtils.renderTemplate(path, parameterMap); |
||||||
|
WebUtils.printAsString(res, macPage); |
||||||
|
}catch (Exception e){ |
||||||
|
FRUtils.FRLogError("跳转页面异常"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否是管理员 |
||||||
|
* @param username |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isAdmin(String username) throws Exception{ |
||||||
|
return UserService.getInstance().isAdmin(UserService.getInstance().getUserByUserName(username).getId()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 去掉浏览器中的参数 |
||||||
|
* @param url |
||||||
|
* @param param |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String removeParam(String url,String param){ |
||||||
|
if(!url.contains("?"+param) && !url.contains("&"+param)){ |
||||||
|
return url; |
||||||
|
} |
||||||
|
|
||||||
|
return url.substring(0,url.indexOf(url.contains("?"+param) ? "?"+param : "&"+param)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取跳转链接 |
||||||
|
* @param req |
||||||
|
* @param param |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getRedirectUrl(HttpServletRequest req,String param){ |
||||||
|
String url = FRUtils.getAllUrl(req); |
||||||
|
|
||||||
|
if(isNotNullStr(param)){ |
||||||
|
url = removeParam(url,param); |
||||||
|
} |
||||||
|
|
||||||
|
url = encodeCH(url); |
||||||
|
|
||||||
|
return url; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 去除空格换行 |
||||||
|
* @param str |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String trim(String str){ |
||||||
|
return str.trim().replaceAll("\n","").replaceAll("\r",""); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* list 转化为指定字符分割的字符串 |
||||||
|
* @param list |
||||||
|
* @param list |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String listToStr(List<String> list, String split){ |
||||||
|
String result = ""; |
||||||
|
|
||||||
|
if(list == null || list.size() <= 0){ |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
for(String str : list){ |
||||||
|
result+=","+str; |
||||||
|
} |
||||||
|
|
||||||
|
result = result.substring(1); |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* array 转化为指定字符分割的字符串 |
||||||
|
* @param list |
||||||
|
* @param list |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String arrayToStr(String[] list, String split){ |
||||||
|
String result = ""; |
||||||
|
|
||||||
|
if(list == null ||list.length <= 0){ |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
for(int i=0;i<list.length;i++){ |
||||||
|
String str = list[i]; |
||||||
|
result+=","+str; |
||||||
|
} |
||||||
|
|
||||||
|
result = result.substring(1); |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue