diff --git a/skywalking-webui/src/main/java/com/ai/cloud/controller/AuthFileCtl.java b/skywalking-webui/src/main/java/com/ai/cloud/controller/AuthFileCtl.java new file mode 100644 index 000000000..4abf4376e --- /dev/null +++ b/skywalking-webui/src/main/java/com/ai/cloud/controller/AuthFileCtl.java @@ -0,0 +1,91 @@ +package com.ai.cloud.controller; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.OutputStream; +import java.net.URLDecoder; +import java.net.URLEncoder; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; + +import com.ai.cloud.util.Constants; +import com.ai.cloud.util.common.StringUtil; +import com.alibaba.fastjson.JSONObject; + +@Controller +public class AuthFileCtl { + + private static Logger logger = LogManager.getLogger(AlarmRuleCtl.class); + + @RequestMapping("/exportAuth/{appCode}") + public void exportApplicationAuthFile(HttpServletRequest request, HttpServletResponse response, + @PathVariable("appCode") String appCode) throws Exception { + HttpSession session = request.getSession(); + String uid = (String) session.getAttribute("uid"); + + JSONObject reJson = new JSONObject(); + + if (StringUtil.isBlank(uid)) { + reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL); + reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时"); + return ; + } + + String filepath = "sky-walking.auth"; + response.reset(); + response.setContentType("application/octet-stream"); + String fileName = URLDecoder.decode(filepath, "utf-8"); + java.net.URLEncoder.encode(fileName, "utf-8"); + response.addHeader("Content-Disposition", + "attachment;" + "filename=\"" + URLEncoder.encode(fileName, "utf-8") + "\""); + + StringBuilder sb = new StringBuilder(""); + sb.append("测试魂牵梦萦魂牵梦萦" + "\r\n"); + BufferedOutputStream output = null; + BufferedInputStream input = null; + OutputStream os = null; + try { + os = response.getOutputStream(); + byte[] byt = sb.toString().getBytes(); + os.write(byt); + } catch (Exception e) { + logger.error("导出 {} 应用制空权文件异常", appCode); + e.printStackTrace(); + } finally { + os.flush(); + os.close(); + if (input != null) { + input.close(); + } + if (output != null) { + output.close(); + } + } + return; + } + + @RequestMapping("/confAuthInfo/{appCode}") + public String confAuthInfo(HttpServletRequest request, HttpServletResponse response, + @PathVariable("appCode") String appCode) throws Exception { + HttpSession session = request.getSession(); + String uid = (String) session.getAttribute("uid"); + + JSONObject reJson = new JSONObject(); + + if (StringUtil.isBlank(uid)) { + reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL); + reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时"); + return reJson.toJSONString(); + } + + return reJson.toJSONString(); + } +} diff --git a/skywalking-webui/src/main/java/com/ai/cloud/dao/impl/AppAuthInfoMDAO.java b/skywalking-webui/src/main/java/com/ai/cloud/dao/impl/AppAuthInfoMDAO.java new file mode 100644 index 000000000..7a76ff93d --- /dev/null +++ b/skywalking-webui/src/main/java/com/ai/cloud/dao/impl/AppAuthInfoMDAO.java @@ -0,0 +1,88 @@ +package com.ai.cloud.dao.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import com.ai.cloud.dao.inter.IAppAuthInfoMDAO; +import com.ai.cloud.vo.mvo.AppAuthInfoMVO; + +@Repository +public class AppAuthInfoMDAO implements IAppAuthInfoMDAO { + + @Autowired + private JdbcTemplate jdbcTemplate; + + private static Logger logger = LogManager.getLogger(AppAuthInfoMDAO.class); + + @Override + public AppAuthInfoMVO queryAppAuthInfo(AppAuthInfoMVO rule) { + final AppAuthInfoMVO ruleMVO = new AppAuthInfoMVO(); + String sql = "select info_id,app_id,auth_json,create_time,sts,modify_time from app_auth_info where "; + final Object[] params = new Object[] { rule.getInfoId() }; + jdbcTemplate.query(sql, params, new RowCallbackHandler() { + @Override + public void processRow(ResultSet rs) throws SQLException { + ruleMVO.setInfoId(rs.getString("info_id")); + ruleMVO.setAppId(rs.getString("app_id")); + ruleMVO.setAuthJson(rs.getString("auth_json")); + ruleMVO.setCreateTime(rs.getTimestamp("create_time")); + ruleMVO.setSts(rs.getString("sts")); + ruleMVO.setModifyTime(rs.getTimestamp("modify_time")); + } + }); + logger.info("result : {}", ruleMVO); + return ruleMVO; + } + + @Override + public AppAuthInfoMVO createAlarmRule(final AppAuthInfoMVO ruleMVO) { + final String sql = "insert into app_auth_info (app_id,auth_json,create_time,sts,modify_time) values (?,?,sysdate(),?,sysdate())"; + KeyHolder keyHolder = new GeneratedKeyHolder(); + + int count = jdbcTemplate.update(new PreparedStatementCreator() { + public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { + PreparedStatement pstmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + int i = 0; + pstmt.setString(++i, ruleMVO.getAppId()); + pstmt.setString(++i, ruleMVO.getAuthJson()); + pstmt.setString(++i, ruleMVO.getSts()); + return pstmt; + } + }, keyHolder); + logger.info("创建授权文件成功:{}", keyHolder.getKey().intValue()); + ruleMVO.setInfoId(keyHolder.getKey().toString()); + + return ruleMVO; + } + + @Override + public AppAuthInfoMVO modifyAlarmRule(final AppAuthInfoMVO ruleMVO) { + final String sql = "update app_auth_info set auth_json = ?,modify_time = sysdate() where info_id = ?"; + + int count = jdbcTemplate.update(new PreparedStatementCreator() { + public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { + PreparedStatement pstmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + int i = 0; + pstmt.setString(++i, ruleMVO.getAuthJson()); + pstmt.setString(++i, ruleMVO.getInfoId()); + return pstmt; + } + }); + + return ruleMVO; + } + +} diff --git a/skywalking-webui/src/main/java/com/ai/cloud/dao/inter/IAppAuthInfoMDAO.java b/skywalking-webui/src/main/java/com/ai/cloud/dao/inter/IAppAuthInfoMDAO.java new file mode 100644 index 000000000..d942c371b --- /dev/null +++ b/skywalking-webui/src/main/java/com/ai/cloud/dao/inter/IAppAuthInfoMDAO.java @@ -0,0 +1,13 @@ +package com.ai.cloud.dao.inter; + +import com.ai.cloud.vo.mvo.AppAuthInfoMVO; + +public interface IAppAuthInfoMDAO { + + AppAuthInfoMVO queryAppAuthInfo(AppAuthInfoMVO rule); + + AppAuthInfoMVO createAlarmRule(AppAuthInfoMVO ruleMVO); + + AppAuthInfoMVO modifyAlarmRule(AppAuthInfoMVO ruleMVO); + +} diff --git a/skywalking-webui/src/main/java/com/ai/cloud/vo/mvo/AppAuthInfoMVO.java b/skywalking-webui/src/main/java/com/ai/cloud/vo/mvo/AppAuthInfoMVO.java new file mode 100644 index 000000000..a75f844e8 --- /dev/null +++ b/skywalking-webui/src/main/java/com/ai/cloud/vo/mvo/AppAuthInfoMVO.java @@ -0,0 +1,7 @@ +package com.ai.cloud.vo.mvo; + +import com.ai.cloud.vo.svo.AppAuthInfoSVO; + +public class AppAuthInfoMVO extends AppAuthInfoSVO{ + +} diff --git a/skywalking-webui/src/main/java/com/ai/cloud/vo/svo/AppAuthInfoSVO.java b/skywalking-webui/src/main/java/com/ai/cloud/vo/svo/AppAuthInfoSVO.java new file mode 100644 index 000000000..2c140d524 --- /dev/null +++ b/skywalking-webui/src/main/java/com/ai/cloud/vo/svo/AppAuthInfoSVO.java @@ -0,0 +1,73 @@ +package com.ai.cloud.vo.svo; + +import java.sql.Timestamp; + +public class AppAuthInfoSVO { + + private String infoId; + + private String appId; + + private String authJson; + + private Timestamp createTime; + + private String sts; + + private Timestamp modifyTime; + + public String getInfoId() { + return infoId; + } + + public void setInfoId(String infoId) { + this.infoId = infoId; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAuthJson() { + return authJson; + } + + public void setAuthJson(String authJson) { + this.authJson = authJson; + } + + public Timestamp getCreateTime() { + return createTime; + } + + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } + + public String getSts() { + return sts; + } + + public void setSts(String sts) { + this.sts = sts; + } + + public Timestamp getModifyTime() { + return modifyTime; + } + + public void setModifyTime(Timestamp modifyTime) { + this.modifyTime = modifyTime; + } + + @Override + public String toString() { + return "AppAuthInfo [infoId=" + infoId + ", appId=" + appId + ", authJson=" + authJson + ", createTime=" + + createTime + ", sts=" + sts + ", modifyTime=" + modifyTime + "]"; + } + +} diff --git a/skywalking-webui/src/main/webapp/ftl/applist.ftl b/skywalking-webui/src/main/webapp/ftl/applist.ftl index 4486e3c17..91fb7437f 100644 --- a/skywalking-webui/src/main/webapp/ftl/applist.ftl +++ b/skywalking-webui/src/main/webapp/ftl/applist.ftl @@ -91,6 +91,105 @@ + @@ -123,6 +222,7 @@
@@ -114,7 +213,7 @@
${appInfo.appCode!} - +
+ <@common.importJavaScript />