LAPTOP-SB56SG4Q\86185
3 years ago
19 changed files with 1428 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-9083 |
||||
|
||||
JSD-9083 基于票据验证的单点 |
||||
JSD-9083 基于票据验证的单点\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
Binary file not shown.
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.eco.plugin.xxxx.fqlsso</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.xxxx.fqlsso</main-package> |
||||
<lifecycle-monitor class="com.eco.plugin.xxxx.fqlsso.config.InitializeMonitor"/> |
||||
|
||||
<extra-decision> |
||||
<WebResourceProvider class="com.eco.plugin.xxxx.fqlsso.webResourceProvider.WebResourceProvider"/> |
||||
<LogInOutEventProvider class="com.eco.plugin.xxxx.fqlsso.logout.Logout"/> |
||||
<GlobalRequestFilterProvider class="com.eco.plugin.xxxx.fqlsso.filter.SSOFilter"/> |
||||
<HttpHandlerProvider class="com.eco.plugin.xxxx.fqlsso.handler.ExtendAttrHandlerProvider"/> |
||||
<URLAliasProvider class="com.eco.plugin.xxxx.fqlsso.handler.URLAliasProvide"/> |
||||
</extra-decision> |
||||
|
||||
<function-recorder class="com.eco.plugin.xxxx.fqlsso.config.PluginSimpleConfig"/> |
||||
</plugin> |
@ -0,0 +1,21 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.config; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @version 10.0 |
||||
* Created by fr.open on 2018-12-04 |
||||
*/ |
||||
public class InitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
public void afterRun(PluginContext pluginContext) { |
||||
PluginSimpleConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,112 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.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.xxxx.fqlsso.config", text = "单点登录配置", source = Original.PLUGIN) |
||||
public static PluginSimpleConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "clientId", name = "appid", description = "appid", status = Status.SHOW) |
||||
private Conf<String> clientId = Holders.simple(""); |
||||
|
||||
@Identifier(value = "secret", name = "appkey", description = "appkey", status = Status.SHOW) |
||||
private Conf<String> secret = Holders.simple(""); |
||||
|
||||
// @Identifier(value = "index", name = "帆软首页", description = "帆软首页", status = Status.SHOW)
|
||||
// private Conf<String> index = Holders.simple("http://localhost:8075/webroot/decision");
|
||||
|
||||
@Identifier(value = "authUrl", name = "获取ticket接口", description = "获取ticket接口", status = Status.SHOW) |
||||
private Conf<String> authUrl = Holders.simple(""); |
||||
|
||||
// @Identifier(value = "tokenUrl", name = "获取token接口", description = "获取token接口", status = Status.SHOW)
|
||||
// private Conf<String> tokenUrl = Holders.simple("");
|
||||
|
||||
@Identifier(value = "userUrl", name = "获取用户信息接口", description = "获取用户信息接口", status = Status.SHOW) |
||||
private Conf<String> userUrl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "logoutUrl", name = "登出接口", description = "登出接口", status = Status.SHOW) |
||||
private Conf<String> logoutUrl = Holders.simple(""); |
||||
|
||||
public String getClientId() { |
||||
return clientId.get(); |
||||
} |
||||
|
||||
public void setClientId(String url) { |
||||
this.clientId.set(url); |
||||
} |
||||
|
||||
public String getSecret() { |
||||
return secret.get(); |
||||
} |
||||
|
||||
public void setSecret(String url) { |
||||
this.secret.set(url); |
||||
} |
||||
|
||||
public String getAuthUrl() { |
||||
return authUrl.get(); |
||||
} |
||||
|
||||
public void setAuthUrl(String url) { |
||||
this.authUrl.set(url); |
||||
} |
||||
|
||||
// public String getTokenUrl() {
|
||||
// return tokenUrl.get();
|
||||
// }
|
||||
//
|
||||
// public void setTokenUrl(String url) {
|
||||
// this.tokenUrl.set(url);
|
||||
// }
|
||||
|
||||
public String getUserUrl() { |
||||
return userUrl.get(); |
||||
} |
||||
|
||||
public void setUserUrl(String url) { |
||||
this.userUrl.set(url); |
||||
} |
||||
|
||||
public String getLogoutUrl() { |
||||
return logoutUrl.get(); |
||||
} |
||||
|
||||
public void setLogoutUrl(String url) { |
||||
this.logoutUrl.set(url); |
||||
} |
||||
|
||||
// public String geIndex() {
|
||||
// return index.get();
|
||||
// }
|
||||
//
|
||||
// public void setIndex(String url) {
|
||||
// this.index.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,165 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.filter; |
||||
|
||||
import com.eco.plugin.xxxx.fqlsso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xxxx.fqlsso.utils.Aes; |
||||
import com.eco.plugin.xxxx.fqlsso.utils.FRUtils; |
||||
import com.eco.plugin.xxxx.fqlsso.utils.HttpUtils; |
||||
import com.eco.plugin.xxxx.fqlsso.utils.Utils; |
||||
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||
import com.fr.json.JSONObject; |
||||
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.net.URLEncoder; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Random; |
||||
|
||||
@EnableMetrics |
||||
@Authorize(callSignKey = "com.eco.plugin.xxxx.fqlsso") |
||||
public class SSOFilter extends AbstractGlobalRequestFilterProvider { |
||||
@Override |
||||
public String filterName() { |
||||
return "fqlssoFilter"; |
||||
} |
||||
|
||||
@Override |
||||
public String[] urlPatterns() { |
||||
return new String[]{"/*"}; |
||||
} |
||||
|
||||
@Override |
||||
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){ |
||||
|
||||
if(PluginContexts.currentContext().isAvailable()){ |
||||
//是否放行
|
||||
boolean release = isRelease(req); |
||||
FRUtils.FRLogInfo("isRelease : " + release); |
||||
if(release){ |
||||
release(req,res,chain); |
||||
return; |
||||
} |
||||
|
||||
//code
|
||||
String code = req.getParameter("ticket"); |
||||
|
||||
FRUtils.FRLogInfo("ticket : " + code); |
||||
|
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
|
||||
if(Utils.isNullStr(code)){ |
||||
//跳转认证中心
|
||||
redirect(req,res,psc); |
||||
return; |
||||
} |
||||
|
||||
// //获取token
|
||||
// String token = getToken(code,psc);
|
||||
|
||||
//获取userInfo
|
||||
String username = getUsername(req,code,psc); |
||||
|
||||
//登录
|
||||
FRUtils.login(req,res,username,""); |
||||
} |
||||
|
||||
release(req,res,chain); |
||||
} |
||||
|
||||
private boolean isRelease(HttpServletRequest req) { |
||||
String url = FRUtils.getAllUrl(req); |
||||
// String reft = req.getParameter("ref_t");
|
||||
|
||||
boolean isLogin = FRUtils.isLogin(req); |
||||
boolean isRemote = url.contains("remote"); |
||||
// boolean isLoginPage = url.contains("login")||url.contains("decision/file")||url.contains("decision/resource")||url.contains("decision/system")||url.contains("query/ip");
|
||||
// boolean isViewlt = url.contains("viewlet") || "design".equals(reft) || url.contains("view/report") || url.contains("view/form");
|
||||
return isLogin || isRemote || url.contains("getLogout"); |
||||
} |
||||
|
||||
//跳转认证中心
|
||||
private void redirect(HttpServletRequest req,HttpServletResponse res, PluginSimpleConfig psc) { |
||||
String authurl = psc.getAuthUrl(); |
||||
String appid = psc.getClientId(); |
||||
String url = FRUtils.getAllUrl(req); |
||||
|
||||
authurl += "?url="+URLEncoder.encode(url)+"&appid="+appid; |
||||
FRUtils.FRLogInfo("redirect " + authurl); |
||||
try { |
||||
res.sendRedirect(authurl); |
||||
} catch (IOException e) { |
||||
FRUtils.FRLogInfo("跳转认证中心异常:"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
//获取用户名
|
||||
private String getUsername(HttpServletRequest req,String ticket,PluginSimpleConfig psc) { |
||||
String tokenurl = psc.getUserUrl(); |
||||
String ip = Utils.getIp(req); |
||||
|
||||
tokenurl += "?ticket="+ticket+"&ip="+ip; |
||||
|
||||
Map<String,String> header = getFofApiRequestHeader(psc.getClientId(),psc.getSecret()); |
||||
|
||||
String result = HttpUtils.get(tokenurl,null,header); |
||||
|
||||
if(Utils.isNullStr(result)){ |
||||
return ""; |
||||
} |
||||
|
||||
JSONObject json = new JSONObject(result); |
||||
|
||||
if(json == null ){ |
||||
return ""; |
||||
} |
||||
|
||||
String username = json.getJSONObject("result_rows").getString("min"); |
||||
return username; |
||||
} |
||||
|
||||
//放行拦截器
|
||||
private void release(HttpServletRequest req, HttpServletResponse res, FilterChain chain) { |
||||
try{ |
||||
chain.doFilter(req,res); |
||||
}catch (Exception e){ |
||||
FRUtils.FRLogInfo("拦截失败"); |
||||
} |
||||
} |
||||
|
||||
private static Map<String, String> getFofApiRequestHeader(String appId, String appKey) { |
||||
//当前时间戳
|
||||
long t = System.currentTimeMillis(); |
||||
//不要毫秒
|
||||
String timestamp = t / 1000 + ""; |
||||
|
||||
Random r = new Random(); |
||||
int rand = r.nextInt(); |
||||
if (rand < 0 && rand != Integer.MIN_VALUE) { |
||||
rand = Math.abs(rand); |
||||
} |
||||
|
||||
String data = "timestamp=" + timestamp + "&rand=" + rand + "&appid=" + appId; |
||||
|
||||
//以appKey为密钥,生成签名
|
||||
String token = null; |
||||
try { |
||||
token = Aes.encrypt(String.valueOf(appKey), data); |
||||
} catch (Exception e) { |
||||
|
||||
} |
||||
|
||||
// 授权信息放在header中
|
||||
Map<String, String> map = new HashMap<String, String>(); |
||||
map.put("appid", appId); |
||||
map.put("timestamp", timestamp); |
||||
map.put("rand", String.valueOf(rand)); |
||||
map.put("token", token); |
||||
|
||||
return map; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,13 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.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 LogoutHandler() |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,45 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.handler; |
||||
|
||||
import com.eco.plugin.xxxx.fqlsso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xxxx.fqlsso.utils.ResponseUtils; |
||||
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; |
||||
|
||||
@FunctionRecorder |
||||
public class LogoutHandler extends BaseHttpHandler { |
||||
|
||||
|
||||
public LogoutHandler() { |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/getLogout"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) { |
||||
ResponseUtils.successResponse(res, PluginSimpleConfig.getInstance().getLogoutUrl()); |
||||
|
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,14 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.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("/getLogout","/getLogout",true), |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.logout; |
||||
|
||||
import com.eco.plugin.xxxx.fqlsso.config.PluginSimpleConfig; |
||||
import com.fr.decision.fun.impl.AbstractLogInOutEventProvider; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
public class Logout extends AbstractLogInOutEventProvider { |
||||
|
||||
@Override |
||||
public String logoutAction(LogInOutResultInfo result) { |
||||
HttpSession session = result.getRequest().getSession(true); |
||||
LoginService.getInstance().crossDomainLogout(result.getRequest(),result.getResponse(),""); |
||||
session.invalidate(); |
||||
return PluginSimpleConfig.getInstance().getLogoutUrl(); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,53 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.utils; |
||||
|
||||
import javax.crypto.Cipher; |
||||
import javax.crypto.spec.IvParameterSpec; |
||||
import javax.crypto.spec.SecretKeySpec; |
||||
|
||||
import org.apache.commons.codec.binary.Base64; |
||||
|
||||
/** |
||||
* Created by tomcanli on 2017/9/16. |
||||
*/ |
||||
public class Aes { |
||||
//keyStr为加密密钥串,即申请下来的appkey,sSrc为需要加密的内容
|
||||
public static String encrypt(String keyStr, String sSrc) throws Exception { |
||||
if (keyStr == null) { |
||||
throw new Exception("Key为空null"); |
||||
} |
||||
|
||||
// 判断Key是否为16位
|
||||
if (keyStr.length() != 16) { |
||||
throw new Exception("Key长度不是16位"); |
||||
} |
||||
|
||||
byte[] raw = keyStr.getBytes(); |
||||
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); |
||||
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");// "算法/模式/补码方式"
|
||||
IvParameterSpec iv = new IvParameterSpec(keyStr.getBytes());// 使用CBC模式,需要一个向量iv,可增加加密算法的强度
|
||||
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); |
||||
|
||||
byte[] srawt = sSrc.getBytes(); |
||||
|
||||
int len = srawt.length; |
||||
|
||||
/* 计算补0后的长度 */ |
||||
while (len % 16 != 0) |
||||
len++; |
||||
|
||||
byte[] sraw = new byte[len]; |
||||
/* 在最后补0 */ |
||||
|
||||
for (int i = 0; i < len; ++i) { |
||||
if (i < srawt.length) { |
||||
sraw[i] = srawt[i]; |
||||
} else { |
||||
sraw[i] = 0; |
||||
} |
||||
} |
||||
|
||||
byte[] encrypted = cipher.doFinal(sraw); |
||||
|
||||
return new String(Base64.encodeBase64(encrypted)); |
||||
} |
||||
} |
@ -0,0 +1,257 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.utils; |
||||
|
||||
import com.fr.base.ServerConfig; |
||||
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.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 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 |
||||
* @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 var1, String var2, int var3) { |
||||
try { |
||||
if (StringUtils.isNotEmpty(var2)) { |
||||
Cookie var4 = new Cookie("fine_auth_token", var2); |
||||
long var5 = var3 == -2 ? 1209600000L : (long)var3; |
||||
var4.setMaxAge((int)var5); |
||||
var4.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
var1.addCookie(var4); |
||||
Cookie var7 = new Cookie("fine_remember_login", String.valueOf(var3 == -2 ? -2 : -1)); |
||||
var7.setMaxAge((int)var5); |
||||
var7.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
var1.addCookie(var7); |
||||
} else { |
||||
FineLoggerFactory.getLogger().error("empty token cannot save."); |
||||
} |
||||
} catch (Exception var8) { |
||||
FineLoggerFactory.getLogger().error(var8.getMessage(), var8); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @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,230 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.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.KeyManagementException; |
||||
import java.security.KeyStoreException; |
||||
import java.security.NoSuchAlgorithmException; |
||||
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 get(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); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--returnResult:"+returnResult); |
||||
|
||||
if (status == HttpStatus.SC_OK) { |
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--exception:"+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); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:returnResult:"+returnResult); |
||||
|
||||
if (status == HttpStatus.SC_OK) { |
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:exception:"+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 entity2 = null; |
||||
try { |
||||
entity2 = new StringEntity(xmlParam); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity2); |
||||
|
||||
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 entity2 = null; |
||||
try { |
||||
entity2 = new StringEntity(param); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity2); |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostWWWForm(String url, Map<String,String> header,Map<String,String> param){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm: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:HttpWWWForm:异常:"+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,94 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.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,226 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.utils; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
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 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.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 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); |
||||
} |
||||
|
||||
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("跳转页面异常"); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.eco.plugin.xxxx.fqlsso.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 zhouping on 2019/1/16. |
||||
*/ |
||||
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/xxxx/fqlsso/js/logout.js"); |
||||
} |
||||
|
||||
@Override |
||||
public StylePath style(RequestClient requestClient) { |
||||
return StylePath.EMPTY; |
||||
// return StylePath.build("/com/fr/plugin/jdfSSO/css/icon.css");
|
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,116 @@
|
||||
/** |
||||
* Created by pioneer on 2020/1/8 |
||||
* |
||||
* 替换main.service.js里面loginKick方法 实现登录超时自定义跳转 |
||||
* |
||||
*/ |
||||
|
||||
!(function () { |
||||
console.log("--------------------加载my.global.service.js------------------"); |
||||
var myService = BI.Services.getService("dec.service.global"); |
||||
/** |
||||
* 踢出登录 |
||||
* @param errorCode 错误码 |
||||
* @param errorText 错误信息 |
||||
*/ |
||||
myService.loginKick=function (errorCode, errorText) { |
||||
var name = "login.timeout", text = errorText || "Dec-Login_Info_Not_Available"; |
||||
switch (errorCode) { |
||||
case DecCst.ErrorCode.USERNAME_UNAVAILABLE: |
||||
case DecCst.ErrorCode.USERNAME_NOT_EXITS: |
||||
case DecCst.ErrorCode.PLATFORM_USER_REMOVE: |
||||
text = "Dec-Login_Account_Not_Available"; |
||||
break; |
||||
case DecCst.ErrorCode.SINGLE_LOGIN_KICK: |
||||
text = "Dec-Login_Single_Logged_Tip"; |
||||
break; |
||||
case DecCst.ErrorCode.USERNAME_PASSWORD_ERROR: |
||||
text = "Dec-Login_Password_Changed"; |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
BI.Popovers.create(name, { |
||||
header: BI.i18nText("BI-Basic_Prompt"), |
||||
size: "small", |
||||
closable: false, |
||||
body: { |
||||
type: "bi.label", |
||||
whiteSpace: "normal", |
||||
text: BI.i18nText(text) |
||||
}, |
||||
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(name); |
||||
var host =window.location.host; |
||||
var url = getLogoutUrl(); |
||||
console.info(url); |
||||
window.location.href=url |
||||
// if (myService.isAdmin()){
|
||||
// window.location.reload(true);
|
||||
// }else {
|
||||
// var url = getUrl();
|
||||
// window.location.href=url;
|
||||
// }
|
||||
} |
||||
}] |
||||
} |
||||
}, this).open(name); |
||||
} |
||||
|
||||
function getLogoutUrl(){ |
||||
var url = ""; |
||||
|
||||
$.ajax({ |
||||
type:"get", |
||||
async:false, |
||||
url:"/webroot/decision/url/getLogout", |
||||
success:function(data){ |
||||
url = data.data |
||||
} |
||||
}) |
||||
|
||||
return url; |
||||
} |
||||
|
||||
function getUrl() { |
||||
var jsonData = "{}"; |
||||
var url=""; |
||||
$.ajax({ |
||||
url: Dec.fineServletURL + "/getUrl", |
||||
type: "post", |
||||
contentType: "application/json", |
||||
data: jsonData, |
||||
dataType: "json", |
||||
cache: false, |
||||
async: false, |
||||
error: function () { |
||||
console.log("或取普通用户跳转的地址失败 !"); |
||||
}, |
||||
complete: function (data, status) { |
||||
if (status == "success"){ |
||||
if(data.responseText=="") { |
||||
console.log("或取普通用户跳转的地址为空!"); |
||||
}else { |
||||
var remindPage = $.parseJSON( data.responseText ).remindPage; |
||||
url = remindPage; |
||||
console.log("或取普通用户跳转的地址为:"+url); |
||||
} |
||||
}else { |
||||
console.log("或取普通用户跳转的地址失败!"); |
||||
} |
||||
|
||||
} |
||||
}); |
||||
return url; |
||||
|
||||
} |
||||
|
||||
|
||||
})(); |
Binary file not shown.
Loading…
Reference in new issue