Browse Source

提交开源任务材料

10.0
LAPTOP-SB56SG4Q\86185 3 years ago
parent
commit
1daa33633c
  1. BIN
      JSD-8975-需求确认书V.docx
  2. 5
      README.md
  3. BIN
      lib/aws-api-client.jar
  4. BIN
      lib/commons-codec-1.15.jar
  5. 26
      plugin.xml
  6. 25
      src/main/java/com/fr/plugin/bsSSO/bean/simple/DemoInitializeMonitor.java
  7. 24
      src/main/java/com/fr/plugin/bsSSO/bean/simple/PluginInitializeFilterBridge.java
  8. 10
      src/main/java/com/fr/plugin/bsSSO/bean/simple/PluginLocaleFinderBridge.java
  9. 140
      src/main/java/com/fr/plugin/bsSSO/bean/simple/account/PluginSimpleConfig.java
  10. 57
      src/main/java/com/fr/plugin/bsSSO/filter/LoginFilter.java
  11. 13
      src/main/java/com/fr/plugin/bsSSO/handler/ExtendAttrHandlerProvider.java
  12. 146
      src/main/java/com/fr/plugin/bsSSO/handler/MobileLogin.java
  13. 121
      src/main/java/com/fr/plugin/bsSSO/handler/PCLogin.java
  14. 48
      src/main/java/com/fr/plugin/bsSSO/handler/PCLogin2.java
  15. 16
      src/main/java/com/fr/plugin/bsSSO/handler/URLAliasProvide.java
  16. 244
      src/main/java/com/fr/plugin/bsSSO/utils/FRUtils.java
  17. 208
      src/main/java/com/fr/plugin/bsSSO/utils/HttpUtils.java
  18. 44
      src/main/java/com/fr/plugin/bsSSO/utils/OpenapiUtil.java
  19. 60
      src/main/java/com/fr/plugin/bsSSO/utils/ResponseUtils.java
  20. 42
      src/main/java/com/fr/plugin/bsSSO/utils/Utils.java
  21. 92
      src/main/resources/com/fr/plugin/bsSSO/html/error.html

BIN
JSD-8975-需求确认书V.docx

Binary file not shown.

5
README.md

@ -1,3 +1,6 @@
# open-JSD-8975
JSD-8975 单点(PC+移动端区分)
JSD-8975 单点(PC+移动端区分)\
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
仅作为开发者学习参考使用!禁止用于任何商业用途!\
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。

BIN
lib/aws-api-client.jar

Binary file not shown.

BIN
lib/commons-codec-1.15.jar

Binary file not shown.

26
plugin.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.bsSSO</id>
<name><![CDATA[单点登录]]></name>
<active>yes</active>
<version>1.0.22</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.fr.plugin.bsSSO</main-package>
<extra-core>
<LocaleFinder class="com.fr.plugin.bsSSO.bean.simple.PluginLocaleFinderBridge"/>
</extra-core>
<lifecycle-monitor class="com.fr.plugin.bsSSO.bean.simple.DemoInitializeMonitor"/>
<extra-decision>
<EmbedRequestFilterProvider class="com.fr.plugin.bsSSO.filter.LoginFilter"/>
<HttpHandlerProvider class="com.fr.plugin.bsSSO.handler.ExtendAttrHandlerProvider"/>
<URLAliasProvider class="com.fr.plugin.bsSSO.handler.URLAliasProvide"/>
</extra-decision>
<function-recorder class="com.fr.plugin.bsSSO.bean.simple.account.PluginSimpleConfig"/>
</plugin>

25
src/main/java/com/fr/plugin/bsSSO/bean/simple/DemoInitializeMonitor.java

@ -0,0 +1,25 @@
package com.fr.plugin.bsSSO.bean.simple;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.plugin.bsSSO.bean.simple.account.PluginSimpleConfig;
/**
* @author fr.open
* @version 10.0
* Created by fr.open on 2018-12-04
*/
public class DemoInitializeMonitor extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
PluginSimpleConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

