Browse Source

OPEN

master
pioneer 2 years ago
parent
commit
66a66a8442
  1. 7
      src/main/java/com/fr/plugin/third/party/jsdidig/Utils.java
  2. 10
      src/main/java/com/fr/plugin/third/party/jsdidig/config/CustomDataConfig.java
  3. 2
      src/main/java/com/fr/plugin/third/party/jsdidig/http/CustomConfigHttpHandler.java
  4. 61
      src/main/java/com/fr/plugin/third/party/jsdidig/http/SessionGlobalRequestFilterProvider.java

7
src/main/java/com/fr/plugin/third/party/jsdidig/Utils.java

@ -182,15 +182,14 @@ public class Utils {
}
public static String getOAuthCodeUrl(String url) throws UnsupportedEncodingException {
//http://ssotestnew.logan.com.cn:28080/siam/oauth2.0/authorize?client_id=oauthdemo&redirect_uri=http://application.com:9700/oauthdemo&response_type=code
//String mappingUrl = CustomDataConfig.getInstance().getFrUrl() + "?url_id=" + state;
String tempUrl = UriUtils.encodeQueryParam(url, "UTF-8");
LogKit.info("龙光IDM集成登录,授权报表地址:" + url);
LogKit.info("集成登录,授权报表地址:" + url);
//if (tempUrl.indexOf("?") >= 0) {
// tempUrl = UriUtils.encodeQueryParam(tempUrl, "UTF-8");
//}
String authUrl = CustomDataConfig.getInstance().getoAuthCodeUrl() + "?client_id=" + CustomDataConfig.getInstance().getIdmClientId() + "&redirect_uri=" + tempUrl + "&response_type=code";
LogKit.info("龙光IDM集成登录,获取临时授权码地址:" + authUrl);
LogKit.info("集成登录,获取临时授权码地址:" + authUrl);
return authUrl;
}

10
src/main/java/com/fr/plugin/third/party/jsdidig/config/CustomDataConfig.java

