Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ssssssss-team
magic-api
提交
8475bea7
M
magic-api
项目概览
ssssssss-team
/
magic-api
12 个月 前同步成功
通知
41
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
magic-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8475bea7
编写于
12月 30, 2021
作者:
M
mxd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
数据源测试连接
上级
3438d122
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
81 addition
and
111 deletion
+81
-111
magic-api-spring-boot-starter/src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicAPIAutoConfiguration.java
...gicapi/spring/boot/starter/MagicAPIAutoConfiguration.java
+3
-1
magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicController.java
...ava/org/ssssssss/magicapi/controller/MagicController.java
+1
-6
magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicDataSourceController.java
...ssssss/magicapi/controller/MagicDataSourceController.java
+30
-0
magic-api/src/main/java/org/ssssssss/magicapi/interceptor/AuthorizationInterceptor.java
...ssssss/magicapi/interceptor/AuthorizationInterceptor.java
+3
-29
magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java
...ssssss/magicapi/provider/impl/DefaultMagicAPIService.java
+0
-75
magic-api/src/main/java/org/ssssssss/magicapi/utils/JdbcUtils.java
.../src/main/java/org/ssssssss/magicapi/utils/JdbcUtils.java
+44
-0
未找到文件。
magic-api-spring-boot-starter/src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicAPIAutoConfiguration.java
浏览文件 @
8475bea7
...
...
@@ -577,7 +577,9 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
MagicWorkbenchController
magicWorkbenchController
=
new
MagicWorkbenchController
(
configuration
,
properties
.
getSecretKey
());
if
(
base
!=
null
)
{
configuration
.
setEnableWeb
(
true
);
mapping
.
registerController
(
magicWorkbenchController
).
registerController
(
new
MagicResourceController
(
configuration
));
mapping
.
registerController
(
magicWorkbenchController
)
.
registerController
(
new
MagicResourceController
(
configuration
))
.
registerController
(
new
MagicDataSourceController
(
configuration
));
}
// 注册接收推送的接口
if
(
StringUtils
.
isNotBlank
(
properties
.
getSecretKey
()))
{
...
...
magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicController.java
浏览文件 @
8475bea7
...
...
@@ -62,12 +62,7 @@ public class MagicController implements JsonCodeConstants {
return
true
;
}
MagicUser
magicUser
=
(
MagicUser
)
request
.
getAttribute
(
Constants
.
ATTRIBUTE_MAGIC_USER
);
if
(
entity
instanceof
ApiInfo
)
{
return
configuration
.
getAuthorizationInterceptor
().
allowVisit
(
magicUser
,
request
,
authorization
,
(
ApiInfo
)
entity
);
}
else
if
(
entity
instanceof
FunctionInfo
)
{
return
configuration
.
getAuthorizationInterceptor
().
allowVisit
(
magicUser
,
request
,
authorization
,
(
FunctionInfo
)
entity
);
}
return
false
;
return
configuration
.
getAuthorizationInterceptor
().
allowVisit
(
magicUser
,
request
,
authorization
,
entity
);
}
boolean
allowVisit
(
HttpServletRequest
request
,
Authorization
authorization
,
Group
group
)
{
...
...
magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicDataSourceController.java
0 → 100644
浏览文件 @
8475bea7
package
org.ssssssss.magicapi.controller
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.ssssssss.magicapi.config.MagicConfiguration
;
import
org.ssssssss.magicapi.model.DataSourceInfo
;
import
org.ssssssss.magicapi.model.JsonBean
;
import
org.ssssssss.magicapi.utils.JdbcUtils
;
import
java.sql.Connection
;
public
class
MagicDataSourceController
extends
MagicController
implements
MagicExceptionHandler
{
public
MagicDataSourceController
(
MagicConfiguration
configuration
)
{
super
(
configuration
);
}
@RequestMapping
(
"/datasource/jdbc/test"
)
@ResponseBody
public
JsonBean
<
String
>
test
(
@RequestBody
DataSourceInfo
properties
)
{
try
{
Connection
connection
=
JdbcUtils
.
getConnection
(
properties
.
getDriverClassName
(),
properties
.
getUrl
(),
properties
.
getUsername
(),
properties
.
getPassword
());
JdbcUtils
.
close
(
connection
);
}
catch
(
Exception
e
)
{
return
new
JsonBean
<>(
e
.
getMessage
());
}
return
new
JsonBean
<>(
"ok"
);
}
}
magic-api/src/main/java/org/ssssssss/magicapi/interceptor/AuthorizationInterceptor.java
浏览文件 @
8475bea7
package
org.ssssssss.magicapi.interceptor
;
import
org.ssssssss.magicapi.exception.MagicLoginException
;
import
org.ssssssss.magicapi.model.ApiInfo
;
import
org.ssssssss.magicapi.model.DataSourceInfo
;
import
org.ssssssss.magicapi.model.FunctionInfo
;
import
org.ssssssss.magicapi.model.Group
;
import
org.ssssssss.magicapi.model.MagicEntity
;
import
javax.servlet.http.HttpServletRequest
;
...
...
@@ -75,25 +73,13 @@ public interface AuthorizationInterceptor {
* @param magicUser 登录的用户对象
* @param request HttpServletRequest
* @param authorization 鉴权方法
* @param
apiInfo 接口
信息
* @param
entity 接口、函数、数据源
信息
* @return true 有权限访问, false 无权限访问
*/
default
boolean
allowVisit
(
MagicUser
magicUser
,
HttpServletRequest
request
,
Authorization
authorization
,
ApiInfo
apiInfo
)
{
default
boolean
allowVisit
(
MagicUser
magicUser
,
HttpServletRequest
request
,
Authorization
authorization
,
MagicEntity
entity
)
{
return
allowVisit
(
magicUser
,
request
,
authorization
);
}
/**
* 是否拥有对该函数的增删改权限
*
* @param magicUser 登录的用户对象
* @param request HttpServletRequest
* @param authorization 鉴权方法
* @param functionInfo 函数信息
* @return true 有权限访问, false 无权限访问
*/
default
boolean
allowVisit
(
MagicUser
magicUser
,
HttpServletRequest
request
,
Authorization
authorization
,
FunctionInfo
functionInfo
)
{
return
allowVisit
(
magicUser
,
request
,
authorization
);
}
/**
* 是否拥有对该分组的增删改权限
...
...
@@ -108,16 +94,4 @@ public interface AuthorizationInterceptor {
return
allowVisit
(
magicUser
,
request
,
authorization
);
}
/**
* 是否拥有对该数据源的增删改权限
*
* @param magicUser 登录的用户对象
* @param request HttpServletRequest
* @param authorization 鉴权方法
* @param dataSourceInfo 数据源信息
* @return true 有权限访问, false 无权限访问
*/
default
boolean
allowVisit
(
MagicUser
magicUser
,
HttpServletRequest
request
,
Authorization
authorization
,
DataSourceInfo
dataSourceInfo
)
{
return
allowVisit
(
magicUser
,
request
,
authorization
);
}
}
magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java
浏览文件 @
8475bea7
...
...
@@ -133,81 +133,6 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
@Override
public
void
upload
(
InputStream
inputStream
,
String
mode
)
throws
IOException
{
// ZipResource root = new ZipResource(inputStream);
// Set<String> apiPaths = new LinkedHashSet<>();
// Set<String> functionPaths = new LinkedHashSet<>();
// Set<String> websocketPaths = new LinkedHashSet<>();
// Set<Group> groups = new LinkedHashSet<>();
// Set<ApiInfo> apiInfos = new LinkedHashSet<>();
// Set<FunctionInfo> functionInfos = new LinkedHashSet<>();
// Set<WebSocketInfo> websocketInfos = new LinkedHashSet<>();
// boolean checked = !UPLOAD_MODE_FULL.equals(mode);
// // 检查上传资源中是否有冲突
// readPaths(groups, apiPaths, functionPaths, websocketPaths, apiInfos, functionInfos, websocketInfos, "/", root, checked);
// Resource item = root.getResource(GROUP_METABASE);
// if (item.exists()) {
// Group group = groupServiceProvider.readGroup(item);
// // 检查上级分组是否存在
// isTrue("0".equals(group.getParentId()) || groupServiceProvider.getGroupResource(group.getParentId()).exists(), GROUP_NOT_FOUND);
// }
// if (checked) {
// // 检测分组是否有冲突
// groups.forEach(group -> {
// Resource resource;
// if ("0".equals(group.getParentId())) {
// resource = workspace.getDirectory(GROUP_TYPE_API.equals(group.getType()) ? PATH_API : (GROUP_TYPE_WEBSOCKET.equals(group.getType()) ? PATH_WEBSOCKET : PATH_FUNCTION)).getDirectory(group.getName());
// } else {
// resource = groupServiceProvider.getGroupResource(group.getId());
// }
// if (resource != null && resource.exists()) {
// Group src = groupServiceProvider.readGroup(resource.getResource(GROUP_METABASE));
// isTrue(src == null || src.getId().equals(group.getId()), GROUP_CONFLICT);
// }
// });
// } else {
// Resource resource = workspace.getDirectory(PATH_API);
// resource.delete();
// resource.mkdir();
// resource = workspace.getDirectory(PATH_FUNCTION);
// resource.delete();
// resource.mkdir();
// resource = workspace.getDirectory(PATH_WEBSOCKET);
// resource.delete();
// resource.mkdir();
// resource = workspace.getDirectory(PATH_DATASOURCE);
// resource.delete();
// resource.mkdir();
// }
// for (Group group : groups) {
// Resource groupResource = groupServiceProvider.getGroupResource(group.getId());
// if (groupResource != null && groupResource.exists()) {
// groupServiceProvider.update(group);
// } else {
// groupServiceProvider.insert(group);
// }
// }
// // 保存
// write(mappingRegistry.getStoreServiceProvider(), apiInfos);
// write(functionRegistry.getStoreServiceProvider(), functionInfos);
// write(webSocketRegistry.getStoreServiceProvider(), websocketInfos);
// // 备份
// apiInfos.forEach(backupService::backup);
// functionInfos.forEach(backupService::backup);
// websocketInfos.forEach(backupService::backup);
// // 重新注册
// this.mappingRegistries.forEach(AbstractMagicDynamicMappingRegistry::registerAll);
// Resource uploadDatasourceResource = root.getResource(PATH_DATASOURCE + "/");
// if (uploadDatasourceResource.exists()) {
// uploadDatasourceResource.files(".json").forEach(it -> {
// byte[] content = it.read();
// // 保存数据源
// this.datasourceResource.getResource(it.name()).write(content);
// // TODO 备份数据源
// });
// }
// // TODO 会造成闪断,需要上锁处理。
// registerAllDataSource();
// magicNotifyService.sendNotify(new MagicNotify(instanceId));
}
@Override
...
...
magic-api/src/main/java/org/ssssssss/magicapi/utils/JdbcUtils.java
0 → 100644
浏览文件 @
8475bea7
package
org.ssssssss.magicapi.utils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.jdbc.DatabaseDriver
;
import
org.ssssssss.magicapi.exception.MagicAPIException
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
public
class
JdbcUtils
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
JdbcUtils
.
class
);
public
static
Connection
getConnection
(
String
driver
,
String
url
,
String
username
,
String
password
)
{
try
{
if
(
StringUtils
.
isBlank
(
driver
))
{
driver
=
DatabaseDriver
.
fromJdbcUrl
(
url
).
getDriverClassName
();
if
(
StringUtils
.
isBlank
(
driver
))
{
throw
new
MagicAPIException
(
"无法从url中获得驱动类"
);
}
}
Class
.
forName
(
driver
);
}
catch
(
ClassNotFoundException
e
)
{
throw
new
MagicAPIException
(
"找不到驱动:"
+
driver
);
}
try
{
return
DriverManager
.
getConnection
(
url
,
username
,
password
);
}
catch
(
SQLException
e
)
{
logger
.
error
(
"获取Jdbc链接失败"
,
e
);
throw
new
MagicAPIException
(
"获取Jdbc链接失败:"
+
e
.
getMessage
());
}
}
public
static
void
close
(
Connection
connection
)
{
try
{
connection
.
close
();
}
catch
(
Exception
ignored
)
{
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录