24
src/main/java/com/fr/plugin/bsSSO/bean/simple/PluginInitializeFilterBridge.java

@ -0,0 +1,24 @@
package com.fr.plugin.bsSSO.bean.simple;
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider;
import com.fr.plugin.bsSSO.bean.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 {
}
}

10
src/main/java/com/fr/plugin/bsSSO/bean/simple/PluginLocaleFinderBridge.java

@ -0,0 +1,10 @@
package com.fr.plugin.bsSSO.bean.simple;
import com.fr.stable.fun.impl.AbstractLocaleFinder;
public class PluginLocaleFinderBridge extends AbstractLocaleFinder {
@Override
public String find() {
return "conf";
}
}

140
src/main/java/com/fr/plugin/bsSSO/bean/simple/account/PluginSimpleConfig.java

@ -0,0 +1,140 @@
package com.fr.plugin.bsSSO.bean.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 = "Plugin-Config_Group")
@EnableMetrics
public class PluginSimpleConfig extends DefaultConfiguration {
private static volatile PluginSimpleConfig config = null;
@Focus(id="com.fr.plugin.bsSSO.bean.simple", text = "Plugin-Config_Demo", source = Original.PLUGIN)
public static PluginSimpleConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class);
}
return config;
}
@Identifier(value = "awsServer", name = "认证中心地址", description = "认证中心地址", status = Status.SHOW)
private Conf<String> awsServer = Holders.simple("https://xxx");
@Identifier(value = "accessKey", name = "认证中心秘钥", description = "认证中心秘钥", status = Status.SHOW)
private Conf<String> accessKey = Holders.simple("");
@Identifier(value = "index", name = "帆软首页", description = "帆软首页", status = Status.SHOW)
private Conf<String> index = Holders.simple("http://localhost:8075/webroot/decision");
@Identifier(value = "mindex", name = "帆软移动端首页", description = "帆软移动端首页", status = Status.SHOW)
private Conf<String> mindex = Holders.simple("http://localhost:8075/webroot/decision/url/mobile");
@Identifier(value = "mtoken", name = "移动端获取用户id接口地址", description = "移动端获取用户id接口地址", status = Status.SHOW)
private Conf<String> mtoken = Holders.simple("https://xxxx");
@Identifier(value = "muser", name = "移动端获取用户信息接口地址", description = "移动端获取用户信息接口地址", status = Status.SHOW)
private Conf<String> muser = Holders.simple("https://xxxx");
@Identifier(value = "mdomain", name = "移动端接口域名", description = "移动端接口域名", status = Status.SHOW)
private Conf<String> mdomain = Holders.simple("xxxx");
@Identifier(value = "puser", name = "PC端获取用户信息接口地址", description = "PC端获取用户信息接口地址", status = Status.SHOW)
private Conf<String> puser = Holders.simple("http://xxxx");
@Identifier(value = "pkey", name = "PC端accessKey", description = "pc用", status = Status.SHOW)
private Conf<String> pkey = Holders.simple("xxxx");
@Identifier(value = "psecret", name = "PC端secret", description = "pc用", status = Status.SHOW)
private Conf<String> psecret = Holders.simple("xxxx");
public String getAwsServer() {
return awsServer.get();
}
public void setAwsServer(String url) {
this.awsServer.set(url);
}
public String getAccessKey() {
return accessKey.get();
}
public void setAccessKey(String url) {
this.accessKey.set(url);
}
public String getIndex() {
return index.get();
}
public void setIndex(String url) {
this.index.set(url);
}
public String getMindex() {
return mindex.get();
}
public void setMindex(String url) {
this.mindex.set(url);
}
public String getMtoken() {
return mtoken.get();
}
public void setMtoken(String url) {
this.mtoken.set(url);
}
public String getMuser() {
return muser.get();
}
public void setMuser(String url) {
this.muser.set(url);
}
public String getPuser() {
return puser.get();
}
public void setPuser(String url) {
this.puser.set(url);
}
public String getPkey() {
return pkey.get();
}
public void setPkey(String url) {
this.pkey.set(url);
}
public String getPsecret() {
return psecret.get();
}
public void setPsecret(String url) {
this.psecret.set(url);
}
public String getMdomain() {
return mdomain.get();
}
public void setMdomain(String url) {
this.mdomain.set(url);
}
@Override
public Object clone() throws CloneNotSupportedException {
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone();
return cloned;
}
}

