From ca547c3df0c74849d6f52d389829d815b5eff508 Mon Sep 17 00:00:00 2001 From: pioneer Date: Tue, 8 Nov 2022 15:10:52 +0800 Subject: [PATCH] open --- README.md | 7 + plugin.xml | 25 ++ .../xx/yzdlsso/config/InitializeMonitor.java | 21 ++ .../xx/yzdlsso/config/PluginSimpleConfig.java | 112 +++++++ .../ControllerRegisterProvider.java | 14 + .../yzdlsso/controller/UtilsController.java | 41 +++ .../xx/yzdlsso/filter/LogoutFilter.java | 44 +++ .../plugin/xx/yzdlsso/filter/SSOFilter.java | 185 +++++++++++ .../eco/plugin/xx/yzdlsso/logout/Logout.java | 20 ++ .../eco/plugin/xx/yzdlsso/utils/FRUtils.java | 293 ++++++++++++++++++ .../plugin/xx/yzdlsso/utils/HttpUtils.java | 265 ++++++++++++++++ .../xx/yzdlsso/utils/ResponseUtils.java | 108 +++++++ .../eco/plugin/xx/yzdlsso/utils/Utils.java | 244 +++++++++++++++ .../webresource/WebResourceProvider.java | 36 +++ .../resources/com/eco/plugin/xx/js/yzdlsso.js | 248 +++++++++++++++ 15 files changed, 1663 insertions(+) create mode 100644 README.md create mode 100644 plugin.xml create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/config/InitializeMonitor.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/config/PluginSimpleConfig.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/controller/ControllerRegisterProvider.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/controller/UtilsController.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/filter/LogoutFilter.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/filter/SSOFilter.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/logout/Logout.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/utils/FRUtils.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/utils/HttpUtils.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/utils/ResponseUtils.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/utils/Utils.java create mode 100644 src/main/java/com/eco/plugin/xx/yzdlsso/webresource/WebResourceProvider.java create mode 100644 src/main/resources/com/eco/plugin/xx/js/yzdlsso.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..8864f8e --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ + +# open-JSD-9870 + +JSD-9870 OA单点集成\ +免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ +仅作为开发者学习参考使用!禁止用于任何商业用途!\ +为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 \ No newline at end of file diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..75d5889 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,25 @@ + + com.eco.plugin.xx.yzdlsso + + yes + 1.0.6 + 10.0 + 2018-07-31 + fr.open + + + com.eco.plugin.xx.yzdlsso + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/config/InitializeMonitor.java b/src/main/java/com/eco/plugin/xx/yzdlsso/config/InitializeMonitor.java new file mode 100644 index 0000000..9f86194 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/config/InitializeMonitor.java @@ -0,0 +1,21 @@ +package com.eco.plugin.xx.yzdlsso.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) { + + } +} diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/config/PluginSimpleConfig.java b/src/main/java/com/eco/plugin/xx/yzdlsso/config/PluginSimpleConfig.java new file mode 100644 index 0000000..5f9620e --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/config/PluginSimpleConfig.java @@ -0,0 +1,112 @@ +package com.eco.plugin.xx.yzdlsso.config; + +import com.fr.config.*; +import com.fr.config.holder.Conf; +import com.fr.config.holder.factory.Holders; +import com.fr.intelli.record.Focus; +import com.fr.intelli.record.Original; +import com.fr.record.analyzer.EnableMetrics; + +@Visualization(category = "单点登录配置") +@EnableMetrics +public class PluginSimpleConfig extends DefaultConfiguration { + + private static volatile PluginSimpleConfig config = null; + + @Focus(id="com.eco.plugin.xx.yzdlsso.config", 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 = "index", name = "帆软首页", description = "帆软首页", status = Status.SHOW) + private Conf index = Holders.simple("http://localhost:8075/webroot/decision"); + + @Identifier(value = "authUrl", name = "获取授权码接口", description = "获取授权码接口", status = Status.SHOW) + private Conf authUrl = Holders.simple(""); + + @Identifier(value = "tokenUrl", name = "获取token接口", description = "获取token接口", status = Status.SHOW) + private Conf tokenUrl = Holders.simple(""); + + @Identifier(value = "userUrl", name = "获取用户信息接口", description = "获取用户信息接口", status = Status.SHOW) + private Conf userUrl = Holders.simple(""); + + @Identifier(value = "logoutUrl", name = "登出接口", description = "登出接口", status = Status.SHOW) + private Conf 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 getIndex() { + 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) 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/eco/plugin/xx/yzdlsso/controller/ControllerRegisterProvider.java b/src/main/java/com/eco/plugin/xx/yzdlsso/controller/ControllerRegisterProvider.java new file mode 100644 index 0000000..aefa43e --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/controller/ControllerRegisterProvider.java @@ -0,0 +1,14 @@ +package com.eco.plugin.xx.yzdlsso.controller; + +import com.fr.decision.fun.impl.AbstractControllerRegisterProvider; +import com.fr.plugin.transform.FunctionRecorder; + +@FunctionRecorder +public class ControllerRegisterProvider extends AbstractControllerRegisterProvider { + @Override + public Class[] getControllers() { + return new Class[]{ + UtilsController.class + }; + } +} diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/controller/UtilsController.java b/src/main/java/com/eco/plugin/xx/yzdlsso/controller/UtilsController.java new file mode 100644 index 0000000..ec711ed --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/controller/UtilsController.java @@ -0,0 +1,41 @@ +package com.eco.plugin.xx.yzdlsso.controller; + +import com.eco.plugin.xx.yzdlsso.utils.FRUtils; +import com.eco.plugin.xx.yzdlsso.utils.Utils; +import com.fr.decision.webservice.annotation.LoginStatusChecker; +import com.fr.plugin.transform.FunctionRecorder; +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.util.HashMap; +import java.util.Map; + +@Controller +@LoginStatusChecker(required = false) +@FunctionRecorder +public class UtilsController { + + @GetMapping(value = "/isAdmin") + @ResponseBody + public Map isAdmin(HttpServletRequest request, HttpServletResponse response) throws Exception { + Map result = new HashMap(); + String username = request.getParameter("username"); + + result.put("isadmin", Utils.isAdmin(username)); + + return result; + } + + @GetMapping(value = "/userIsExist") + @ResponseBody + public Map userIsExist(HttpServletRequest request, HttpServletResponse response) throws Exception { + Map result = new HashMap(); + String username = request.getParameter("username"); + + result.put("isExist", FRUtils.isUserExist(username)); + + return result; + } +} diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/filter/LogoutFilter.java b/src/main/java/com/eco/plugin/xx/yzdlsso/filter/LogoutFilter.java new file mode 100644 index 0000000..02fcfeb --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/filter/LogoutFilter.java @@ -0,0 +1,44 @@ +package com.eco.plugin.xx.yzdlsso.filter; + +import com.fr.decision.fun.GlobalRequestFilterProvider; +import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; +import com.fr.record.analyzer.EnableMetrics; +import org.jetbrains.annotations.NotNull; +import javax.servlet.FilterChain; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@EnableMetrics +public class LogoutFilter extends AbstractGlobalRequestFilterProvider { + @Override + public String filterName() { + return "logoutFilter"; + } + + @Override + public String[] urlPatterns() { + return new String[]{"/*"}; + } + + @Override + public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){ + + } + + public String externalFilterClassName() { + return "org.jasig.cas.client.session.SingleSignOutFilter"; + } + + + /** + * 可选实现的多个filter排序(执行顺序)的方法 + * @param other + * @return 0 相等,大于0是自身优先 小于0 是other优先 + */ + + public int compareTo(@NotNull GlobalRequestFilterProvider other ){ + return super.compareTo(other); + } + +} + diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/filter/SSOFilter.java b/src/main/java/com/eco/plugin/xx/yzdlsso/filter/SSOFilter.java new file mode 100644 index 0000000..7aa793b --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/filter/SSOFilter.java @@ -0,0 +1,185 @@ +package com.eco.plugin.xx.yzdlsso.filter; + +import com.eco.plugin.xx.yzdlsso.config.PluginSimpleConfig; +import com.eco.plugin.xx.yzdlsso.utils.FRUtils; +import com.eco.plugin.xx.yzdlsso.utils.HttpUtils; +import com.eco.plugin.xx.yzdlsso.utils.Utils; +import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; +import com.fr.decision.webservice.v10.login.LoginService; +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 javax.servlet.http.HttpSession; +import java.io.IOException; +import java.net.URLEncoder; + +@EnableMetrics +@Authorize(callSignKey = "com.eco.plugin.xx.yzdlsso") +public class SSOFilter extends AbstractGlobalRequestFilterProvider { + @Override + public String filterName() { + return "yzdlssoFilter"; + } + + @Override + public String[] urlPatterns() { + return new String[]{"/*"}; + } + + @Override + public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){ + FRUtils.FRLogInfo("request:"+FRUtils.getAllUrl(req)); + if(PluginContexts.currentContext().isAvailable()){ + PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); + + + + //是否放行 + boolean release = isRelease(req,res,psc); + + if(release){ + release(req,res,chain); + return; + } + + String url1 = FRUtils.getAllUrl(req); + String code = req.getParameter("ticket"); + + if(Utils.isNullStr(code)){ + //跳转认证中心 + redirect(req,res,psc); + return; + } + + String url = FRUtils.getAllUrl(req); + url = Utils.removeParam(url,"ticket"); + + //获取token + String token = getToken(code,psc,url); + + //获取userInfo + String username = getUsername(token,psc); + + //登录 + FRUtils.login(req,res,username,Utils.encodeCH(url)); + return ; + } + + release(req,res,chain); + } + + public static String safeGetParameter(HttpServletRequest request, String parameter) { + if ("POST".equals(request.getMethod()) && "logoutRequest".equals(parameter)) { + return request.getParameter(parameter); + } else { + return request.getQueryString() != null && request.getQueryString().indexOf(parameter) != -1 ? request.getParameter(parameter) : null; + } + } + + private static boolean isMultipartRequest(HttpServletRequest request) { + return request.getContentType() != null && request.getContentType().toLowerCase().startsWith("multipart"); + } + + public static boolean isLogoutRequest(HttpServletRequest request) { + return "POST".equals(request.getMethod()) && !isMultipartRequest(request) && Utils.isNotNullStr(safeGetParameter(request, "logoutRequest")); + } + + private static boolean isRelease(HttpServletRequest req,HttpServletResponse res,PluginSimpleConfig psc){ + //请求url,ngix映射有问题,手动将ip换为域名 + String url = FRUtils.getAllUrl(req); + + //登出请求 + if(isLogoutRequest(req)){ + FRUtils.FRLogInfo("登出请求!"); + HttpSession session = req.getSession(true); + LoginService.getInstance().crossDomainLogout(req,res,""); + session.invalidate(); + + try { + res.sendRedirect(psc.getLogoutUrl()+"?service="+psc.getIndex()); + } catch (IOException e) { + FRUtils.FRLogInfo("统一登出异常"); + } + return true; + } + + //是否需要拦截 系统首页、模板链接 + boolean isViewlet = (url.contains("viewlet=") && (url.contains(".cpt") || url.contains(".frm"))) || url.equals(psc.getIndex()); + + //是否登陆 + boolean isLogin = FRUtils.isLogin(req); + + //远程设计 + String reft = req.getParameter("ref_t"); + + return ("design".equals(reft) || !isViewlet || isLogin) && !url.contains("ticket"); + } + + //跳转认证中心 + private void redirect(HttpServletRequest req,HttpServletResponse res, PluginSimpleConfig psc) { + String authurl = psc.getAuthUrl()+"?client_id="+psc.getClientId()+"&redirect_uri="+ URLEncoder.encode(FRUtils.getAllUrl(req))+"&response_type=code"; +// String authurl = psc.getAuthUrl()+"?client_id="+psc.getClientId()+"&redirect_uri=http://127.0.0.1:8075/webroot/decision&response_type=code"; + + try { + res.sendRedirect(authurl); + } catch (IOException e) { + FRUtils.FRLogInfo("跳转认证中心异常:"+e.getMessage()); + } + } + + //获取token + private String getToken(String code,PluginSimpleConfig psc,String url) { + String tokenurl = psc.getTokenUrl()+"?client_id="+psc.getClientId()+"&client_secret="+psc.getSecret()+"&grant_type=authorization_code&code="+code+"&redirect_uri="+URLEncoder.encode(url); +// String tokenurl = psc.getTokenUrl()+"?client_id="+psc.getClientId()+"&client_secret="+psc.getSecret()+"&grant_type=authorization_code&code="+code+"&redirect_uri=http://127.0.0.1:8075/webroot/decision"; + + String result = HttpUtils.HttpPostJson(tokenurl,"",null); + + if(Utils.isNullStr(result)){ + return ""; + } + + JSONObject json = new JSONObject(result); + + if(json == null ){ + return ""; + } + + String token = json.getString("access_token"); + return token; + } + + //获取用户名 + private String getUsername(String openId,PluginSimpleConfig psc) { + String tokenurl = psc.getUserUrl()+"?access_token="+openId; + + String result = HttpUtils.HttpPostJson(tokenurl,"",null); + + if(Utils.isNullStr(result)){ + return ""; + } + + JSONObject json = new JSONObject(result); + + if(json == null ){ + return ""; + } + + String username = json.getString("id"); + return username; + } + + //放行拦截器 + private void release(HttpServletRequest req, HttpServletResponse res, FilterChain chain) { + try{ + chain.doFilter(req,res); + }catch (Exception e){ + FRUtils.FRLogInfo("拦截失败"); + } + } +} + diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/logout/Logout.java b/src/main/java/com/eco/plugin/xx/yzdlsso/logout/Logout.java new file mode 100644 index 0000000..ef5d911 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/logout/Logout.java @@ -0,0 +1,20 @@ +package com.eco.plugin.xx.yzdlsso.logout; + +import com.eco.plugin.xx.yzdlsso.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(); + PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); + return psc.getLogoutUrl()+"?service="+psc.getIndex(); + } +} + diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/utils/FRUtils.java b/src/main/java/com/eco/plugin/xx/yzdlsso/utils/FRUtils.java new file mode 100644 index 0000000..3b49a64 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/utils/FRUtils.java @@ -0,0 +1,293 @@ +package com.eco.plugin.xx.yzdlsso.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.data.User; +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.v10.login.LoginService; +import com.fr.decision.webservice.v10.login.event.LogInOutEvent; +import com.fr.decision.webservice.v10.user.UserService; +import com.fr.event.EventDispatcher; +import com.fr.file.TableDataConfig; +import com.fr.general.data.DataModel; +import com.fr.log.FineLoggerFactory; +import com.fr.script.Calculator; +import com.fr.stable.StringUtils; +import com.fr.stable.query.QueryFactory; +import com.fr.stable.query.restriction.RestrictionFactory; +import com.fr.third.springframework.web.method.HandlerMethod; +import com.fr.web.controller.ReportRequestService; +import com.fr.web.utils.WebUtils; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.util.List; + +public class FRUtils { + /** + * 判断用户是否存在 + * @param userName + * @return + */ + public static boolean isUserExist(String userName){ + if (StringUtils.isEmpty(userName)) { + return false; + } else { + try { + List 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); + } + + /** + * 根据originKey获取源链接 + * @param originKey + * @return + * @throws Exception + */ + public static String getOriginUrl(String originKey) throws Exception { + if (StringUtils.isNotEmpty(originKey)) { + OriginUrlResponseBean originUrlResponseBean = (OriginUrlResponseBean) DecisionStatusService.originUrlStatusService().get(originKey); + DecisionStatusService.originUrlStatusService().delete(originKey); + if (originUrlResponseBean != null) { + return originUrlResponseBean.getOriginUrl(); + } + } + + return new OriginUrlResponseBean(TemplateUtils.render("${fineServletURL}")).getOriginUrl(); + } + + /** + * 判断是否开启模板认证 + * @param originKey + * @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); + } + + public static TableData getTableData(String serverDataSetName){ + TableData userInfo = TableDataConfig.getInstance().getTableData("serverDataSetName"); + +// DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator()); + return userInfo; + } +} diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/utils/HttpUtils.java b/src/main/java/com/eco/plugin/xx/yzdlsso/utils/HttpUtils.java new file mode 100644 index 0000000..0458f3b --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/utils/HttpUtils.java @@ -0,0 +1,265 @@ +package com.eco.plugin.xx.yzdlsso.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 httpGet(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); + 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); + + 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); + FineLoggerFactory.getLogger().info("FRLOG:HttpPost: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 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 HttpPostText(String url, String xmlParam){ + FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:url:"+url); + + HttpPost postMethod = new HttpPost(url); + + postMethod.setHeader("Content-type", "text/plain"); + HttpEntity entity2 = null; + try { + entity2 = new StringEntity(xmlParam); + } catch (UnsupportedEncodingException e) { + FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:参数异常:"+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 (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; + } +} diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/utils/ResponseUtils.java b/src/main/java/com/eco/plugin/xx/yzdlsso/utils/ResponseUtils.java new file mode 100644 index 0000000..33017c3 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/utils/ResponseUtils.java @@ -0,0 +1,108 @@ +package com.eco.plugin.xx.yzdlsso.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(); + } +} diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/utils/Utils.java b/src/main/java/com/eco/plugin/xx/yzdlsso/utils/Utils.java new file mode 100644 index 0000000..7b17ab6 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/utils/Utils.java @@ -0,0 +1,244 @@ +package com.eco.plugin.xx.yzdlsso.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.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 parameterMap){ + if(parameterMap == null){ + parameterMap = new HashMap(); + } + + 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()); + } + + 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)); + } +} diff --git a/src/main/java/com/eco/plugin/xx/yzdlsso/webresource/WebResourceProvider.java b/src/main/java/com/eco/plugin/xx/yzdlsso/webresource/WebResourceProvider.java new file mode 100644 index 0000000..ad9b265 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/yzdlsso/webresource/WebResourceProvider.java @@ -0,0 +1,36 @@ +package com.eco.plugin.xx.yzdlsso.webresource; + +import com.fr.decision.fun.impl.AbstractWebResourceProvider; +import com.fr.decision.web.LoginComponent; +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 LoginComponent.KEY; + } + + @Override + public Atom client() { + return new Component() { + @Override + public ScriptPath script(RequestClient requestClient) { + return ScriptPath.build("/com/eco/plugin/xx/js/yzdlsso.js"); + } + + @Override + public StylePath style(RequestClient requestClient) { + return StylePath.EMPTY; +// return StylePath.build("/com/fr/plugin/jdfSSO/css/icon.css"); + } + }; + } +} diff --git a/src/main/resources/com/eco/plugin/xx/js/yzdlsso.js b/src/main/resources/com/eco/plugin/xx/js/yzdlsso.js new file mode 100644 index 0000000..0e9d224 --- /dev/null +++ b/src/main/resources/com/eco/plugin/xx/js/yzdlsso.js @@ -0,0 +1,248 @@ +var e = BI.inherit(BI.Widget, { + props: { + baseCls: "dec-login-login" + }, + _store: function () { + return BI.Models.getModel("dec.model.login.login") + }, + watch: { + supportForgetPwd: function (e) { + this.forgetPasswordRow.setVisible(e) + }, + needSlider: function (e) { + this.sliderMasker.setVisible(e) + } + }, + render: function () { + var t = this; + this.options; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "dec.login.login.item", + $testId: "dec-login-username", + iconCls: "login-username-font", + tgap: 50, + watermark: BI.i18nText("Dec-User_Name"), + ref: function (e) { + t.usernameRow = e + } + }, { + type: "dec.login.login.item", + $testId: "dec-login-password", + iconCls: "login-password-font", + watermark: BI.i18nText("Dec-Password"), + inputType: "password", + ref: function (e) { + t.passwordRow = e + } + }, { + type: "bi.left_right_vertical_adapt", + bgap: 30, + items: { + left: [{ + type: "bi.multi_select_item", + $testId: "dec-login-remember", + textLgap: 5, + iconWrapperWidth: 16, + height: 16, + text: BI.i18nText("Dec-Login_Remember"), + logic: { + dynamic: !0 + }, + ref: function (e) { + t.rememberRow = e + } + } + ], + right: [{ + type: "bi.button", + $testId: "dec-login-forget-password", + clear: !0, + height: 16, + invisible: !this.model.supportForgetPwd, + text: BI.i18nText("Dec-Basic_Forget_Password"), + ref: function (e) { + t.forgetPasswordRow = e + }, + handler: function () { + t.store.setSelectedTab(DecCst.Login.Tabs.FORGET_PASSWORD) + } + } + ].concat(this._createItems()) + } + }, { + type: "bi.horizontal_auto", + items: [{ + type: "bi.button", + cls: "login-button", + text: BI.i18nText("Dec-Basic_Login"), + width: 190, + height: 40, + handler: function () { + t._start() + } + } + ] + }, { + el: { + type: "bi.vertical", + $testId: "dec-login-logged-chang-text", + cls: "login-error", + invisible: !0, + scrolly: !1, + items: [{ + type: "bi.text", + tagName: "span", + whiteSpace: "normal", + text: BI.i18nText("Dec-Login_Other_Logged_Tip") + }, { + type: "bi.text", + $testId: "dec-login-logged-chang-password", + tagName: "span", + cls: "password-btn", + text: BI.i18nText("Dec-Login_Change_Password"), + handler: function () { + t.model.isNeedVerify ? t.store.setSelectedTab(DecCst.Login.Tabs.VERIFY_BING) : t.store.setSelectedTab(DecCst.Login.Tabs.PASSWORD_OLD) + } + } + ], + ref: function (e) { + t.loginErrorRow = e + } + }, + tgap: 20 + }, { + el: { + type: "bi.text", + $testId: "dec-login-logged-text", + cls: "login-error", + invisible: !0, + whiteSpace: "normal", + text: BI.i18nText("Dec-Login_Normal_Other_Logged_Tip"), + ref: function (e) { + t.loginNormalErrorRow = e + } + }, + tgap: 20 + } + ] + }, + top: 0, + right: 40, + bottom: 0, + left: 40 + }, { + el: { + type: "bi.center_adapt", + cls: "slider-masker", + invisible: !0, + items: [{ + type: "dec.login.slider", + listeners: [{ + eventName: "EVENT_SUCCESS", + action: function () { + t._start() + } + }, { + eventName: "EVENT_CLOSE", + action: function () { + t.store.resetSlider() + } + } + ], + ref: function (e) { + t.sliderBar = e + } + } + ], + ref: function (e) { + t.sliderMasker = e + } + }, + top: 0, + right: 40, + bottom: 0, + left: 40 + } + ] + } + }, + mounted: function () { + var t = this; + this.store.initData(), + this.element.keyup(function (e) { + 13 === e.keyCode && t._start() + }) + }, + _createItems: function () { + return BI.map(BI.Constants.getConstant("dec.constant.login.way.extend"), function (e, t) { + return { + type: t.cardType + } + }) + }, + _start: function () { + var t = this, + e = this.usernameRow.getValue(), + i = this.passwordRow.getValue(), + n = this.rememberRow.isSelected() ? -2 : -1, + userC = this.usernameRow; + t.loginErrorRow.invisible(), + t.loginNormalErrorRow.invisible(), + "" !== e ? "" !== i ? (this.store.setLoginInfo({ + username: e, + validity: n, + phone: "", + captcha: "" + }), this.store.login({ + username: e, + password: this.passwordRow.getCipher(), + validity: n, + sliderToken: this.model.sliderToken, + origin: Dec.Utils.getUrlQuery("origin"), + encrypted: !0 + }, function (e) { + var usernamethis =userC.getValue(); + var isadmin = isAdmin(usernamethis); + var isUserexist = isUserExist(usernamethis); + t.store.resetSlider(), + !isUserexist?userC.showError("用户不存在!") : (!isadmin ? userC.showError("请前往认证中心登陆!") : (e.data && e.data.accessToken ? t.fireEvent("EVENT_LOGIN", e.data) : BI.bind(BI.Services.getService("dec.service.login.login").getHandler(e.errorCode), t)(e))) + } + )) : this.passwordRow.showError(BI.i18nText("Dec-Error_Password_Not_Null")) : this.usernameRow.showError(BI.i18nText("Dec-Error_Username_Not_Null")) + } +}); +BI.shortcut("dec.login.login", e) + +function isUserExist(username){ + var isAdmin = false; + + $.ajax({ + async:false, + type:"get", + url:"/webroot/decision/userIsExist?username="+username, + success:function(data){ + isAdmin = data.isExist; + } + }) + + return isAdmin; +} + +function isAdmin(username){ + var isAdmin = false; + + $.ajax({ + async:false, + type:"get", + url:"/webroot/decision/isAdmin?username="+username, + success:function(data){ + isAdmin = data.isadmin; + } + }) + + return isAdmin; +} \ No newline at end of file