systemUrlGet.jsp 4.15 KB
<%--
  Created by IntelliJ IDEA.
  User: zhaiyaqi
  Date: 2020/3/15
  Time: 7:34 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
<%@ page import="org.apache.http.HttpResponse" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="com.cntytz.HttpUtils" %>
<%@ page import="java.util.Map" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    response.setContentType("application/json;charset=utf-8");
    out.clear();
    writeLog("【sysytem=========================22222222222222】:");
    writeLog("【sysytem=========================22222222222222】:");
    writeLog("【sysytem=========================22222222222222】:");
    JSONObject result = new JSONObject(true);
    String sysytem = request.getParameter("sysytem");
    String userName = request.getParameter("userName");
    String password = request.getParameter("password");
    JSONObject json = new JSONObject();
    writeLog("sysytem========================="+sysytem);
    writeLog("userName========================="+userName);
    writeLog("password========================="+password);
    try {
        Map<String, String> headers = new HashMap<>();
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        String host = "";
        String path = "";
        String redirectUrl = "";
        String errorUrl ="";
        //jira
        if ("jira".equals(sysytem)){
            bodys.put("os_username",userName);
            bodys.put("os_password",password);
            bodys.put("os_destination","");
            bodys.put("user_role","");
            bodys.put("atl_token","");
            bodys.put("login","登录");
            host = "https://jira.cntytz.com";
            path = "/login.jsp";
            redirectUrl = host+path+"?"+"os_username="+userName+"&os_password="+password+"&os_destination=&user_role=&atl_token=&login=登录";
            errorUrl ="https://os.cntytz.com/spa/integration/static4engine/engine.html#/main/integration/accountSetting/confluence";

        }
        writeLog("confluence=========================");
        //confluence
        if ("confluence".equals(sysytem)){
            bodys.put("os_username",userName);
            bodys.put("os_password",password);
            bodys.put("login","登录");
            bodys.put("os_destination","");
            bodys.put("permissionViolation","true");
            host = "https://confluence.cntytz.com";
//            host = "https://192.168.150.212:8090";
            path = "/dologin.action";
            redirectUrl = host+path+"?"+"os_username="+userName+"&os_password="+password+"&&login=登录&permissionViolation=true&os_destination=";
            errorUrl ="https://os.cntytz.com/spa/integration/static4engine/engine.html#/main/integration/accountSetting/confluence";
        }
        writeLog("https========================="+redirectUrl);
        writeLog("host========================="+host);
        writeLog("path========================="+path);
        writeLog("querys========================="+JSONObject.toJSONString(bodys));
        HttpResponse res = HttpUtils.doPost(host, path, "POST", headers, querys, bodys);
        writeLog("res========================="+res);
        org.apache.http.HeaderElement element = res.getHeaders("X-Seraph-LoginReason")[0].getElements()[0];
        writeLog("element========================="+element);
        if ("OK".equals(element)){
            response.sendRedirect(redirectUrl);
        }else{
            response.sendRedirect(errorUrl);
        }
    } catch (Exception e) {
        result.put("code", -1);
        result.put("message", "接口处理异常"+e.getMessage());
        return;
    }
    out.print(result.toJSONString());
%>
<%!
    private void writeLog(Object o) {
        Log var3 = LogFactory.getLog(this.getClass().getName());
        if(o instanceof Exception) {
            var3.info(this.getClass().getName(), (Exception)o);
        } else {
            var3.info(o);
        }
    }

%>