57
src/main/java/com/fr/plugin/bsSSO/filter/LoginFilter.java

@ -0,0 +1,57 @@
package com.fr.plugin.bsSSO.filter;
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider;
import com.fr.json.JSONObject;
import com.fr.plugin.bsSSO.bean.simple.account.PluginSimpleConfig;
import com.fr.plugin.bsSSO.utils.FRUtils;
import com.fr.plugin.bsSSO.utils.HttpUtils;
import com.fr.plugin.bsSSO.utils.Utils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class LoginFilter extends AbstractEmbedRequestFilterProvider {
private static String awsServer = ""; //认证中心url
private static String accessKey = ""; //认证中心秘钥
static
{
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
awsServer = psc.getAwsServer();
accessKey = psc.getAccessKey();
}
@Override
public void filter(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
String tokenId = httpServletRequest.getParameter("tokenId");
if(!Utils.isNullStr(tokenId)){
FRUtils.FRLogInfo("SSO:tokenId:"+tokenId);
String tokenUrl = awsServer+"/r/jd?cmd=com.actionsoft.apps.addons.sso_validate&tokenId="+tokenId+"&access_key="+accessKey;
FRUtils.FRLogInfo("SSO:tokenUrl:"+tokenUrl);
String result = HttpUtils.HttpPost(tokenUrl);
if(!Utils.isNullStr(result)){
JSONObject jsonObject = new JSONObject(result);
JSONObject data = jsonObject.getJSONObject("data");
boolean validate = data.getBoolean("validate");
if(validate){
String uid = data.getString("uid");
FRUtils.FRLogInfo("SSO:uid:"+uid);
FRUtils.Login(httpServletRequest,httpServletResponse,uid,"");
return;
}
}
}
}
}

13
src/main/java/com/fr/plugin/bsSSO/handler/ExtendAttrHandlerProvider.java

@ -0,0 +1,13 @@
package com.fr.plugin.bsSSO.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 MobileLogin(),new PCLogin(),new PCLogin2()
};
}
}

146
src/main/java/com/fr/plugin/bsSSO/handler/MobileLogin.java

