commit
761199f4b5
16 changed files with 1604 additions and 0 deletions
@ -0,0 +1,6 @@
|
||||
# open-JSD-10330 |
||||
|
||||
JSD-10330 单点集成\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 |
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.eco.plugin.gfkdsso</id> |
||||
<name><![CDATA[单点登录_EK]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.1</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[单点登录_EK]]></description> |
||||
<change-notes><![CDATA[ |
||||
[2022-12-02] JSD-10330 初始化 |
||||
]]></change-notes> |
||||
<main-package>com.eco.plugin.gfkdsso</main-package> |
||||
<lifecycle-monitor class="com.eco.plugin.gfkdsso.config.InitializeMonitor"/> |
||||
|
||||
<extra-decision> |
||||
<WebResourceProvider class="com.eco.plugin.gfkdsso.webresourceProvider.WebResourceProvider"/> |
||||
<LogInOutEventProvider class="com.eco.plugin.gfkdsso.logout.Logout"/> |
||||
<ControllerRegisterProvider class="com.eco.plugin.gfkdsso.controller.ControllerRegisterProvider"/> |
||||
</extra-decision> |
||||
<extra-core> |
||||
<LocaleFinder class="com.eco.plugin.gfkdsso.localeFinder.locale"/> |
||||
</extra-core> |
||||
<function-recorder class="com.eco.plugin.gfkdsso.config.PluginSimpleConfig"/> |
||||
|
||||
</plugin> |
@ -0,0 +1,21 @@
|
||||
package com.eco.plugin.gfkdsso.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,80 @@
|
||||
package com.eco.plugin.gfkdsso.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 = "Plugin-Config-Title") |
||||
@EnableMetrics |
||||
public class PluginSimpleConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile PluginSimpleConfig config = null; |
||||
|
||||
@Focus(id="com.eco.plugin.wink.gfkdsso", text = "Plugin-Config-Title", source = Original.PLUGIN) |
||||
public static PluginSimpleConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "ssoUrl", name = "Plugin-Config-ssoUrl", description = "Plugin-Config-ssoUrl", status = Status.SHOW) |
||||
private Conf<String> ssoUrl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "userserviceid", name = "Plugin-Config-userserviceid", description = "Plugin-Config-userserviceid", status = Status.SHOW) |
||||
private Conf<String> userserviceid = Holders.simple(""); |
||||
|
||||
@Identifier(value = "logoutserviceid", name = "Plugin-Config-logoutserviceid", description = "Plugin-Config-logoutserviceid", status = Status.SHOW) |
||||
private Conf<String> logoutserviceid = Holders.simple("http://localhost:8075/webroot/decision"); |
||||
|
||||
@Identifier(value = "logoutUrl", name = "Plugin-Config-logoutUrl", description = "Plugin-Config-logoutUrl", status = Status.SHOW) |
||||
private Conf<String> logoutUrl = Holders.simple(""); |
||||
|
||||
|
||||
public String getSsoUrl() { |
||||
return ssoUrl.get(); |
||||
} |
||||
|
||||
public void setssoUrl(String url) { |
||||
this.ssoUrl.set(url); |
||||
} |
||||
|
||||
public String getUserserviceid() { |
||||
return userserviceid.get(); |
||||
} |
||||
|
||||
public void setUserserviceid(String url) { |
||||
this.userserviceid.set(url); |
||||
} |
||||
|
||||
public String getLogoutserviceid() { |
||||
return logoutserviceid.get(); |
||||
} |
||||
|
||||
public void setLogoutserviceid(String url) { |
||||
this.logoutserviceid.set(url); |
||||
} |
||||
|
||||
public String getLogoutUrl() { |
||||
return logoutUrl.get(); |
||||
} |
||||
|
||||
public void setLogoutUrl(String url) { |
||||
this.logoutUrl.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,20 @@
|
||||
package com.eco.plugin.gfkdsso.controller; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
@Authorize(callSignKey = "com.eco.plugin.gfkdsso") |
||||
public class ControllerRegisterProvider extends AbstractControllerRegisterProvider { |
||||
@Override |
||||
public Class<?>[] getControllers() { |
||||
|
||||
if(!PluginContexts.currentContext().isAvailable()) { |
||||
return new Class[]{}; |
||||
} |
||||
|
||||
return new Class[]{ |
||||
ControllerSelf.class |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,108 @@
|
||||
package com.eco.plugin.gfkdsso.controller; |
||||
|
||||
import com.eco.plugin.gfkdsso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.gfkdsso.utils.FRUtils; |
||||
import com.eco.plugin.gfkdsso.utils.HttpUtils; |
||||
import com.eco.plugin.gfkdsso.utils.ResponseUtils; |
||||
import com.eco.plugin.gfkdsso.utils.Utils; |
||||
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.third.springframework.stereotype.Controller; |
||||
import com.fr.third.springframework.web.bind.annotation.GetMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
|
||||
@Controller |
||||
@LoginStatusChecker(required = false) |
||||
public class ControllerSelf { |
||||
|
||||
@GetMapping(value = "/ssologin") |
||||
@ResponseBody |
||||
public void ssologin(HttpServletRequest req,HttpServletResponse res){ |
||||
String token = req.getParameter("admin_token"); |
||||
String redirect = req.getParameter("redirect"); |
||||
|
||||
if(Utils.isNullStr(token) || Utils.isNullStr(redirect)){ |
||||
ResponseUtils.failedResponse(res,"请求非法"); |
||||
return ; |
||||
} |
||||
PluginSimpleConfig pluginSimpleConfig = PluginSimpleConfig.getInstance(); |
||||
String username = null; |
||||
try { |
||||
username = getUsername(token,pluginSimpleConfig); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
ResponseUtils.failedResponse(res,"获取用户信息异常!"); |
||||
return ; |
||||
} |
||||
|
||||
FRUtils.login(req,res,username,redirect,token); |
||||
} |
||||
|
||||
@GetMapping(value = "/ssologout") |
||||
@ResponseBody |
||||
public void ssologout(HttpServletRequest req,HttpServletResponse res){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
logout(req,psc); |
||||
|
||||
try { |
||||
res.sendRedirect(psc.getLogoutUrl()); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
ResponseUtils.failedResponse(res,"跳转登出地址异常!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 登出 |
||||
* @param req |
||||
* @param psc |
||||
*/ |
||||
public void logout(HttpServletRequest req, PluginSimpleConfig psc) { |
||||
String token = String.valueOf(req.getSession(true).getAttribute("admin_token")); |
||||
|
||||
if(Utils.isNullStr(token)){ |
||||
return ; |
||||
} |
||||
|
||||
String result = requestinfo(token,psc,psc.getLogoutserviceid()); |
||||
} |
||||
|
||||
/** |
||||
* 获取用户信息 |
||||
* @param token |
||||
* @param pluginSimpleConfig |
||||
* @return |
||||
*/ |
||||
private String getUsername(String token, PluginSimpleConfig pluginSimpleConfig) throws Exception{ |
||||
String result = requestinfo(token,pluginSimpleConfig,pluginSimpleConfig.getUserserviceid()); |
||||
|
||||
return new JSONObject(result).getJSONObject("Data").getJSONObject("user").getString("account"); |
||||
} |
||||
|
||||
/** |
||||
* 发起请求 |
||||
* @param token |
||||
* @param pluginSimpleConfig |
||||
* @param |
||||
* @return |
||||
*/ |
||||
private String requestinfo(String token, PluginSimpleConfig pluginSimpleConfig, String serviceid) { |
||||
String url = pluginSimpleConfig.getSsoUrl(); |
||||
JSONObject formParam = new JSONObject(); |
||||
formParam.put("cookie",token); |
||||
|
||||
JSONObject param = new JSONObject(); |
||||
param.put("serviceId",serviceid); |
||||
param.put("method","GET"); |
||||
param.put("dataType","form"); |
||||
param.put("formParams",formParam); |
||||
|
||||
return HttpUtils.HttpPostJson(url,param.toString(),null); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,10 @@
|
||||
package com.eco.plugin.gfkdsso.localeFinder; |
||||
|
||||
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||
|
||||
public class locale extends AbstractLocaleFinder{ |
||||
@Override |
||||
public String find() { |
||||
return "com/eco/plugin/gfkdsso/locale/locale"; |
||||
} |
||||
} |
@ -0,0 +1,62 @@
|
||||
package com.eco.plugin.gfkdsso.logout; |
||||
|
||||
import com.eco.plugin.gfkdsso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.gfkdsso.utils.HttpUtils; |
||||
import com.eco.plugin.gfkdsso.utils.Utils; |
||||
import com.fr.decision.fun.impl.AbstractLogInOutEventProvider; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
public class Logout extends AbstractLogInOutEventProvider { |
||||
|
||||
@Override |
||||
public String logoutAction(LogInOutResultInfo result) { |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
HttpSession session = result.getRequest().getSession(true); |
||||
logout(result.getRequest(),psc); |
||||
LoginService.getInstance().crossDomainLogout(result.getRequest(),result.getResponse(),""); |
||||
session.invalidate(); |
||||
return psc.getLogoutUrl(); |
||||
} |
||||
|
||||
/** |
||||
* 登出 |
||||
* @param req |
||||
* @param psc |
||||
*/ |
||||
public void logout(HttpServletRequest req, PluginSimpleConfig psc) { |
||||
String token = String.valueOf(req.getSession(true).getAttribute("admin_token")); |
||||
|
||||
if(Utils.isNullStr(token)){ |
||||
return ; |
||||
} |
||||
|
||||
String result = requestinfo(token,psc,psc.getLogoutserviceid()); |
||||
} |
||||
|
||||
/** |
||||
* 发起请求 |
||||
* @param token |
||||
* @param pluginSimpleConfig |
||||
* @param |
||||
* @return |
||||
*/ |
||||
private String requestinfo(String token, PluginSimpleConfig pluginSimpleConfig, String serviceid) { |
||||
String url = pluginSimpleConfig.getSsoUrl(); |
||||
JSONObject formParam = new JSONObject(); |
||||
formParam.put("cookie",token); |
||||
|
||||
JSONObject param = new JSONObject(); |
||||
param.put("serviceId",serviceid); |
||||
param.put("method","GET"); |
||||
param.put("dataType","form"); |
||||
param.put("formParams",formParam); |
||||
|
||||
return HttpUtils.HttpPostJson(url,param.toString(),null); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,372 @@
|
||||
package com.eco.plugin.gfkdsso.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.TransmissionTool; |
||||
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.json.JSONObject; |
||||
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 userList = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
||||
return userList != null && !userList.isEmpty(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.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,String token){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:用户名:"+userName+";跳转链接:"+url); |
||||
|
||||
//判断用户名是否为空
|
||||
if(!Utils.isNullStr(userName)){ |
||||
if(isUserExist(userName)){ |
||||
try { |
||||
LoginService.getInstance().login(httpServletRequest, httpServletResponse, userName); |
||||
|
||||
EventDispatcher.fire(LogInOutEvent.LOGIN,new LogInOutResultInfo(httpServletRequest,httpServletResponse,userName,true)); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登陆成功!"); |
||||
|
||||
if(!Utils.isNullStr(url)){ |
||||
HttpSession session = httpServletRequest.getSession(true); |
||||
session.setAttribute("admin_token",token); |
||||
httpServletResponse.sendRedirect(url); |
||||
} |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"登录异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"用户在报表系统中不存在!"); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"用户名不能为空!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 帆软登录 |
||||
* @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+";跳转链接:"+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,"跳转异常!"); |
||||
} |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"token不能为空!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 产品原始登录方法 |
||||
* @param req |
||||
* @param res |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static JSONObject originLogin(HttpServletRequest req,HttpServletResponse res,String username){ |
||||
// String password = param.getString("password");
|
||||
// password = decryptFRPsd(password);
|
||||
|
||||
FRUtils.FRLogInfo("originLogin:"+username); |
||||
|
||||
if(isUserExist(username)){ |
||||
try { |
||||
String token = LoginService.getInstance().login(req, res, username); |
||||
JSONObject result = new JSONObject(); |
||||
result.put("username",username); |
||||
result.put("validity",-1); |
||||
result.put("accessToken",token); |
||||
result.put("username",username); |
||||
result.put("url","/webroot/decision"); |
||||
JSONObject originUrlResponse = new JSONObject(); |
||||
originUrlResponse.put("originUrl","/webroot/decision"); |
||||
originUrlResponse.put("method","GET"); |
||||
originUrlResponse.put("parameters",new JSONObject()); |
||||
result.put("originUrlResponse",originUrlResponse); |
||||
return new JSONObject().put("data",result); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(res,"登录异常,请联系管理员!"); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(res,"用户在报表系统中不存在!"); |
||||
} |
||||
|
||||
return new JSONObject(); |
||||
} |
||||
|
||||
/** |
||||
* 获取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 req, String token, int num) { |
||||
try { |
||||
if (StringUtils.isNotEmpty(token)) { |
||||
Cookie cookie = new Cookie("fine_auth_token", token); |
||||
long maxAge = num == -2 ? 1209600000L : (long)num; |
||||
cookie.setMaxAge((int)maxAge); |
||||
cookie.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
req.addCookie(cookie); |
||||
Cookie rememberCookie = new Cookie("fine_remember_login", String.valueOf(num == -2 ? -2 : -1)); |
||||
rememberCookie.setMaxAge((int)maxAge); |
||||
rememberCookie.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
req.addCookie(rememberCookie); |
||||
} else { |
||||
FineLoggerFactory.getLogger().error("empty token cannot save."); |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 后台登出 |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
*/ |
||||
public static void logoutByToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String token) |
||||
{ |
||||
httpServletRequest.setAttribute("fine_auth_token",token); |
||||
logout(httpServletRequest,httpServletResponse); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @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("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 req |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String getOriginUrl(HttpServletRequest req) throws Exception { |
||||
String origin = req.getParameter("origin"); |
||||
if (StringUtils.isNotEmpty(origin)) { |
||||
OriginUrlResponseBean originUrlResponseBean = (OriginUrlResponseBean) DecisionStatusService.originUrlStatusService().get(origin); |
||||
DecisionStatusService.originUrlStatusService().delete(origin); |
||||
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; |
||||
} |
||||
|
||||
/** |
||||
* 获取帆软域名 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static String getFRDomain(HttpServletRequest req){ |
||||
String domain = req.getScheme()+"://"+req.getServerName(); |
||||
int port = req.getServerPort(); |
||||
|
||||
if(port != 80){ |
||||
domain += ":"+String.valueOf(req.getServerPort()); |
||||
} |
||||
|
||||
return domain; |
||||
} |
||||
} |
@ -0,0 +1,260 @@
|
||||
package com.eco.plugin.gfkdsso.utils; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.third.org.apache.http.HttpEntity; |
||||
import com.fr.third.org.apache.http.HttpResponse; |
||||
import com.fr.third.org.apache.http.HttpStatus; |
||||
import com.fr.third.org.apache.http.NameValuePair; |
||||
import com.fr.third.org.apache.http.client.CookieStore; |
||||
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity; |
||||
import com.fr.third.org.apache.http.client.methods.HttpGet; |
||||
import com.fr.third.org.apache.http.client.methods.HttpPost; |
||||
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier; |
||||
import com.fr.third.org.apache.http.entity.StringEntity; |
||||
import com.fr.third.org.apache.http.impl.client.BasicCookieStore; |
||||
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; |
||||
import com.fr.third.org.apache.http.impl.client.HttpClients; |
||||
import com.fr.third.org.apache.http.impl.cookie.BasicClientCookie; |
||||
import com.fr.third.org.apache.http.message.BasicNameValuePair; |
||||
import com.fr.third.org.apache.http.ssl.SSLContexts; |
||||
import com.fr.third.org.apache.http.ssl.TrustStrategy; |
||||
import com.fr.third.org.apache.http.util.EntityUtils; |
||||
|
||||
import javax.net.ssl.SSLContext; |
||||
import javax.servlet.http.Cookie; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.security.cert.CertificateException; |
||||
import java.security.cert.X509Certificate; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
public class HttpUtils { |
||||
|
||||
/** |
||||
* httpGet请求 |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String httpGet(String url,Cookie[] cookies,Map<String,String> header){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url); |
||||
|
||||
//创建httpClient
|
||||
CloseableHttpClient httpclient = createHttpClient(cookies); |
||||
|
||||
HttpGet getMethod = new HttpGet(url); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
getMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
try { |
||||
HttpResponse response = httpclient.execute(getMethod); |
||||
int status =response.getStatusLine().getStatusCode(); |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--status:"+status +";returnResult:"+returnResult); |
||||
|
||||
httpclient.close(); |
||||
|
||||
if (status == HttpStatus.SC_OK) { |
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--exception:"+e.getMessage()); |
||||
} |
||||
|
||||
try { |
||||
httpclient.close(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* HttpPost请求 |
||||
* @param postMethod |
||||
* @return |
||||
*/ |
||||
private static String HttpPost(HttpPost postMethod){ |
||||
CloseableHttpClient httpclient = createHttpClient(null); |
||||
|
||||
try { |
||||
HttpResponse response = httpclient.execute(postMethod); |
||||
int status = response.getStatusLine().getStatusCode(); |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:status:"+status+"returnResult:"+returnResult); |
||||
httpclient.close(); |
||||
|
||||
if (status == HttpStatus.SC_OK) { |
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:exception:"+e.getMessage()); |
||||
} |
||||
|
||||
try { |
||||
httpclient.close(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
public static String HttpPostXML(String url, String xmlParam){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-type", "text/html"); |
||||
HttpEntity entity = null; |
||||
try { |
||||
entity = new StringEntity(xmlParam); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity); |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostText(String url, String xmlParam){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-type", "text/plain"); |
||||
HttpEntity entity = null; |
||||
try { |
||||
entity = new StringEntity(xmlParam); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity); |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostJson(String url, String param,Map<String,String> header){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-Type","application/json"); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
postMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
if(!Utils.isNullStr(param)){ |
||||
HttpEntity entity = null; |
||||
try { |
||||
entity = new StringEntity(param); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity); |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostForm(String url, Map<String,String> header,Map<String,String> param){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpForm:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
postMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
if(param != null && param.size() > 0){ |
||||
List<NameValuePair> params = new ArrayList<NameValuePair>(param.size()); |
||||
|
||||
for(Map.Entry<String,String> map : param.entrySet()){ |
||||
params.add(new BasicNameValuePair(map.getKey(), map.getValue())); |
||||
} |
||||
|
||||
try { |
||||
postMethod.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpForm:异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
private static CloseableHttpClient createHttpClient(Cookie[] cookies){ |
||||
|
||||
SSLContext sslContext = null; |
||||
try { |
||||
sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { |
||||
@Override |
||||
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { |
||||
return true; |
||||
} |
||||
}).build(); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("exception:"+e.getMessage()); |
||||
} |
||||
|
||||
CloseableHttpClient httpclient = null; |
||||
|
||||
if(cookies != null && cookies.length > 0){ |
||||
CookieStore cookieStore = cookieToCookieStore(cookies); |
||||
|
||||
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||
setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build(); |
||||
} |
||||
else{ |
||||
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||
setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); |
||||
} |
||||
|
||||
return httpclient; |
||||
} |
||||
|
||||
/** |
||||
* cookies转cookieStore |
||||
* @param cookies |
||||
* @return |
||||
*/ |
||||
public static CookieStore cookieToCookieStore(Cookie[] cookies){ |
||||
CookieStore cookieStore = new BasicCookieStore(); |
||||
|
||||
if(cookies != null && cookies.length>0){ |
||||
for(Cookie cookie : cookies){ |
||||
BasicClientCookie cookie1 = new BasicClientCookie(cookie.getName(), cookie.getValue()); |
||||
cookieStore.addCookie(cookie1); |
||||
} |
||||
} |
||||
|
||||
return cookieStore; |
||||
} |
||||
} |
@ -0,0 +1,108 @@
|
||||
package com.eco.plugin.gfkdsso.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,362 @@
|
||||
package com.eco.plugin.gfkdsso.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 { |
||||
|
||||
public static byte[] getByteHeader(byte[] bytes){ |
||||
byte[] newByte = new byte[3]; |
||||
for(int i=0;i<bytes.length;i++){ |
||||
if(i < 3){ |
||||
newByte[i] = bytes[i]; |
||||
continue; |
||||
} |
||||
|
||||
break; |
||||
} |
||||
|
||||
return newByte; |
||||
} |
||||
|
||||
public static String bytesToHexString(byte[] src) { |
||||
StringBuilder stringBuilder = new StringBuilder(); |
||||
if (src == null || src.length <= 0) { |
||||
return null; |
||||
} |
||||
for (int i = 0; i < src.length; i++) { |
||||
int v = src[i] & 0xFF; |
||||
String hv = Integer.toHexString(v); |
||||
if (hv.length() < 2) { |
||||
stringBuilder.append(0); |
||||
} |
||||
stringBuilder.append(hv); |
||||
} |
||||
return stringBuilder.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 判断字符串是否为空 |
||||
* @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",""); |
||||
FRUtils.FRLogInfo("reqBody:"+jsonString); |
||||
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 para3 = fw.indexOf(","); |
||||
return para3 != -1 ? fw.substring(0, para3) : 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);
|
||||
Matcher matcher = Pattern.compile("[^\\x00-\\xff]").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; |
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.eco.plugin.gfkdsso.webresourceProvider; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractWebResourceProvider; |
||||
import com.fr.decision.web.MainComponent; |
||||
import com.fr.web.struct.Atom; |
||||
import com.fr.web.struct.Component; |
||||
import com.fr.web.struct.browser.RequestClient; |
||||
import com.fr.web.struct.category.ScriptPath; |
||||
import com.fr.web.struct.category.StylePath; |
||||
|
||||
/** |
||||
* Created by xx on 2021-12-03 |
||||
*/ |
||||
public class WebResourceProvider extends AbstractWebResourceProvider { |
||||
@Override |
||||
public Atom attach() { |
||||
return MainComponent.KEY; |
||||
} |
||||
|
||||
@Override |
||||
public Atom client() { |
||||
return new Component() { |
||||
@Override |
||||
public ScriptPath script(RequestClient requestClient) { |
||||
return ScriptPath.build("/com/eco/plugin/gfkdsso/js/ui.js"); |
||||
} |
||||
|
||||
@Override |
||||
public StylePath style(RequestClient requestClient) { |
||||
return StylePath.EMPTY; |
||||
// return StylePath.build("/com/fr/plugin/jdfSSO/css/icon.css");
|
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,124 @@
|
||||
var loginKickUrl = "/webroot/decisoin/ssologout"; |
||||
|
||||
var t; |
||||
t = BI.inherit(BI.OB, { |
||||
showLastLoginInfo: function () { |
||||
Dec.system.loginInfoRemind && !BI.Cache.getCookie(DecCst.Cookie.LAST_LOGIN_INFO) && Dec.Utils.getLastLoginInfo((function (e) { |
||||
if (e.data) { |
||||
var t = e.data; |
||||
Dec.Msg.pop({ |
||||
type: "dec.components.login.last.info", |
||||
time: t.time, |
||||
ip: t.ip, |
||||
address: t.city |
||||
}, { |
||||
height: 170, |
||||
width: 300 |
||||
}), |
||||
BI.Cache.addCookie(DecCst.Cookie.LAST_LOGIN_INFO, !0, Dec.system.cookiePath, -1) |
||||
} |
||||
})) |
||||
}, |
||||
loginKick: function (t, i) { |
||||
function e(e, t, i) { |
||||
return t in e ? Object.defineProperty(e, t, { |
||||
value: i, |
||||
enumerable: !0, |
||||
configurable: !0, |
||||
writable: !0 |
||||
}) : e[t] = i, |
||||
e |
||||
}; |
||||
var n; |
||||
BI.contains([DecCst.ErrorCode.SINGLE_LOGIN_KICK], t) && Dec.Utils.clearLoginToken(), |
||||
BI.isNotNull(Dec.socket) && Dec.socket.disconnect(); |
||||
var o = i || (n = {}, e(n, DecCst.ErrorCode.PLATFORM_USER_REMOVE, "Dec-Login_Account_Not_Available"), e(n, DecCst.ErrorCode.SINGLE_LOGIN_KICK, "Dec-Login_Single_Logged_Tip"), e(n, DecCst.ErrorCode.USERNAME_PASSWORD_ERROR, "Dec-Login_Password_Changed"), e(n, DecCst.ErrorCode.CANNOT_GET_TOKEN, { |
||||
type: "bi.center_adapt", |
||||
items: [{ |
||||
type: "bi.label", |
||||
whiteSpace: "normal", |
||||
text: BI.i18nText("Dec-Login_Cannot_Get_Token") |
||||
}, { |
||||
type: "dec.link.button", |
||||
text: BI.i18nText("Dec-Basic_Click_Here_To_View_Help_Document"), |
||||
link: Dec.system[DecCst.Hyperlink.DECISION_HYPERLINK_CONFIG][DecCst.Hyperlink.CANNOT_GET_TOKEN] |
||||
} |
||||
] |
||||
}), n)[t] || "Dec-Login_Info_Not_Available", |
||||
r = "string" == typeof o ? { |
||||
type: "bi.label", |
||||
whiteSpace: "normal", |
||||
text: BI.i18nText(o) |
||||
} |
||||
: o, |
||||
s = "login.timeout"; |
||||
BI.Popovers.create(s, { |
||||
header: BI.i18nText("BI-Basic_Prompt"), |
||||
size: "small", |
||||
closable: !1, |
||||
body: r, |
||||
footer: { |
||||
type: "bi.right_vertical_adapt", |
||||
items: [{ |
||||
type: "bi.button", |
||||
$testId: "dec-login-kick-btn", |
||||
text: BI.i18nText("BI-Basic_OK"), |
||||
height: 24, |
||||
handler: function () { |
||||
BI.Popovers.remove(s), |
||||
window.location.href = loginKickUrl; |
||||
// window.location.reload(!0)
|
||||
} |
||||
} |
||||
] |
||||
} |
||||
}, this).open(s) |
||||
}, |
||||
showErrorMasker: function (e) { |
||||
var t = BI.UUID(); |
||||
BI.Maskers.create(t, null, { |
||||
render: { |
||||
type: "dec.error_masker.single", |
||||
text: e |
||||
} |
||||
}), |
||||
BI.Maskers.show(t) |
||||
}, |
||||
refreshToken: function () { |
||||
$(document).click((function () { |
||||
Dec.Utils.saveLastOperatingTime() |
||||
})), |
||||
Dec.Utils.initRefreshToken() |
||||
}, |
||||
isAdmin: function () { |
||||
return BI.contains(Dec.system.adminUser, Dec.personal.username) |
||||
}, |
||||
checkAdmin: function (e) { |
||||
return BI.contains(Dec.system.adminUser, e.username) |
||||
}, |
||||
initUsebleModules: function (e) { |
||||
var t = this; |
||||
if (!this._useableModules) |
||||
return Dec.personal.modules ? (this._useableModules = Dec.personal.modules, void e(this._useableModules)) : void Dec.Utils.getUseAbleDecisionModules((function (i) { |
||||
t._useableModules = i.data, |
||||
e(t._useableModules) |
||||
})); |
||||
e(this._useableModules) |
||||
}, |
||||
checkModulesUseable: function (e) { |
||||
return BI.some(this._useableModules, (function (t, i) { |
||||
return i.id === e |
||||
})) |
||||
}, |
||||
getLanguage: function () { |
||||
return { |
||||
"默认": "zh_CN", |
||||
"預設": "zh_TW", |
||||
Default: "en_US", |
||||
"既定": "ja_JP", |
||||
"디폴트": "ko_KR" |
||||
} |
||||
[BI.i18nText("Dec-Basic_Default")] |
||||
} |
||||
}), |
||||
BI.service("dec.service.global", t) |
@ -0,0 +1,5 @@
|
||||
Plugin-Config-Title=title |
||||
Plugin-Config-ssoUrl=ssoUrl |
||||
Plugin-Config-userserviceid=userserviceid |
||||
Plugin-Config-logoutserviceid=logoutserviceid |
||||
Plugin-Config-logoutUrl=logoutUrl |
@ -0,0 +1,5 @@
|
||||
Plugin-Config-Title=\u5355\u70b9\u767b\u5f55\u914d\u7f6e |
||||
Plugin-Config-ssoUrl=\u5355\u70b9\u63a5\u53e3 |
||||
Plugin-Config-userserviceid=\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u670d\u52a1id |
||||
Plugin-Config-logoutserviceid=\u5355\u70b9\u767b\u51fa\u670d\u52a1id |
||||
Plugin-Config-logoutUrl=\u767b\u51fa\u8df3\u8f6curl |
Loading…
Reference in new issue