@ -9,7 +9,7 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* 配置数据保存
*/
@Visualization(category = "龙光IDM集成登录配置")
@Visualization(category = "集成登录配置")
public class CustomDataConfig extends DefaultConfiguration {
public String getNameSpace() {
return this.getClass().getName();
@ -58,15 +58,15 @@ public class CustomDataConfig extends DefaultConfiguration {
@Identifier(value = "oAuthCodeUrl", name = "获取临时令牌接口地址", description = "", status = Status.SHOW)
private Conf<String> oAuthCodeUrl = Holders.simple("http://ssotestnew.logan.com.cn:28080/siam/oauth2.0/authorize");
private Conf<String> oAuthCodeUrl = Holders.simple("http:///xxx/oauth2.0/authorize");
@Identifier(value = "accessTokenUrl", name = "获取Access Token地址(json)", description = "", status = Status.SHOW)
private Conf<String> accessTokenUrl = Holders.simple("http://ssotestnew.logan.com.cn:28080/siam/oauth2.0/accessTokenByJson");
private Conf<String> accessTokenUrl = Holders.simple("http://xxx/siam/oauth2.0/accessTokenByJson");
@Identifier(value = "userUrl", name = "获取用户信息地址(json)", description = "", status = Status.SHOW)
private Conf<String> userUrl = Holders.simple("http://ssotestnew.logan.com.cn:28080/siam/oauth2.0/profileByJson");
private Conf<String> userUrl = Holders.simple("http://xxx/siam/oauth2.0/profileByJson");
@Identifier(value = "userSyncUrl", name = "用户同步的地址", description = "", status = Status.SHOW)
@ -79,7 +79,7 @@ public class CustomDataConfig extends DefaultConfiguration {
private Conf<String> userSyncPassword = Holders.simple("");
@Identifier(value = "logoutUrl", name = "退出登录地址", description = "", status = Status.SHOW)
private Conf<String> logoutUrl = Holders.simple("http://siam.logan.com.cn/siam/logout");
private Conf<String> logoutUrl = Holders.simple("http://xxx/siam/logout");
@Identifier(value = "loginTypeNameParameter", name = "登录类型参数名称", description = "", status = Status.HIDE)

2
src/main/java/com/fr/plugin/third/party/jsdidig/http/CustomConfigHttpHandler.java

@ -36,7 +36,7 @@ public class CustomConfigHttpHandler extends BaseHttpHandler {
res.setContentType("application/json; charset=utf-8");
String logoutUrl = Utils.getLogoutUrl();
String oAuthLoginUrl = Utils.getOAuthCodeUrlWithFr();;
LogKit.info("龙光IDM集成登录,退出认证登录地址:" + logoutUrl);
LogKit.info("集成登录,退出认证登录地址:" + logoutUrl);
JSONObject json = new JSONObject();
json.put("logoutUrl",logoutUrl);
json.put("oAuthLoginUrl",oAuthLoginUrl);

61
src/main/java/com/fr/plugin/third/party/jsdidig/http/SessionGlobalRequestFilterProvider.java

@ -55,7 +55,7 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) {
try {
if (!PluginContexts.currentContext().isAvailable()) {
LogKit.info("龙光IDM集成登录,许可证过期");
LogKit.info("集成登录,许可证过期");
filterChain.doFilter(req, res);
return;
}
@ -63,7 +63,7 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
String reqUrl = req.getRequestURL().toString();
String fullUrl = Utils.getFullRequestUrl(req);
String method = req.getMethod();
LogKit.info("龙光IDM集成登录,记录访问地址:" + method + " " + fullUrl);
LogKit.info("集成登录,记录访问地址:" + method + " " + fullUrl);
if (!"GET".equalsIgnoreCase(method)) {
filterChain.doFilter(req, res);
@ -94,7 +94,7 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
if (isAllowIdmOAuthLogin(req)) {
String requestUrl = getRequestUrl(req);
requestUrl = replaceUrl(requestUrl);
LogKit.info("龙光IDM集成登录,真实访问地址," + requestUrl);
LogKit.info("集成登录,真实访问地址," + requestUrl);
//CustomDataConfig.addUrl(state, requestUrl);
String locationUrl = Utils.getOAuthCodeUrl(requestUrl);
Utils.sendRedirect(res, locationUrl);
@ -107,17 +107,17 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
return;
}
LogKit.info("龙光IDM集成登录, OAuth 用户名:" + loginUsername);
LogKit.info("集成登录, OAuth 用户名:" + loginUsername);
User user = UserService.getInstance().getUserByUserName(loginUsername);
boolean tipsOption = false;
String tipsContent = "";
if (user == null) {
tipsOption = true;
LogKit.info("龙光IDM集成登录,用户名:" + loginUsername + "在报表平台不存在");
LogKit.info("集成登录,用户名:" + loginUsername + "在报表平台不存在");
tipsContent = "在报表服务器上不存在";
} else if (!user.isEnable()) {
tipsOption = true;
LogKit.info("龙光IDM集成登录,用户名:" + loginUsername + "在报表平台上被禁用");
LogKit.info("集成登录,用户名:" + loginUsername + "在报表平台上被禁用");
tipsContent = "在报表平台上被禁用";
}
@ -146,9 +146,9 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
}
//loginUsername = user.getUserName();
//LogKit.info("龙光IDM集成登录,报表平台用户名:" + loginUsername);
//LogKit.info("集成登录,报表平台用户名:" + loginUsername);
LogKit.info("龙光IDM集成登录,报表平台用户名:" + loginUsername + "生成 login token");
LogKit.info("集成登录,报表平台用户名:" + loginUsername + "生成 login token");
String loginToken = LoginService.getInstance().login(req, res, loginUsername);
req.setAttribute("fine_auth_token", loginToken);
@ -160,13 +160,13 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
if (fullUrl.indexOf("code=") >= 0) {
String requestUrl = getRequestUrl(req);
requestUrl = replaceUrl(requestUrl);
LogKit.info("龙光IDM集成登录,真实跳转地址:" + requestUrl);
LogKit.info("集成登录,真实跳转地址:" + requestUrl);
Utils.sendRedirect(res, requestUrl);
return;
}
filterChain.doFilter(req, res);
} catch (Exception e) {
LogKit.error("龙光IDM集成登录出错," + e.getMessage(), e);
LogKit.error("集成登录出错," + e.getMessage(), e);
}
}
@ -295,19 +295,16 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
if (StringKit.isEmpty(oAuthCode)) {
return "";
}
LogKit.info("龙光IDM集成登录,code:" + oAuthCode);
LogKit.info("集成登录,code:" + oAuthCode);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(10000)
.setSocketTimeout(10000) // 服务端相应超时
.setConnectTimeout(10000) // 建立socket链接超时时间
.build();
//获取Access Token
//环境地址/getTokens
//http://ssotestnew.logan.com.cn:28080/siam/oauth2.0/accessTokenByJson
//"client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=GRANTTYPE&code=CODE&redirect_uri=REDIRECTURL";
String accessTokenUrl = CustomDataConfig.getInstance().getAccessTokenUrl();
LogKit.info("龙光IDM集成登录,获取access_toke url:" + accessTokenUrl);
LogKit.info("集成登录,获取access_toke url:" + accessTokenUrl);
HttpPost httpPost = new HttpPost(accessTokenUrl);
httpPost.addHeader("User-Agent", DEFAULT_USER_AGENT);
@ -332,7 +329,7 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
if (statusCode != HttpStatus.SC_OK) {
response.close();
httpClient.close();
LogKit.info("龙光IDM集成登录,获取Access Token请求出错,http status:" + statusCode);
LogKit.info("集成登录,获取Access Token请求出错,http status:" + statusCode);
return "";
}
@ -340,30 +337,30 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
if (httpEntity == null) {
response.close();
httpClient.close();
LogKit.info("龙光IDM集成登录,获取Access Token请求出错,http响应内容为空");
LogKit.info("集成登录,获取Access Token请求出错,http响应内容为空");
return "";
}
String responseContent = EntityUtils.toString(httpEntity, "UTF-8");
response.close();
if (StringKit.isEmpty(responseContent)) {
httpClient.close();
LogKit.info("龙光IDM集成登录,获取Access Token请求出错,http响应内容为空1");
LogKit.info("集成登录,获取Access Token请求出错,http响应内容为空1");
return "";
}
LogKit.info("龙光IDM集成登录,获取Access Token请求,http响应内容\n" + responseContent);
LogKit.info("集成登录,获取Access Token请求,http响应内容\n" + responseContent);
String accessToken = getAccessToken(responseContent);
if (StringKit.isEmpty(accessToken)) {
httpClient.close();
LogKit.info("龙光IDM集成登录,获取Access Token请求出错,access_token为空");
LogKit.info("集成登录,获取Access Token请求出错,access_token为空");
return "";
}
LogKit.info("龙光IDM集成登录,Access Token:" + accessToken);
LogKit.info("集成登录,Access Token:" + accessToken);
//http://192.168.0.115:8080/sso/oauth2.0/profile?access_token=TGT-2-QQbe3iHQJeXYx13daRnKRxMYh4HucodEmFlxwiSCpua2hMSxXB-c01
String userUrl = CustomDataConfig.getInstance().getUserUrl();
LogKit.info("龙光IDM集成登录,获取用户信息Url:" + userUrl);
LogKit.info("集成登录,获取用户信息Url:" + userUrl);
httpPost = new HttpPost(userUrl);
httpPost.setConfig(requestConfig);
httpPost.addHeader("User-Agent", DEFAULT_USER_AGENT);
@ -378,7 +375,7 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
if (statusCode != HttpStatus.SC_OK) {
response.close();
httpClient.close();
LogKit.info("龙光IDM集成登录,获取用户信息请求出错,http status:" + statusCode);
LogKit.info("集成登录,获取用户信息请求出错,http status:" + statusCode);
return "";
}
@ -386,28 +383,28 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
if (httpEntity == null) {
response.close();
httpClient.close();
LogKit.info("龙光IDM集成登录,获取用户信息请求出错,http响应内容为空");
LogKit.info("集成登录,获取用户信息请求出错,http响应内容为空");
return "";
}
responseContent = EntityUtils.toString(httpEntity, "UTF-8");
response.close();
httpClient.close();
if (StringKit.isEmpty(responseContent)) {
LogKit.info("龙光IDM集成登录,获取用户信息请求出错,http响应内容为空1");
LogKit.info("集成登录,获取用户信息请求出错,http响应内容为空1");
return "";
}
LogKit.info("龙光IDM集成登录,获取用户信息请求,http响应内容\n" + responseContent);
LogKit.info("集成登录,获取用户信息请求,http响应内容\n" + responseContent);
String uid = getUsername(responseContent);
if (StringKit.isEmpty(uid)) {
LogKit.info("龙光IDM集成登录,获取用户信息请求出错,用户名为空");
LogKit.info("集成登录,获取用户信息请求出错,用户名为空");
return "";
}
LogKit.info("龙光IDM集成登录,用户名:" + uid);
LogKit.info("集成登录,用户名:" + uid);
uid = uid.toLowerCase();
return uid;
} catch (Exception e) {
LogKit.error("龙光IDM集成登录获取用户名出错," + e.getMessage(), e);
LogKit.error("集成登录获取用户名出错," + e.getMessage(), e);
}
return "";
}
@ -469,7 +466,7 @@ public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFil
// continue;
//}
paraValues = entry.getValue();
LogKit.info("龙光IDM集成登录,获取用户信息请求出错,login_name为空");
LogKit.info("集成登录,获取用户信息请求出错,login_name为空");
queryStr = addParaToQuery(queryStr, paraName, paraValues);
}
if (StringKit.isEmpty(queryStr)) {

Loading…
Cancel
Save