@ -0,0 +1,146 @@
package com.fr.plugin.bsSSO.handler;
import com.fr.base.TemplateUtils;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONObject;
import com.fr.plugin.bsSSO.bean.simple.account.PluginSimpleConfig;
import com.fr.plugin.bsSSO.utils.FRUtils;
import com.fr.plugin.bsSSO.utils.HttpUtils;
import com.fr.plugin.bsSSO.utils.ResponseUtils;
import com.fr.plugin.bsSSO.utils.Utils;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.HttpResponse;
import com.fr.third.org.apache.http.client.HttpClient;
import com.fr.third.org.apache.http.client.methods.HttpGet;
import com.fr.third.org.apache.http.impl.client.BasicCookieStore;
import com.fr.third.org.apache.http.impl.client.HttpClientBuilder;
import com.fr.third.org.apache.http.impl.cookie.BasicClientCookie;
import com.fr.third.org.apache.http.util.EntityUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class MobileLogin extends BaseHttpHandler {
public MobileLogin() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/mobilelogin";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
//获取请求参数
String token = req.getParameter("token");
//生成cookie
BasicClientCookie cookie = new BasicClientCookie("access_token", token);
cookie.setDomain(psc.getMdomain());
cookie.setPath("/");
//获取用户id
String userid = getUserid(cookie,psc);
//获取用户名
String username = getUsername(cookie,userid,psc);
if(!FRUtils.isUserExist(username)){
String tip ="数据平台不存在该账号:"+username;
Map<String, String> parameterMap = new HashMap<String, String>();
String path = "/com/fr/plugin/bsSSO/html/error.html";
parameterMap.put("tip", tip);
String macPage = TemplateUtils.renderTemplate(path, parameterMap);
WebUtils.printAsString(res, macPage);
return ;
}
FRUtils.Login(req,res,username,PluginSimpleConfig.getInstance().getMindex());
// try {
// FRUtils.Login2(req,res,username,PluginSimpleConfig.getInstance().getMindex());
// } catch (Exception e) {
//// res.sendRedirect(PluginSimpleConfig.getInstance().getMindex());
// }
}
private String getUsername(BasicClientCookie cookies, String userid, PluginSimpleConfig psc) {
String url = psc.getMuser();
url += userid;
String result = get(cookies,url);
if(Utils.isNullStr(result)){
return "";
}
JSONObject resultJson = new JSONObject(result);
int status = resultJson.getInt("status");
if(status != 200){
return "";
}
return resultJson.getJSONObject("content").getString("login");
}
//获取用户id
private String getUserid(BasicClientCookie cookies,PluginSimpleConfig psc) {
String url = psc.getMtoken();
String result = get(cookies,url);
if(Utils.isNullStr(result)){
return "";
}
JSONObject resultJson = new JSONObject(result);
int status = resultJson.getInt("status");
if(status != 200){
return "";
}
return resultJson.getString("content");
}
private String get(BasicClientCookie cookie,String url) {
BasicCookieStore cookieStore = new BasicCookieStore();
cookieStore.addCookie(cookie);
HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
final HttpGet request = new HttpGet(url);
String returnResult = "";
try{
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
returnResult = EntityUtils.toString(entity, "utf-8");
}catch(Exception e){
FRUtils.FRLogInfo("get exception " + e.getMessage());
}
return returnResult;
}
}

121
src/main/java/com/fr/plugin/bsSSO/handler/PCLogin.java

@ -0,0 +1,121 @@
package com.fr.plugin.bsSSO.handler;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONObject;
import com.fr.plugin.bsSSO.bean.simple.account.PluginSimpleConfig;
import com.fr.plugin.bsSSO.utils.*;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PCLogin extends BaseHttpHandler {
public PCLogin() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/openapi";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res){
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
String access_key = req.getParameter("access_key");
FRUtils.FRLogInfo("pc access_key " + access_key);
if(Utils.isNullStr(access_key) || !psc.getPkey().equals(access_key)){
FRUtils.FRLogInfo("access_key 无效");
ResponseUtils.response(res,"access_key 无效","-1","","error");
return ;
}
String sig = req.getParameter("sig");
FRUtils.FRLogInfo("query sig "+sig);
String allUrl = FRUtils.getAllUrl(req);
FRUtils.FRLogInfo("allUrl: "+allUrl);
String queryStr = allUrl.split("\\?")[1];
String validateSign = OpenapiUtil.generateSign(queryStr,psc.getPsecret());
FRUtils.FRLogInfo("validateSign "+sig);
if(!sig.equals(validateSign)){
FRUtils.FRLogInfo("验签失败");
ResponseUtils.response(res,"验签失败","-1","","error");
return ;
}
//获取请求参数
String token = req.getParameter("token");
//获取用户名
String username = getUsername(token);
// String username = "xiamaofa";
if(Utils.isNullStr(username)){
FRUtils.FRLogInfo("获取用户信息失败");
ResponseUtils.response(res,"获取用户信息失败","-1","","error");
return ;
}
if(!FRUtils.isUserExist(username)){
FRUtils.FRLogInfo("数据平台不存在该账号:"+username);
ResponseUtils.response(res,"数据平台不存在该账号:"+username,"-1","","error");
return ;
}
String frtoken = FRUtils.getToken(req,res,username);
if(Utils.isNullStr(frtoken)){
FRUtils.FRLogInfo("生成token失败:");
ResponseUtils.response(res,"生成token失败","-1","","error");
return ;
}
String url = psc.getIndex()+"/url/pclogin?token="+frtoken;
ResponseUtils.response(res,"","200",url,"ok");
}
private String getUsername(String token) {
String url = PluginSimpleConfig.getInstance().getPuser();
url += "?token="+token;
String result = HttpUtils.get(url,null,null);
if(Utils.isNullStr(result)){
return "";
}
JSONObject resultJson = new JSONObject(result);
String status = resultJson.getString("Status");
if(!status.equals("S")){
return "";
}
return resultJson.getString("LoginId");
}
}

