diff --git a/JSD-7930-需求确认书V1.docx b/JSD-7930-需求确认书V1.docx new file mode 100644 index 0000000..fc4b83c Binary files /dev/null and b/JSD-7930-需求确认书V1.docx differ diff --git a/README.md b/README.md index 958cd3e..d4ffa6c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # open-JSD-7930 -JSD-7930 开源任务材料 \ No newline at end of file +JSD-7930 开源任务材料\ +免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ +仅作为开发者学习参考使用!禁止用于任何商业用途!\ +为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 \ No newline at end of file diff --git a/lib/common-1.1.3.jar b/lib/common-1.1.3.jar new file mode 100644 index 0000000..0f3c8b9 Binary files /dev/null and b/lib/common-1.1.3.jar differ diff --git a/lib/commons-codec-1.9.jar b/lib/commons-codec-1.9.jar new file mode 100644 index 0000000..ef35f1c Binary files /dev/null and b/lib/commons-codec-1.9.jar differ diff --git a/lib/http-client-1.1.3.jar b/lib/http-client-1.1.3.jar new file mode 100644 index 0000000..fffabdb Binary files /dev/null and b/lib/http-client-1.1.3.jar differ diff --git a/lib/httpasyncclient-4.1.jar b/lib/httpasyncclient-4.1.jar new file mode 100644 index 0000000..a2689b4 Binary files /dev/null and b/lib/httpasyncclient-4.1.jar differ diff --git a/lib/httpclient-4.4.1.jar b/lib/httpclient-4.4.1.jar new file mode 100644 index 0000000..b80d379 Binary files /dev/null and b/lib/httpclient-4.4.1.jar differ diff --git a/lib/httpcore-4.4.1.jar b/lib/httpcore-4.4.1.jar new file mode 100644 index 0000000..99715b6 Binary files /dev/null and b/lib/httpcore-4.4.1.jar differ diff --git a/lib/httpcore-nio-4.4.1.jar b/lib/httpcore-nio-4.4.1.jar new file mode 100644 index 0000000..ebb5c10 Binary files /dev/null and b/lib/httpcore-nio-4.4.1.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..60a9f18 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,26 @@ + + com.fr.plugin.jdfSSO2 + + yes + 1.0.12 + 10.0 + 2018-07-31 + author + + + com.fr.plugin.jdfSSO2 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/jdfSSO2/ThemeWebResourceProvider.java b/src/main/java/com/fr/plugin/jdfSSO2/ThemeWebResourceProvider.java new file mode 100644 index 0000000..52acbf6 --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/ThemeWebResourceProvider.java @@ -0,0 +1,34 @@ +package com.fr.plugin.jdfSSO2; + +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 ThemeWebResourceProvider 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/fr/plugin/jdfSSO2/js/updateName.js"); + } + + @Override + public StylePath style(RequestClient requestClient) { + return StylePath.build("/com/fr/plugin/jdfSSO2/css/icon.css"); + } + }; + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/config/simple/DemoInitializeMonitor.java b/src/main/java/com/fr/plugin/jdfSSO2/config/simple/DemoInitializeMonitor.java new file mode 100644 index 0000000..56f85e4 --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/config/simple/DemoInitializeMonitor.java @@ -0,0 +1,22 @@ +package com.fr.plugin.jdfSSO2.config.simple; + +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.jdfSSO2.config.simple.account.PluginSimpleConfig; +import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2018-12-04 + */ +public class DemoInitializeMonitor extends AbstractPluginLifecycleMonitor { + @Override + public void afterRun(PluginContext pluginContext) { + PluginSimpleConfig.getInstance(); + } + + @Override + public void beforeStop(PluginContext pluginContext) { + + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/config/simple/PluginInitializeFilterBridge.java b/src/main/java/com/fr/plugin/jdfSSO2/config/simple/PluginInitializeFilterBridge.java new file mode 100644 index 0000000..f9d04dd --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/config/simple/PluginInitializeFilterBridge.java @@ -0,0 +1,23 @@ +package com.fr.plugin.jdfSSO2.config.simple; + +import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider; +import com.fr.plugin.jdfSSO2.config.simple.account.PluginSimpleConfig; + +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class PluginInitializeFilterBridge extends AbstractEmbedRequestFilterProvider { + + @Override + public void init(FilterConfig filterConfig) { + PluginSimpleConfig.getInstance(); + } + + @Override + public void filter(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { + + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/config/simple/PluginLocaleFinderBridge.java b/src/main/java/com/fr/plugin/jdfSSO2/config/simple/PluginLocaleFinderBridge.java new file mode 100644 index 0000000..c50ff47 --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/config/simple/PluginLocaleFinderBridge.java @@ -0,0 +1,10 @@ +package com.fr.plugin.jdfSSO2.config.simple; + +import com.fr.stable.fun.impl.AbstractLocaleFinder; + +public class PluginLocaleFinderBridge extends AbstractLocaleFinder { + @Override + public String find() { + return "conf"; + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/config/simple/account/PluginSimpleConfig.java b/src/main/java/com/fr/plugin/jdfSSO2/config/simple/account/PluginSimpleConfig.java new file mode 100644 index 0000000..bffb0c2 --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/config/simple/account/PluginSimpleConfig.java @@ -0,0 +1,101 @@ +package com.fr.plugin.jdfSSO2.config.simple.account; + +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.fr.plugin.jdfSSO2.config.simple", text = "单点登录配置", source = Original.PLUGIN) + public static PluginSimpleConfig getInstance() { + if (config == null) { + config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); + } + return config; + } + + @Identifier(value = "clientId", name = "客户端id", description = "客户端应用注册ID(用户中心应用管理中查看)", status = Status.SHOW) + private Conf clientId = Holders.simple(""); + + @Identifier(value = "secret", name = "客户端密钥", description = "客户端应用密钥(用户中心应用管理中查看)", status = Status.SHOW) + private Conf secret = Holders.simple(""); + + @Identifier(value = "tokenUrl", name = "单点认证接口", description = "单点认证接口", status = Status.SHOW) + private Conf tokenUrl = Holders.simple(""); + + @Identifier(value = "tokenName", name = "单点认证接口接口名称", description = "单点认证接口接口名称", status = Status.SHOW) + private Conf tokenName = Holders.simple(""); + + @Identifier(value = "ak", name = "ak", description = "ak", status = Status.SHOW) + private Conf ak = Holders.simple(""); + + @Identifier(value = "sk", name = "sk", description = "sk", status = Status.SHOW) + private Conf sk = 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 getTokenUrl() { + return tokenUrl.get(); + } + + public void setTokenUrl(String url) { + this.tokenUrl.set(url); + } + + public String getTokenName() { + return tokenName.get(); + } + + public void setTokenName(String url) { + this.tokenName.set(url); + } + + public String getAk() { + return ak.get(); + } + + public void setAk(String url) { + this.ak.set(url); + } + + public String getSk() { + return sk.get(); + } + + public void setSk(String url) { + this.sk.set(url); + } + + @Override + public Object clone() throws CloneNotSupportedException { + PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone(); +// cloned.text = (Conf) text.clone(); +// cloned.count = (Conf) count.clone(); +// cloned.price = (Conf) price.clone(); +// cloned.time = (Conf) time.clone(); +// cloned.student = (Conf) student.clone(); + return cloned; + } + +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/filter/LoginFilter.java b/src/main/java/com/fr/plugin/jdfSSO2/filter/LoginFilter.java new file mode 100644 index 0000000..2ab92be --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/filter/LoginFilter.java @@ -0,0 +1,131 @@ +package com.fr.plugin.jdfSSO2.filter; + + +import com.alibaba.csb.sdk.ContentBody; +import com.alibaba.csb.sdk.HttpCaller; +//import com.alibaba.csb.sdk.HttpCallerException; +import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider; +import com.fr.json.JSONObject; +import com.fr.plugin.jdfSSO2.config.simple.account.PluginSimpleConfig; +import com.fr.plugin.jdfSSO2.utils.FRUtils; +import com.fr.plugin.jdfSSO2.utils.Utils; + + +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.Date; +import java.util.HashMap; +import java.util.Map; + +public class LoginFilter extends AbstractEmbedRequestFilterProvider { + + @Override + public void filter(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException { + boolean isLogin = FRUtils.isLogin(httpServletRequest); + String url = FRUtils.getAllUrl(httpServletRequest); + FRUtils.FRLogInfo("url:"+url); + + HttpSession session = httpServletRequest.getSession(true); + String systemName = httpServletRequest.getParameter("systemName"); + + if(Utils.isNotNullStr(systemName)){ + systemName = "DBG".equals(systemName)?"显示事业智慧决策":"报表中心"; + FRUtils.FRLogInfo("单点登录:systemName"+systemName); + FRUtils.FRLogInfo("单点时间:"+new Date().toString()); + session.setAttribute("systemName",systemName); + session.setMaxInactiveInterval(60*60*24); + } + + //判断系统是否登录 + if(!isLogin && !url.contains("getName") && !url.contains("updateName")){ + PluginSimpleConfig pluginSimpleConfig = PluginSimpleConfig.getInstance(); + //认证方式 + String boeType = ""; + //token + String boeToken = ""; + String clientId =pluginSimpleConfig.getClientId(); + String secret = pluginSimpleConfig.getSecret(); + String tokenUrl = pluginSimpleConfig.getTokenUrl(); + + //如果系统未登录,判断cookie里面是否有token + Cookie[] cookies = httpServletRequest.getCookies(); + + if(cookies != null && cookies.length > 0){ + for(Cookie cookie : cookies){ + String cookieName = cookie.getName(); + if("boeType".equals(cookieName)){ + boeType = cookie.getValue(); + } + + if("boeToken".equals(cookieName)){ + boeToken = cookie.getValue(); + } + + FRUtils.FRLogInfo("单点登录:cookieName"+cookieName+";cookieValue:"+cookie.getValue()); + } + } + + + //如果存在token则请求50008接口,返回用户信息进行登录 + if(Utils.isNotNullStr(boeToken) && Utils.isNotNullStr(boeType)){ + FRUtils.FRLogInfo("单点登录:boeToken:"+boeToken+";boeType="+boeType); + + String reqMethos = "post"; + String version = "1.0.0"; + JSONObject params = new JSONObject(); + params.put("type",boeType); + params.put("token",boeToken); + params.put("client_id",clientId); + params.put("client_secret",secret); + + String returnResult = request(tokenUrl,reqMethos,params,version); + FRUtils.FRLogInfo("单点登录:returnResult:"+returnResult); + + JSONObject result = new JSONObject(returnResult); + String resultCode = result.getString("result_code"); + + //状态码 + FRUtils.FRLogInfo("单点登录:result_code:"+resultCode); + + if("200".equals(resultCode)){ + JSONObject data = result.getJSONObject("data"); + String userCode = data.getString("userCode"); + + FRUtils.FRLogInfo("单点登录:userCode:"+userCode); + if(!Utils.isNullStr(userCode)){ + FRUtils.login(httpServletRequest,httpServletResponse,userCode,""); + } + } + + } + } + } + + public static String request(String httpUrl, String reqMethod, JSONObject params, String version) { + if(httpUrl == null || reqMethod == null || params == null){ + return null; + } + + PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); + String API_NAME = psc.getTokenName(); + String ak = psc.getAk(); + String sk = psc.getSk(); + + String result = null; + try { + ContentBody body = new ContentBody(params.toString()); + result = HttpCaller.doPost(httpUrl, API_NAME, version,body, ak, sk); + if (result != null) { + // 返回结果处理, 如转换为JSON对象 + } + } catch (Exception e) { + FRUtils.FRLogInfo("单点登录:exception:"+e.getMessage()); + // 调用异常处理 + } + return result; + } + +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/handler/ExtendAttrHandlerProvider.java b/src/main/java/com/fr/plugin/jdfSSO2/handler/ExtendAttrHandlerProvider.java new file mode 100644 index 0000000..7585e23 --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/handler/ExtendAttrHandlerProvider.java @@ -0,0 +1,13 @@ +package com.fr.plugin.jdfSSO2.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 UpdateNameHandler(),new GetNameHandler() + }; + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/handler/GetNameHandler.java b/src/main/java/com/fr/plugin/jdfSSO2/handler/GetNameHandler.java new file mode 100644 index 0000000..07ae620 --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/handler/GetNameHandler.java @@ -0,0 +1,44 @@ +package com.fr.plugin.jdfSSO2.handler; + +import com.fr.decision.fun.impl.BaseHttpHandler; +import com.fr.plugin.jdfSSO2.utils.FRUtils; +import com.fr.plugin.jdfSSO2.utils.ResponseUtils; +import com.fr.plugin.transform.FunctionRecorder; +import com.fr.third.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.util.Date; + +@FunctionRecorder +public class GetNameHandler extends BaseHttpHandler { + + public GetNameHandler() { + } + + @Override + public RequestMethod getMethod() { + return RequestMethod.GET; + } + + @Override + public String getPath() { + return "/getName"; + } + + @Override + public boolean isPublic() { + return true; + } + + @Override + public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { + + HttpSession session = req.getSession(true); + + String systemName = String.valueOf(session.getAttribute("systemName")); + FRUtils.FRLogInfo("获取session时间:"+new Date().toString()); + ResponseUtils.successResponse(res,systemName); + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/handler/URLAliasProvide.java b/src/main/java/com/fr/plugin/jdfSSO2/handler/URLAliasProvide.java new file mode 100644 index 0000000..95b88fb --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/handler/URLAliasProvide.java @@ -0,0 +1,15 @@ +package com.fr.plugin.jdfSSO2.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("/updateName","/updateName",true), + URLAliasFactory.createPluginAlias("/getName","/getName",true), + }; + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/handler/UpdateNameHandler.java b/src/main/java/com/fr/plugin/jdfSSO2/handler/UpdateNameHandler.java new file mode 100644 index 0000000..02a76c1 --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/handler/UpdateNameHandler.java @@ -0,0 +1,50 @@ +package com.fr.plugin.jdfSSO2.handler; + +import com.fr.decision.fun.impl.BaseHttpHandler; +import com.fr.third.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +public class UpdateNameHandler extends BaseHttpHandler { + private static String moduleId = ""; + private static String md5Secret=""; + private static String startFlowUrl=""; + + static + { +// PluginSimpleConfig config = PluginSimpleConfig.getInstance(); +// +// moduleId = config.getModuleId(); +// md5Secret = config.getMd5Secret(); +// startFlowUrl = config.getStartFlowUrl(); + } + + public UpdateNameHandler() { + } + + @Override + public RequestMethod getMethod() { + return RequestMethod.GET; + } + + @Override + public String getPath() { + return "/updateName"; + } + + @Override + public boolean isPublic() { + return true; + } + + @Override + public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { + String systemName = req.getParameter("systemName"); + + HttpSession session = req.getSession(true); + session.setAttribute("systemName",systemName); + session.setMaxInactiveInterval(60*60*24); + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/utils/FRUtils.java b/src/main/java/com/fr/plugin/jdfSSO2/utils/FRUtils.java new file mode 100644 index 0000000..dd0b9ee --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/utils/FRUtils.java @@ -0,0 +1,158 @@ +package com.fr.plugin.jdfSSO2.utils; + +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.log.FineLoggerFactory; +import com.fr.stable.StringUtils; +import com.fr.stable.query.QueryFactory; +import com.fr.stable.query.restriction.RestrictionFactory; +import com.fr.web.utils.WebUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.util.List; + +public class FRUtils { + /** + * 判断用户是否存在 + * @param userName + * @return + */ + public static boolean isUserExist(String userName){ + if (StringUtils.isEmpty(userName)) { + return false; + } else { + try { + List var1 = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); + return var1 != null && !var1.isEmpty(); + } catch (Exception var2) { + FineLoggerFactory.getLogger().error(var2.getMessage()); + return false; + } + } + } + + /** + * 判断是否登录FR + * @param req + * @return + */ + public static boolean isLogin(HttpServletRequest req){ + return LoginService.getInstance().isLogged(req); + } + + /** + * 帆软登录 + * @param httpServletRequest + * @param httpServletResponse + * @param userName + * @param url + */ + public static void login(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String userName,String url){ + + FineLoggerFactory.getLogger().info("FRLOG:用户名:"+userName); + FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); + + + //判断用户名是否为空 + if(!Utils.isNullStr(userName)){ + if(isUserExist(userName)){ + String FRToken = ""; + + try { + HttpSession session = httpServletRequest.getSession(true); + + FRToken = LoginService.getInstance().login(httpServletRequest, httpServletResponse, userName); + + httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,FRToken); + + session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, FRToken); + EventDispatcher.fire(LogInOutEvent.LOGIN,new LogInOutResultInfo(httpServletRequest,httpServletResponse,userName,true)); + FineLoggerFactory.getLogger().info("FRLOG:登陆成功!"); + + if(!Utils.isNullStr(url)){ + httpServletResponse.sendRedirect(url); + } + } catch (Exception e) { + ResponseUtils.failedResponse(httpServletResponse,"登录异常,请联系管理员!"); + FineLoggerFactory.getLogger().info("FRLOG:登录异常,请联系管理员!"); + FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); + } + }else{ + ResponseUtils.failedResponse(httpServletResponse,"用户在报表系统中不存在!"); + FineLoggerFactory.getLogger().info("FRLOG:用户在报表系统中不存在!"); + } + }else{ + ResponseUtils.failedResponse(httpServletResponse,"用户名不能为空!"); + FineLoggerFactory.getLogger().info("FRLOG:用户名不能为空!"); + } + } + + /** + * + * @param httpServletRequest + * @param httpServletResponse + */ + public static void logout(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) + { + if(!isLogin(httpServletRequest)){ + return ; + } + + try { + LoginService.getInstance().logout(httpServletRequest,httpServletResponse); + } catch (Exception e) { + ResponseUtils.failedResponse(httpServletResponse,"登出异常,请联系管理员!"); + FineLoggerFactory.getLogger().info("FRLOG:登出异常,请联系管理员!"); + FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); + } + } + + /** + * 打印FR日志 + * @param message + */ + public static void FRLogInfo(String message){ + FineLoggerFactory.getLogger().info("FRLOG:"+message); + } + + /** + * 根据用户名获取用户信息 + * @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); + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/utils/HttpUtils.java b/src/main/java/com/fr/plugin/jdfSSO2/utils/HttpUtils.java new file mode 100644 index 0000000..d6c1a70 --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/utils/HttpUtils.java @@ -0,0 +1,237 @@ +package com.fr.plugin.jdfSSO2.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 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 keySet = header.keySet(); + + for(String key : keySet){ + getMethod.setHeader(key,header.get(key)); + } + } + + try { + HttpResponse response = httpclient.execute(getMethod); + + FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--status:"+response.getStatusLine().getStatusCode()); + + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + HttpEntity entity = response.getEntity(); + String returnResult = EntityUtils.toString(entity, "utf-8"); + + FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--returnResult:"+returnResult); + + 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); + + FineLoggerFactory.getLogger().info("FRLOG:HttpPost:status:"+response.getStatusLine().getStatusCode()); + + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + HttpEntity entity = response.getEntity(); + String returnResult = EntityUtils.toString(entity, "utf-8"); + + FineLoggerFactory.getLogger().info("FRLOG:HttpPost:returnResult:"+returnResult); + + 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 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 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 header,Map param){ + FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:url:"+url); + + HttpPost postMethod = new HttpPost(url); + + if(header != null && header.size() > 0){ + Set keySet = header.keySet(); + + for(String key : keySet){ + postMethod.setHeader(key,header.get(key)); + } + } + + if(param != null && param.size() > 0){ + List params = new ArrayList(param.size()); + + for(Map.Entry 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 (NoSuchAlgorithmException e) { + FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage()); + } catch (KeyManagementException e) { + FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage()); + } catch (KeyStoreException e) { + FRUtils.FRLogInfo("createHttpClientException:"+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; + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/utils/ResponseUtils.java b/src/main/java/com/fr/plugin/jdfSSO2/utils/ResponseUtils.java new file mode 100644 index 0000000..7d77a3a --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/utils/ResponseUtils.java @@ -0,0 +1,94 @@ +package com.fr.plugin.jdfSSO2.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(); + } +} diff --git a/src/main/java/com/fr/plugin/jdfSSO2/utils/Utils.java b/src/main/java/com/fr/plugin/jdfSSO2/utils/Utils.java new file mode 100644 index 0000000..1823e94 --- /dev/null +++ b/src/main/java/com/fr/plugin/jdfSSO2/utils/Utils.java @@ -0,0 +1,94 @@ +package com.fr.plugin.jdfSSO2.utils; + +import com.fr.json.JSONObject; +import com.fr.stable.CodeUtils; +import com.fr.third.org.apache.commons.codec.digest.DigestUtils; +import javax.servlet.http.HttpServletRequest; +import java.io.BufferedReader; +import java.util.UUID; + +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); + } + + + /** + * 获取完整的访问路径 + */ + public static String getAllUrl(HttpServletRequest req, String queryStr){ + String url = req.getRequestURL().toString(); + + if(isNullStr(queryStr)){ + return url; + } + + return url+"?"+queryStr; + } + + /** + * 帆软shaEncode加密 + */ + + public static String shaEncode(String str){ + return CodeUtils.sha256Encode(str); + } + + /** + * 获取uuid + */ + public static String uuid(){ + return UUID.randomUUID().toString(); + } + + public static String replaceNullStr(String str,String replace){ + if(isNullStr(str)){ + return replace; + } + + return str; + } + + 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; + } +} diff --git a/src/main/resources/com/fr/plugin/jdfSSO2/css/icon.css b/src/main/resources/com/fr/plugin/jdfSSO2/css/icon.css new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/com/fr/plugin/jdfSSO2/js/updateName.js b/src/main/resources/com/fr/plugin/jdfSSO2/js/updateName.js new file mode 100644 index 0000000..fc6ef23 --- /dev/null +++ b/src/main/resources/com/fr/plugin/jdfSSO2/js/updateName.js @@ -0,0 +1,53 @@ + +$(document).ready(function(){ + var decisionName = getDecisionName(); + if(decisionName != '数据决策系统'){ + Dec.platformStyles.platformTitle = getDecisionName(); + BI.Services.getService("dec.service.style.configure").savePlatformStyle() + } +}) + +function getDecisionName() +{ + var decisionName = ""; + $.ajax({ + type:"GET", + url:Dec.fineServletURL+"/url/getName", + async:false, + success:function(data){ + if(data.code == 200){ + decisionName=data.data; + } + }, + error:function(data){ + } + }) + + if(decisionName == '' || decisionName == null || decisionName == 'null'){ + decisionName = "数据决策系统"; + } + + return decisionName; +} +// +// function getDecisionName(){ +// var decisionName = ""; +// $.ajax({ +// type:"GET", +// url:Dec.fineServletURL+"/url/getName", +// async:false, +// success:function(data){ +// if(data.code == 200){ +// decisionName=data.data; +// } +// }, +// error:function(data){ +// } +// }) +// +// if(decisionName == ''){ +// decisionName = "数据决策系统"; +// } +// +// return decisionName; +// } \ No newline at end of file diff --git a/操作手册.doc b/操作手册.doc new file mode 100644 index 0000000..0704c5e Binary files /dev/null and b/操作手册.doc differ