Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzuaa
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzuaa
提交
095c58c2
提交
095c58c2
编写于
5月 09, 2020
作者:
ibizdev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ibizdev提交
上级
38637162
变更
7
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
210 行增加
和
24 行删除
+210
-24
pom.xml
ibzuaa-provider/ibzuaa-provider-api/pom.xml
+0
-10
SwaggerConfiguration.java
...rc/main/java/cn/ibizlab/swagger/SwaggerConfiguration.java
+36
-2
pom.xml
ibzuaa-util/pom.xml
+10
-0
AppController.java
...til/src/main/java/cn/ibizlab/util/rest/AppController.java
+10
-6
AuthPermissionEvaluator.java
...ava/cn/ibizlab/util/security/AuthPermissionEvaluator.java
+5
-5
AuthenticationUser.java
...ain/java/cn/ibizlab/util/security/AuthenticationUser.java
+1
-1
IBZOperationParameterReader.java
...java/cn/ibizlab/util/web/IBZOperationParameterReader.java
+148
-0
未找到文件。
ibzuaa-provider/ibzuaa-provider-api/pom.xml
浏览文件 @
095c58c2
...
@@ -19,16 +19,6 @@
...
@@ -19,16 +19,6 @@
<artifactId>
ibzuaa-core
</artifactId>
<artifactId>
ibzuaa-core
</artifactId>
<version>
${project.version}
</version>
<version>
${project.version}
</version>
</dependency>
</dependency>
<!-- Swagger2 -->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
</dependency>
</dependencies>
</dependencies>
<properties>
<properties>
...
...
ibzuaa-provider/ibzuaa-provider-api/src/main/java/cn/ibizlab/swagger/SwaggerConfiguration.java
浏览文件 @
095c58c2
package
cn
.
ibizlab
.
swagger
;
package
cn
.
ibizlab
.
swagger
;
import
cn.ibizlab.util.security.SpringContextHolder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
static
com
.
google
.
common
.
base
.
Predicates
.
or
;
import
static
com
.
google
.
common
.
base
.
Predicates
.
or
;
import
static
springfox
.
documentation
.
builders
.
PathSelectors
.
regex
;
import
static
springfox
.
documentation
.
builders
.
PathSelectors
.
regex
;
import
org.springframework.plugin.core.PluginRegistry
;
import
org.springframework.plugin.core.PluginRegistrySupport
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.service.OperationBuilderPlugin
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.spring.web.readers.operation.OperationParameterReader
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.List
;
@Configuration
@Configuration
//
@EnableSwagger2
@EnableSwagger2
public
class
SwaggerConfiguration
{
public
class
SwaggerConfiguration
{
@Bean
@Bean
public
Docket
docket
()
{
public
Docket
docket
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
Docket
docket
=
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
groupName
(
"DEFAULT"
)
.
groupName
(
"DEFAULT"
)
.
pathMapping
(
"/"
)
.
pathMapping
(
"/"
)
.
apiInfo
(
.
apiInfo
(
...
@@ -33,6 +42,8 @@ public class SwaggerConfiguration {
...
@@ -33,6 +42,8 @@ public class SwaggerConfiguration {
.
paths
(
PathSelectors
.
any
())
.
paths
(
PathSelectors
.
any
())
.
build
()
.
build
()
;
;
removeDefaultPlugin
();
return
docket
;
}
}
@Bean
@Bean
...
@@ -54,4 +65,27 @@ public class SwaggerConfiguration {
...
@@ -54,4 +65,27 @@ public class SwaggerConfiguration {
;
;
}
}
private
void
removeDefaultPlugin
()
{
// 从spring容器中获取swagger插件注册表
PluginRegistry
<
OperationBuilderPlugin
,
DocumentationType
>
pluginRegistry
=
SpringContextHolder
.
getBean
(
"operationBuilderPluginRegistry"
);
// 插件集合
List
<
OperationBuilderPlugin
>
plugins
=
pluginRegistry
.
getPlugins
();
// 从spring容器中获取需要删除的插件
OperationParameterReader
operationParameterReader
=
SpringContextHolder
.
getBean
(
OperationParameterReader
.
class
);
if
(
operationParameterReader
==
null
)
return
;
// 原plugins集合不能修改,创建新集合,通过反射替换
if
(
pluginRegistry
.
contains
(
operationParameterReader
))
{
List
<
OperationBuilderPlugin
>
plugins_new
=
new
ArrayList
<
OperationBuilderPlugin
>(
plugins
);
plugins_new
.
remove
(
operationParameterReader
);
try
{
Field
field
=
PluginRegistrySupport
.
class
.
getDeclaredField
(
"plugins"
);
field
.
setAccessible
(
true
);
field
.
set
(
pluginRegistry
,
plugins_new
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
ibzuaa-util/pom.xml
浏览文件 @
095c58c2
...
@@ -75,5 +75,15 @@
...
@@ -75,5 +75,15 @@
<artifactId>
commons-pool2
</artifactId>
<artifactId>
commons-pool2
</artifactId>
</dependency>
</dependency>
<!-- Swagger2 -->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
ibzuaa-util/src/main/java/cn/ibizlab/util/rest/AppController.java
浏览文件 @
095c58c2
package
cn
.
ibizlab
.
util
.
rest
;
package
cn
.
ibizlab
.
util
.
rest
;
import
java.util.ArrayList
;
import
com.alibaba.fastjson.JSONArray
;
import
java.util.List
;
import
java.util.Map
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
cn.ibizlab.util.security.AuthenticationUser
;
@RestController
@RestController
@RequestMapping
(
value
=
""
)
@RequestMapping
(
value
=
""
)
...
@@ -19,7 +16,14 @@ public class AppController {
...
@@ -19,7 +16,14 @@ public class AppController {
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/appdata"
)
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/appdata"
)
public
ResponseEntity
<
JSONObject
>
getAppData
()
{
public
ResponseEntity
<
JSONObject
>
getAppData
()
{
JSONObject
appData
=
new
JSONObject
()
;
JSONObject
appData
=
new
JSONObject
()
;
JSONArray
uniRes
=
new
JSONArray
();
JSONObject
userPermission
=
AuthenticationUser
.
getAuthenticationUser
().
getPermissionList
();
if
(!
ObjectUtils
.
isEmpty
(
userPermission
)){
uniRes
=
userPermission
.
getJSONArray
(
"unires"
);
}
appData
.
put
(
"unires"
,
uniRes
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
appData
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
appData
);
}
}
...
...
ibzuaa-util/src/main/java/cn/ibizlab/util/security/AuthPermissionEvaluator.java
浏览文件 @
095c58c2
...
@@ -74,7 +74,7 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
...
@@ -74,7 +74,7 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
return
false
;
return
false
;
//获取当前用户权限列表
//获取当前用户权限列表
JSONObject
userPermission
=
AuthenticationUser
.
getAuthenticationUser
().
getPermisionList
();
JSONObject
userPermission
=
AuthenticationUser
.
getAuthenticationUser
().
getPermis
s
ionList
();
if
(
userPermission
==
null
)
if
(
userPermission
==
null
)
return
false
;
return
false
;
...
@@ -88,7 +88,7 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
...
@@ -88,7 +88,7 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
String
entityName
=
entity
.
getClass
().
getSimpleName
();
String
entityName
=
entity
.
getClass
().
getSimpleName
();
//获取实体行为权限信息
//获取实体行为权限信息
JSONObject
permissionList
=
userPermission
.
getJSONObject
(
"
userPermissionList
"
);
JSONObject
permissionList
=
userPermission
.
getJSONObject
(
"
entities
"
);
//检查是否有操作权限[create.update.delete.read]
//检查是否有操作权限[create.update.delete.read]
if
(!
validDEActionHasPermission
(
permissionList
,
entityName
,
action
)){
if
(!
validDEActionHasPermission
(
permissionList
,
entityName
,
action
)){
...
@@ -106,7 +106,7 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
...
@@ -106,7 +106,7 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
String
entityName
=
entity
.
getClass
().
getSimpleName
();
String
entityName
=
entity
.
getClass
().
getSimpleName
();
//获取数据集权限信息
//获取数据集权限信息
JSONObject
permissionList
=
userPermission
.
getJSONObject
(
"
userPermissionList
"
);
JSONObject
permissionList
=
userPermission
.
getJSONObject
(
"
entities
"
);
if
(
StringUtils
.
isEmpty
(
entityName
)||
StringUtils
.
isEmpty
(
dataSetName
))
if
(
StringUtils
.
isEmpty
(
entityName
)||
StringUtils
.
isEmpty
(
dataSetName
))
return
false
;
return
false
;
...
@@ -145,8 +145,8 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
...
@@ -145,8 +145,8 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
if
(
StringUtils
.
isEmpty
(
entity
))
if
(
StringUtils
.
isEmpty
(
entity
))
return
false
;
return
false
;
JSONObject
userPermission
=
AuthenticationUser
.
getAuthenticationUser
().
getPermisionList
();
JSONObject
userPermission
=
AuthenticationUser
.
getAuthenticationUser
().
getPermis
s
ionList
();
JSONObject
permissionList
=
userPermission
.
getJSONObject
(
"
userPermissionList
"
);
JSONObject
permissionList
=
userPermission
.
getJSONObject
(
"
entities
"
);
String
entityName
=
entity
.
getClass
().
getSimpleName
();
String
entityName
=
entity
.
getClass
().
getSimpleName
();
if
(
action
.
equalsIgnoreCase
(
"create"
)){
if
(
action
.
equalsIgnoreCase
(
"create"
)){
...
...
ibzuaa-util/src/main/java/cn/ibizlab/util/security/AuthenticationUser.java
浏览文件 @
095c58c2
...
@@ -61,7 +61,7 @@ public class AuthenticationUser implements UserDetails
...
@@ -61,7 +61,7 @@ public class AuthenticationUser implements UserDetails
private
Collection
<
GrantedAuthority
>
authorities
;
private
Collection
<
GrantedAuthority
>
authorities
;
@JsonIgnore
@JsonIgnore
private
int
superuser
;
private
int
superuser
;
private
JSONObject
permisionList
;
private
JSONObject
permis
s
ionList
;
private
String
orglevel
;
//单位级别
private
String
orglevel
;
//单位级别
private
String
deptlevel
;
//部门级别
private
String
deptlevel
;
//部门级别
@JsonIgnore
@JsonIgnore
...
...
ibzuaa-util/src/main/java/cn/ibizlab/util/web/IBZOperationParameterReader.java
0 → 100644
浏览文件 @
095c58c2
package
cn
.
ibizlab
.
util
.
web
;
import
cn.ibizlab.util.filter.SearchContextBase
;
import
com.fasterxml.classmate.ResolvedType
;
import
com.google.common.base.Predicate
;
import
com.google.common.collect.FluentIterable
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestPart
;
import
springfox.documentation.builders.ParameterBuilder
;
import
springfox.documentation.service.Parameter
;
import
springfox.documentation.service.ResolvedMethodParameter
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.schema.EnumTypeDeterminer
;
import
springfox.documentation.spi.service.OperationBuilderPlugin
;
import
springfox.documentation.spi.service.contexts.OperationContext
;
import
springfox.documentation.spi.service.contexts.ParameterContext
;
import
springfox.documentation.spring.web.plugins.DocumentationPluginsManager
;
import
springfox.documentation.spring.web.readers.parameter.ExpansionContext
;
import
springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander
;
import
java.lang.annotation.Annotation
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
static
com
.
google
.
common
.
base
.
Predicates
.*;
import
static
com
.
google
.
common
.
collect
.
Lists
.*;
import
static
springfox
.
documentation
.
schema
.
Collections
.*;
import
static
springfox
.
documentation
.
schema
.
Maps
.*;
import
static
springfox
.
documentation
.
schema
.
Types
.*;
@Component
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
)
public
class
IBZOperationParameterReader
implements
OperationBuilderPlugin
{
private
final
ModelAttributeParameterExpander
expander
;
private
final
EnumTypeDeterminer
enumTypeDeterminer
;
@Autowired
private
DocumentationPluginsManager
pluginsManager
;
@Autowired
public
IBZOperationParameterReader
(
ModelAttributeParameterExpander
expander
,
EnumTypeDeterminer
enumTypeDeterminer
)
{
this
.
expander
=
expander
;
this
.
enumTypeDeterminer
=
enumTypeDeterminer
;
}
@Override
public
void
apply
(
OperationContext
context
)
{
context
.
operationBuilder
().
parameters
(
context
.
getGlobalOperationParameters
());
context
.
operationBuilder
().
parameters
(
readParameters
(
context
));
}
@Override
public
boolean
supports
(
DocumentationType
delimiter
)
{
return
true
;
}
private
List
<
Parameter
>
readParameters
(
final
OperationContext
context
)
{
List
<
ResolvedMethodParameter
>
methodParameters
=
context
.
getParameters
();
List
<
Parameter
>
parameters
=
newArrayList
();
for
(
ResolvedMethodParameter
methodParameter
:
methodParameters
)
{
ResolvedType
alternate
=
context
.
alternateFor
(
methodParameter
.
getParameterType
());
if
(!
shouldIgnore
(
methodParameter
,
alternate
,
context
.
getIgnorableParameterTypes
()))
{
ParameterContext
parameterContext
=
new
ParameterContext
(
methodParameter
,
new
ParameterBuilder
(),
context
.
getDocumentationContext
(),
context
.
getGenericsNamingStrategy
(),
context
);
if
(
shouldExpand
(
methodParameter
,
alternate
))
{
parameters
.
addAll
(
expander
.
expand
(
new
ExpansionContext
(
""
,
alternate
,
context
)));
}
else
{
parameters
.
add
(
pluginsManager
.
parameter
(
parameterContext
));
}
}
}
return
FluentIterable
.
from
(
parameters
).
filter
(
not
(
hiddenParams
())).
toList
();
}
private
Predicate
<
Parameter
>
hiddenParams
()
{
return
new
Predicate
<
Parameter
>()
{
@Override
public
boolean
apply
(
Parameter
input
)
{
return
input
.
isHidden
();
}
};
}
private
boolean
shouldIgnore
(
final
ResolvedMethodParameter
parameter
,
ResolvedType
resolvedParameterType
,
final
Set
<
Class
>
ignorableParamTypes
)
{
if
(
ignorableParamTypes
.
contains
(
resolvedParameterType
.
getErasedType
()))
{
return
true
;
}
return
FluentIterable
.
from
(
ignorableParamTypes
)
.
filter
(
isAnnotation
())
.
filter
(
parameterIsAnnotatedWithIt
(
parameter
)).
size
()
>
0
;
}
private
Predicate
<
Class
>
parameterIsAnnotatedWithIt
(
final
ResolvedMethodParameter
parameter
)
{
return
new
Predicate
<
Class
>()
{
@Override
public
boolean
apply
(
Class
input
)
{
return
parameter
.
hasParameterAnnotation
(
input
);
}
};
}
private
Predicate
<
Class
>
isAnnotation
()
{
return
new
Predicate
<
Class
>()
{
@Override
public
boolean
apply
(
Class
input
)
{
return
Annotation
.
class
.
isAssignableFrom
(
input
);
}
};
}
private
boolean
shouldExpand
(
final
ResolvedMethodParameter
parameter
,
ResolvedType
resolvedParamType
)
{
return
!
parameter
.
hasParameterAnnotation
(
RequestBody
.
class
)
&&
!
parameter
.
hasParameterAnnotation
(
RequestPart
.
class
)
&&
!
parameter
.
hasParameterAnnotation
(
RequestParam
.
class
)
&&
!
parameter
.
hasParameterAnnotation
(
PathVariable
.
class
)
&&
!
isBaseType
(
typeNameFor
(
resolvedParamType
.
getErasedType
()))
&&
!
enumTypeDeterminer
.
isEnum
(
resolvedParamType
.
getErasedType
())
&&
!
isContainerType
(
resolvedParamType
)
&&
!
isMapType
(
resolvedParamType
)
&&
!
SearchContextBase
.
class
.
isAssignableFrom
(
resolvedParamType
.
getErasedType
());
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录