48
src/main/java/com/fr/plugin/bsSSO/handler/PCLogin2.java

@ -0,0 +1,48 @@
package com.fr.plugin.bsSSO.handler;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONObject;
import com.fr.plugin.bsSSO.bean.simple.account.PluginSimpleConfig;
import com.fr.plugin.bsSSO.utils.*;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PCLogin2 extends BaseHttpHandler {
public PCLogin2() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/pclogin";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res){
String token = req.getParameter("token");
if(Utils.isNullStr(token)){
ResponseUtils.response(res,"token不能为空","error","","");
return ;
}
FRUtils.loginByToken(req,res,token,PluginSimpleConfig.getInstance().getIndex());
}
}

16
src/main/java/com/fr/plugin/bsSSO/handler/URLAliasProvide.java

@ -0,0 +1,16 @@
package com.fr.plugin.bsSSO.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("/openapi","/openapi",true),
URLAliasFactory.createPluginAlias("/pclogin","/pclogin",true),
URLAliasFactory.createPluginAlias("/mobilelogin","/mobilelogin",true),
};
}
}

244
src/main/java/com/fr/plugin/bsSSO/utils/FRUtils.java

@ -0,0 +1,244 @@
package com.fr.plugin.bsSSO.utils;
import com.fr.base.ServerConfig;
import com.fr.decision.authority.AuthorityContext;
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.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.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 {
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
* @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;
}
/**
* 获取带参数的访问链接
* @return
*/
public static String getAllUrl(HttpServletRequest httpServletRequest){
return WebUtils.getOriginalURL(httpServletRequest);
}
/**
* 判断用户是否存在
* @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 userName
* @param url
*/
public static void Login2(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String userName,String url) throws Exception {
FineLoggerFactory.getLogger().info("FRLOG:用户名:"+userName);
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url);
//判断用户名是否为空
if(!Utils.isNullStr(userName)){
if(isUserExist(userName)){
String FRToken = "";
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);
}
}else{
throw new RuntimeException();
}
}else{
throw new RuntimeException();
}
}
/**
*
* @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);
}
}

208
src/main/java/com/fr/plugin/bsSSO/utils/HttpUtils.java

@ -0,0 +1,208 @@
package com.fr.plugin.bsSSO.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.client.CookieStore;
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.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.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Map;
import java.util.Set;
public class HttpUtils {
/**
* 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;
}
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;
}
/**
* 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 "";
}
/**
* httpGet请求
* @param url
* @return
*/
public static String get(String url){
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url);
HttpGet getMethod = new HttpGet(url);
CloseableHttpClient httpclient = HttpClients.createDefault();
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 url
* @return
*/
public static String HttpPost(String url){
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:url:"+url);
HttpPost postMethod = new HttpPost(url);
CloseableHttpClient httpclient = HttpClients.createDefault();
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);
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
postMethod.setHeader("Content-type", "text/html");
HttpEntity entity2 = new StringEntity(xmlParam);
postMethod.setEntity(entity2);
HttpResponse response = httpclient.execute(postMethod);
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML: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:HttpPostXML:returnResult:"+returnResult);
return returnResult;
}
} catch (Exception e) {
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:exception:"+e.getMessage());
}
return "";
}
}

44
src/main/java/com/fr/plugin/bsSSO/utils/OpenapiUtil.java

