LAPTOP-SB56SG4Q\86185
3 years ago
12 changed files with 861 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-8829 |
||||
|
||||
JSD-8829 cognos单点 |
||||
JSD-8829 cognos单点 开源任务材料\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.fr.plugin.cogons</id> |
||||
<name><![CDATA[cogons集成]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.3</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[cogons集成]]></description> |
||||
<change-notes><![CDATA[ |
||||
]]></change-notes> |
||||
<main-package>com.fr.plugin.cogons</main-package> |
||||
<extra-decision> |
||||
<HttpHandlerProvider class="com.fr.plugin.cogons.handler.ExtendAttrHandlerProvider"/> |
||||
<URLAliasProvider class="com.fr.plugin.cogons.handler.URLAliasProvide"/> |
||||
</extra-decision> |
||||
|
||||
<function-recorder class="com.fr.plugin.cogons.handler.ShowCogons"/> |
||||
</plugin> |
@ -0,0 +1,13 @@
|
||||
package com.fr.plugin.cogons.handler; |
||||
|
||||
import com.fr.decision.fun.HttpHandler; |
||||
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||
|
||||
public class ExtendAttrHandlerProvider extends AbstractHttpHandlerProvider { |
||||
@Override |
||||
public HttpHandler[] registerHandlers() { |
||||
return new HttpHandler[]{ |
||||
new ShowCogons(),new Test() |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,121 @@
|
||||
package com.fr.plugin.cogons.handler; |
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.file.TableDataConfig; |
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.plugin.cogons.utils.FRUserUtils; |
||||
import com.fr.plugin.cogons.utils.FRUtils; |
||||
import com.fr.plugin.cogons.utils.ResponseUtils; |
||||
import com.fr.plugin.cogons.utils.Utils; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@FunctionRecorder |
||||
public class ShowCogons extends BaseHttpHandler { |
||||
|
||||
|
||||
public ShowCogons() { |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/showCogons"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
boolean isIE = isIEBrowser(req); |
||||
//获取请求参数
|
||||
String action = req.getParameter("action"); |
||||
|
||||
if(isIE){ |
||||
action = Utils.encodeCH(action); |
||||
} |
||||
//当前登录名
|
||||
String username = null; |
||||
try { |
||||
username = FRUserUtils.getCurrentUser(req).getUserName(); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(res,"获取当前登录用户失败"); |
||||
} |
||||
|
||||
//获取orgId
|
||||
// String orgId = "11";
|
||||
String orgId = getOrgId(username); |
||||
|
||||
if(Utils.isNullStr(orgId)){ |
||||
ResponseUtils.failedResponse(res,"获取"+username+"orgId失败!"); |
||||
} |
||||
|
||||
Map<String, String> parameterMap = new HashMap<String, String>(); |
||||
String path = "/com/fr/plugin/cogons/html/cogons.html"; |
||||
parameterMap.put("action", action); |
||||
parameterMap.put("orgId", orgId); |
||||
String macPage = TemplateUtils.renderTemplate(path, parameterMap); |
||||
WebUtils.printAsString(res, macPage); |
||||
} |
||||
|
||||
private static String getOrgId(String username){ |
||||
FRUtils.FRLogInfo("username:"+username); |
||||
|
||||
//orgid
|
||||
String orgId = ""; |
||||
//获取服务器数据集
|
||||
TableData userInfo = TableDataConfig.getInstance().getTableData("userInfo"); |
||||
DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator()); |
||||
|
||||
try{ |
||||
//获取行号
|
||||
int rowCount = userInfoDM.getRowCount(); |
||||
FRUtils.FRLogInfo("rowCount " + rowCount); |
||||
//获取用户id,机构号列号
|
||||
int useridIndex = userInfoDM.getColumnIndex("用户ID"); |
||||
int orgidIndex = userInfoDM.getColumnIndex("核心机构号"); |
||||
|
||||
for(int i =0;i<rowCount;i++){ |
||||
String userId =String.valueOf(userInfoDM.getValueAt(i,useridIndex)); |
||||
|
||||
if(username.equals(userId)){ |
||||
orgId = String.valueOf(userInfoDM.getValueAt(i,orgidIndex)); |
||||
break; |
||||
} |
||||
} |
||||
}catch (Exception e){ |
||||
FRUtils.FRLogError("获取orgId异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return orgId; |
||||
} |
||||
|
||||
public boolean isIEBrowser(HttpServletRequest request) { |
||||
String[] IEBrowserSignals = {"MSIE", "Trident", "Edge"}; |
||||
String userAgent = request.getHeader("User-Agent"); |
||||
for (String signal : IEBrowserSignals) { |
||||
if (userAgent.contains(signal)){ |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,48 @@
|
||||
package com.fr.plugin.cogons.handler; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.net.URLEncoder; |
||||
|
||||
@FunctionRecorder |
||||
public class Test extends BaseHttpHandler { |
||||
|
||||
|
||||
public Test() { |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/test"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) { |
||||
String a = req.getHeader("User-Agent"); |
||||
System.out.println(a); |
||||
System.out.println(req.getParameter("test")); |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
System.out.println(URLEncoder.encode("测试")); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,16 @@
|
||||
package com.fr.plugin.cogons.handler; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractURLAliasProvider; |
||||
import com.fr.decision.webservice.url.alias.URLAlias; |
||||
import com.fr.decision.webservice.url.alias.URLAliasFactory; |
||||
|
||||
public class URLAliasProvide extends AbstractURLAliasProvider { |
||||
@Override |
||||
public URLAlias[] registerAlias() { |
||||
return new URLAlias[]{ |
||||
URLAliasFactory.createPluginAlias("/showCogons","/showCogons",true), |
||||
URLAliasFactory.createPluginAlias("/test","/test",true), |
||||
|
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,123 @@
|
||||
package com.fr.plugin.cogons.utils; |
||||
|
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.privilege.TransmissionTool; |
||||
import com.fr.decision.webservice.bean.user.UserBean; |
||||
import com.fr.decision.webservice.bean.user.UserUpdateBean; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
public class FRUserUtils { |
||||
|
||||
/** |
||||
* 获取用户Service |
||||
* @return |
||||
*/ |
||||
public static UserService getUserService(){ |
||||
return UserService.getInstance(); |
||||
} |
||||
|
||||
/** |
||||
* 添加用户 |
||||
* @param userBean |
||||
*/ |
||||
public static void addUser(UserBean userBean) throws Exception { |
||||
userBean.setPassword(TransmissionTool.defaultEncrypt(userBean.getPassword())); |
||||
getUserService().addUser(userBean); |
||||
} |
||||
|
||||
// /**
|
||||
// * 删除用户
|
||||
// * @param userBean
|
||||
// */
|
||||
// public static void updateUser(UserBean userBean) throws Exception {
|
||||
// getUserService().editUser(userBean);
|
||||
// }
|
||||
|
||||
/** |
||||
* 删除用户 |
||||
* @param user |
||||
* @return |
||||
*/ |
||||
public static int deleteUser(User user) throws Exception { |
||||
String userId = user.getId(); |
||||
|
||||
UserUpdateBean userUpdateBean = new UserUpdateBean(); |
||||
userUpdateBean.setRemoveUserIds(new String[]{userId}); |
||||
|
||||
return getUserService().deleteUsers(userUpdateBean); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户实体 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static User getUserByUserName(String userName) throws Exception { |
||||
return getUserService().getUserByUserName(userName); |
||||
} |
||||
|
||||
/** |
||||
* 根据id获取用户 |
||||
* @param id |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static UserBean getUser(String id) throws Exception { |
||||
return getUserService().getUser(id); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是管理员 |
||||
* @param userId |
||||
* @return |
||||
*/ |
||||
public static boolean isAdmin(String userId){ |
||||
return getUserService().isAdmin(userId); |
||||
} |
||||
|
||||
/** |
||||
* 禁用启用用户 |
||||
* @param userId |
||||
* @param state false 禁用 true 启用 |
||||
* @throws Exception 异常说明失败 |
||||
*/ |
||||
public static void forbidUser(String userId,boolean state) throws Exception { |
||||
getUserService().forbidUser(userId,state); |
||||
} |
||||
|
||||
/** |
||||
* 修改用户部门 |
||||
* @param departmentId |
||||
* @param postId |
||||
* @param ud |
||||
* @throws Exception |
||||
*/ |
||||
public static void updateDepartmentPostUsers(String departmentId, String postId, UserUpdateBean ud) throws Exception { |
||||
getUserService().updateDepartmentPostUsers(departmentId,postId,ud); |
||||
} |
||||
|
||||
|
||||
// /**
|
||||
// * 验证密码是否正确
|
||||
// * @param psd 明文密码
|
||||
// * @param user 根据用户名获取得用户对象
|
||||
// * @return
|
||||
// */
|
||||
// public static boolean checkPsd(String psd,User user){
|
||||
// String shaPsd = CipherUtils.jdksha256(psd);
|
||||
//
|
||||
// return shaPsd.equals(user.getPassword());
|
||||
// }
|
||||
public static User getCurrentUser(HttpServletRequest req) throws Exception { |
||||
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req); |
||||
|
||||
if(Utils.isNullStr(username)){ |
||||
return null; |
||||
} |
||||
|
||||
return getUserByUserName(username); |
||||
} |
||||
} |
@ -0,0 +1,178 @@
|
||||
package com.fr.plugin.cogons.utils; |
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||
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.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
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 var1 = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
||||
return var1 != null && !var1.isEmpty(); |
||||
} catch (Exception var2) { |
||||
FineLoggerFactory.getLogger().error(var2.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 |
||||
*/ |
||||
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 getAllUrl(HttpServletRequest httpServletRequest){ |
||||
return WebUtils.getOriginalURL(httpServletRequest); |
||||
} |
||||
|
||||
public static TableData getTableData(String serverDataSetName){ |
||||
TableData userInfo = TableDataConfig.getInstance().getTableData("serverDataSetName"); |
||||
|
||||
// DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator());
|
||||
return userInfo; |
||||
} |
||||
} |
@ -0,0 +1,94 @@
|
||||
package com.fr.plugin.cogons.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 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,207 @@
|
||||
package com.fr.plugin.cogons.utils; |
||||
|
||||
import com.fr.data.NetworkHelper; |
||||
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 javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.io.BufferedReader; |
||||
import java.io.InputStream; |
||||
import java.net.URLEncoder; |
||||
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 var3 = fw.indexOf(","); |
||||
return var3 != -1 ? fw.substring(0, var3) : 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); |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
<!doctype html> |
||||
<html> |
||||
<head> |
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
||||
<meta name="format-detection" content="telephone=no"> |
||||
<title>test</title> |
||||
</head> |
||||
|
||||
<body > |
||||
<form name="login" method="post" action="${action}" |
||||
Target=""> |
||||
<input type="hidden" name="b_action" value="cognosViewer" /> |
||||
<input type="hidden" name="m" value="portal/report-viewer.xts" /> |
||||
<input type="hidden" name="method" value="execute" /> |
||||
<input type="hidden" name="prompt" value="false" /> |
||||
<input type="hidden" name="run.prompt" value="true" /> |
||||
<input type="hidden" name="cv.header" value="false" /> |
||||
<!-- <input type="hidden" name="cv.toolbar" value="false" />--> |
||||
<input type="hidden" name="cv.contextmenu" value="false" /> |
||||
<input type="hidden" name="cv.selection" value="false" /> |
||||
<input type="hidden" name="CAMUsername" value="dev" /> |
||||
<input type="hidden" name="CAMPassword" value="dev" /> |
||||
|
||||
<!-- 参数 orgID--> |
||||
<input type="hidden" name="p_orgID" value="${orgId}"> |
||||
<input type="hidden" name="p_orgID2" value="${orgId}"> |
||||
<input type="hidden" name="p_orgID3" value="${orgId}"> |
||||
<input type="hidden" name="p_orgID4" value="${orgId}"> |
||||
<input type="hidden" name="p_orgID5" value="${orgId}"> |
||||
<input type="hidden" name="p_orgID6" value="${orgId}"> |
||||
</form> |
||||
<script language="javascript"> |
||||
login.submit(); |
||||
</script> |
||||
<br> |
||||
</body> |
||||
</html> |
Loading…
Reference in new issue