@ -0,0 +1,44 @@
package com.fr.plugin.bsSSO.utils;
import com.actionsoft.bpms.api.common.ApiUtils;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class OpenapiUtil {
/**
* 生成签名
* @param queryStr
* @param secret
* @return
*/
public static String generateSign(String queryStr,String secret){
Map<String, String> param = getParam(queryStr);
return ApiUtils.makeSig(param, secret, (Collection)Collections.EMPTY_LIST);
}
private static Map<String, String> getParam(String url){
Map<String, String> param = new HashMap<String, String>();
String[] oneSplit = url.split("&");
for(int i = 0;i<oneSplit.length;i++){
String[] kv = oneSplit[i].split("=");
String k = kv[0];
if(k.equals("sig")){
continue;
}
String val = kv.length == 1 ? "" :kv[1];
param.put(kv[0],val);
}
return param;
}
}

60
src/main/java/com/fr/plugin/bsSSO/utils/ResponseUtils.java

@ -0,0 +1,60 @@
package com.fr.plugin.bsSSO.utils;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.web.utils.WebUtils;
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, String msg, String code,String data,String result2) {
JSONObject object = new JSONObject();
PrintWriter pw;
try {
object.put("status", code);
object.put("msg", msg);
object.put("data", data);
object.put("result", result2);
FRUtils.FRLogInfo("result " + object.toString());
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();
}
}

42
src/main/java/com/fr/plugin/bsSSO/utils/Utils.java

@ -0,0 +1,42 @@
package com.fr.plugin.bsSSO.utils;
import com.fr.third.org.apache.commons.codec.digest.DigestUtils;
import javax.servlet.http.HttpServletRequest;
public class Utils {
/**
* 判断字符串是否为空
* @param str
* @return true 空字符串 false 非空字符串
*/
public static boolean isNullStr(String str){
return !(str != null && !str.isEmpty() && !"null".equals(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;
}
}

92
src/main/resources/com/fr/plugin/bsSSO/html/error.html

@ -0,0 +1,92 @@
<html><head>
<meta charset="utf-8">
<title></title>
<style>
body {
background-color: #ffffff;
}
.main {
position: absolute;
top: 25%;
left: 10%;
right: 10%;
margin: auto;
}
.main div {
text-align: center;
}
#header-content {
min-width: 40%;
min-height: 40%;
max-width: 100%;
max-height: 100%;
}
.simple-message {
font-weight: 500;
width: 100%;
font-size: 28px;
color: #3685f2;
text-align: center;
margin-top: 20px;
line-height: 40px;
}
.detail-message {
font-size: 16px;
color: #ff4949;
margin: 15px auto;
line-height: 24px;
}
.solution {
font-size: 16px;
color: #ff4949;
line-height: 24px;
}
.login {
color: #3685f2;
text-decoration: none;
line-height: 24px;
float: right;
height: 24px;
font-size: 12px;
margin-right: 40px;
margin-top: 40px;
}
</style>
<script type="text/javascript" src="/webroot/decision/file?path=com.fr.decision.web.i18n.NormalTextGenerator&amp;type=class&amp;parser=plain"></script>
</head>
<body>
<div class="main" id="12aaed1d-7cb5-488f-91bb-dba35342c9d2">
<div style="font-size:20px;">
<div style="border:1px solid red;padding:5px">数据平台无相关账号</div>
</div>
</div>
<script>
function getI18n(key) {
var value;
try {
value = (I18n && I18n[key]);
} catch (e) {
value = (FR && FR.i18nText(key))
}
return !value ? key : value;
}
var id = "12aaed1d-7cb5-488f-91bb-dba35342c9d2";
var simple = document.getElementById(id).children[1];
var detail = document.getElementById(id).children[2];
var solution = document.getElementById(id).children[3];;
simple.innerText = getI18n(simple.innerText);
detail.innerText = getI18n(detail.innerText);
solution.innerText = getI18n(solution.innerText);
</script>
</body></html>
Loading…
Cancel
Save