Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Springboot Plus
Commits
a0a51905
Commit
a0a51905
authored
Jan 11, 2020
by
trumansdo
Browse files
1. 确定通用管理页面组件完成,通用组件中无法通用部分:下拉选择器;改为自定义插槽中自行添加
2. 更新element-ui版本 至2.13.0 3. 修复jwt 没有刷新过期时间。最终设置为10分钟过期时间窗口,以最后一次网络请求时间开始计算
parent
31fc8a95
Changes
29
Hide whitespace changes
Inline
Side-by-side
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/util/VOUtil.java
View file @
a0a51905
package
com.ibeetl.admin.console.util
;
import
cn.hutool.core.annotation.AnnotationUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.map.MapBuilder
;
import
cn.hutool.core.map.MapUtil
;
import
com.ibeetl.admin.core.annotation.ElColumn
;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.entity.ElCascaderData
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
...
...
@@ -15,6 +20,12 @@ import java.util.Optional;
*/
public
class
VOUtil
{
/**
* Method resolveElColumn ... todo 预计重新定义一个类用来转换,而不是用map
*
* @param cls of type Class ,一个专门存放元数据的ElQuery类
* @return Map
*/
public
static
Map
resolveElColumn
(
Class
cls
)
{
MapBuilder
<
String
,
Map
>
mapBuilder
=
MapUtil
.<
String
,
Map
>
builder
();
...
...
@@ -24,14 +35,9 @@ public class VOUtil {
AnnotationUtil
.
getAnnotationValueMap
(
field
,
ElColumn
.
class
);
ElColumn
elColumn
=
AnnotationUtil
.
getAnnotation
(
field
,
ElColumn
.
class
);
Optional
.
ofNullable
(
elColumn
)
.
ifPresent
(
column
->
{
if
(
column
.
visible
())
{
annotationValueMap
.
remove
(
"visible"
);
mapBuilder
.
put
(
field
.
getName
(),
annotationValueMap
);
}
});
.
ifPresent
(
column
->
mapBuilder
.
put
(
field
.
getName
(),
annotationValueMap
));
}
return
mapBuilder
.
build
();
}
}
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/web/UserElController.java
→
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/web/
Core
UserElController.java
View file @
a0a51905
package
com.ibeetl.admin.console.web
;
import
com.ibeetl.admin.console.util.VOUtil
;
import
com.ibeetl.admin.console.web.query.CoreUserElQuery
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.service.CoreUserService
;
import
com.ibeetl.admin.core.web.JsonResult
;
...
...
@@ -14,13 +15,13 @@ import org.springframework.web.bind.annotation.RestController;
@Validated
@RestController
public
class
UserElController
{
public
class
Core
UserElController
{
@Autowired
private
CoreUserService
coreUserService
;
@GetMapping
(
"/users/met
e
data"
)
@GetMapping
(
"/users/met
a
data"
)
public
JsonResult
<
Map
>
usersMetedata
()
{
return
JsonResult
.
success
(
VOUtil
.
resolveElColumn
(
CoreUser
.
class
));
return
JsonResult
.
success
(
VOUtil
.
resolveElColumn
(
CoreUser
ElQuery
.
class
));
}
@GetMapping
(
"/users"
)
...
...
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/web/query/CoreUserElQuery.java
0 → 100644
View file @
a0a51905
package
com.ibeetl.admin.console.web.query
;
import
static
com
.
ibeetl
.
admin
.
core
.
util
.
enums
.
ElColumnType
.
DATE
;
import
static
com
.
ibeetl
.
admin
.
core
.
util
.
enums
.
ElColumnType
.
DICT
;
import
static
com
.
ibeetl
.
admin
.
core
.
util
.
enums
.
ElColumnType
.
STRING
;
import
com.ibeetl.admin.core.annotation.ElColumn
;
import
java.util.Date
;
import
lombok.Data
;
/**
* Class CoreUserElQuery : <br>
* 描述:用户管理页面的metadata元数据
*
* @author 一日看尽长安花 Created on 2019/12/29
*/
@Data
public
class
CoreUserElQuery
{
@ElColumn
(
name
=
"ID"
,
type
=
STRING
)
protected
Long
id
;
@ElColumn
(
name
=
"创建时间"
,
type
=
DATE
)
protected
Date
createTime
;
@ElColumn
(
name
=
"用户名"
,
type
=
STRING
)
private
String
code
;
@ElColumn
(
name
=
"姓名"
,
type
=
STRING
)
private
String
name
;
@ElColumn
(
name
=
"状态"
,
type
=
STRING
)
private
String
state
;
@ElColumn
(
name
=
"职务"
,
type
=
DICT
)
private
String
jobType0
;
@ElColumn
(
name
=
"岗位"
,
type
=
DICT
)
private
String
jobType1
;
}
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/annotation/ElColumn.java
View file @
a0a51905
...
...
@@ -15,29 +15,35 @@ import java.lang.annotation.Target;
public
@interface
ElColumn
{
/**
* 数据表格
中的列
名称
* 数据表格
列头显示
名称
* @return
* */
String
name
();
/**
* 该列的类型。{@link com.ibeetl.admin.core.util.enums.ElColumnType}
* 该列的类型。
查看
{@link com.ibeetl.admin.core.util.enums.ElColumnType}
* @return
* */
String
type
();
/**
*
增加
数据表格的手动排序
*
开启element-ui 中
数据表格
列
的手动排序
* @return
* */
boolean
sortable
()
default
false
;
/**
* 是否在前端页面
可见,本质是在后端过滤掉注解的字段
* 是否在前端页面
的查询条件区显示
* @return
* */
boolean
visible
()
default
true
;
/**
* 是否在前端页面的数据表格列中显示
* @return
* */
boolean
displayable
()
default
true
;
/**
* 是否在表单中是必填。暂时没做规则的生成功能,暂定没有
* @return
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/conf/SpringWebMvcConfigurer.java
View file @
a0a51905
...
...
@@ -48,11 +48,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor
;
import
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
;
/**
* 切勿在此配置类中向SpringMVC中添加bean。
* 也就是不要 @Bean这类方法。
* 会出现无法ServletContext注入null,因为父接口的原因
* */
/** 切勿在此配置类中向SpringMVC中添加bean。 也就是不要 @Bean这类方法。 会出现无法ServletContext注入null,因为父接口的原因 */
@Configuration
public
class
SpringWebMvcConfigurer
implements
WebMvcConfigurer
,
InitializingBean
{
...
...
@@ -81,8 +77,11 @@ public class SpringWebMvcConfigurer implements WebMvcConfigurer, InitializingBea
*/
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
registry
.
addInterceptor
(
new
SessionInterceptor
(
userService
)).
addPathPatterns
(
"/**"
);
// super.addInterceptors(registry);
registry
.
addInterceptor
(
new
HttpRequestInterceptor
()).
addPathPatterns
(
"/**"
);
registry
.
addInterceptor
(
new
SessionInterceptor
(
userService
))
.
excludePathPatterns
(
"/user/login"
,
"/error"
,
"/user/logout"
)
.
addPathPatterns
(
"/**"
);
}
/**
...
...
@@ -124,6 +123,22 @@ public class SpringWebMvcConfigurer implements WebMvcConfigurer, InitializingBea
}
}
class
HttpRequestInterceptor
implements
HandlerInterceptor
{
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
{
HttpRequestLocal
.
set
(
request
);
return
true
;
}
@Override
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
{
HttpRequestLocal
.
destory
();
}
}
class
SessionInterceptor
implements
HandlerInterceptor
{
CoreUserService
userService
;
...
...
@@ -135,38 +150,20 @@ class SessionInterceptor implements HandlerInterceptor {
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
{
HttpRequestLocal
.
set
(
request
);
if
(
StrUtil
.
containsAny
(
request
.
getRequestURI
(),
"/login"
,
"/error"
,
"/logout"
))
{
return
true
;
}
String
token
=
HttpRequestLocal
.
getAuthorization
();
Map
<
String
,
Object
>
payload
=
JoseJwtUtil
.
parsePayload
(
token
);
if
(
payload
.
isEmpty
()
)
{
boolean
isExpiration
=
JoseJwtUtil
.
verifyJwtJson
(
token
);
if
(
isExpiration
)
{
/*验证失败,无效jwt*/
return
false
;
}
else
{
token
=
JoseJwtUtil
.
refreshIssuedAtTime
(
token
);
response
.
setHeader
(
HttpHeaders
.
AUTHORIZATION
,
token
);
}
return
true
;
}
@Override
public
void
postHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
ModelAndView
modelAndView
)
{
/* do nothing */
}
@Override
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
{
/* do nothing */
}
}
/** 自定义SpringMVC的controller参数注解 {@link RequestBodyPlus} 的注入解析,用json path 的方式注入json请求的参数 */
/** 自定义SpringMVC的controller
方法的
参数注解 {@link RequestBodyPlus} 的注入解析,
用json path 的方式注入json请求的参数 */
class
RequestBodyPlusProcessor
extends
AbstractMessageConverterMethodProcessor
{
private
static
final
ThreadLocal
<
String
>
bodyLocal
=
ThreadLocal
.
withInitial
(()
->
"{}"
);
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/entity/CoreUser.java
View file @
a0a51905
...
...
@@ -25,24 +25,20 @@ public class CoreUser extends BaseEntity {
@NotNull
(
message
=
"ID不能为空"
,
groups
=
ValidateConfig
.
UPDATE
.
class
)
@SeqID
(
name
=
ORACLE_CORE_SEQ_NAME
)
@ElColumn
(
name
=
"ID"
,
type
=
ElColumnType
.
STRING
)
@AutoID
protected
Long
id
;
// 删除标识
@JsonIgnore
protected
Integer
delFlag
=
0
;
// 创建时间
@ElColumn
(
name
=
"创建时间"
,
type
=
ElColumnType
.
DATE
)
protected
Date
createTime
;
// 登录名,编号
@NotBlank
(
message
=
"用户编号不能为空"
,
groups
=
ValidateConfig
.
ADD
.
class
)
@Null
(
message
=
"用户编号不能为空"
,
groups
=
ValidateConfig
.
UPDATE
.
class
)
@ElColumn
(
name
=
"用户名"
,
type
=
ElColumnType
.
STRING
)
private
String
code
;
// 用户姓名
@NotBlank
(
message
=
"用户名不能为空"
)
@ElColumn
(
name
=
"姓名"
,
type
=
ElColumnType
.
STRING
)
private
String
name
;
// 组织机构id
...
...
@@ -53,16 +49,13 @@ public class CoreUser extends BaseEntity {
@JsonIgnore
private
String
password
;
@Dict
(
type
=
CoreDictType
.
USER_STATE
)
@ElColumn
(
name
=
"状态"
,
type
=
ElColumnType
.
STRING
)
private
String
state
;
// 扩展例子
@Dict
(
type
=
"job_type"
)
@ElColumn
(
name
=
"职位"
,
type
=
ElColumnType
.
DICT
)
private
DictType
jobType0
;
@Dict
(
type
=
"job_type"
)
@ElColumn
(
name
=
"职位"
,
type
=
ElColumnType
.
DICT
)
private
DictType
jobType1
;
private
Date
updateTime
;
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/entity/DictType.java
View file @
a0a51905
...
...
@@ -4,10 +4,9 @@ import lombok.Data;
import
lombok.NoArgsConstructor
;
/**
* 专门用于前端UI下拉选择器的字典数据返回类型,与{@link CoreDict} 不同,它是业务中的类。
* 用于数据库表的字典字段映射到本对象中的value字段<br>
* 用于数据表格的显示<br/>
* pojo中字典字段必须使用该类定义<br>
*
处理最终的字典值
由{@link com.ibeetl.admin.core.service.CoreBaseService#processDictField} 方法
提供
<br/>
* 由{@link com.ibeetl.admin.core.service.CoreBaseService#processDictField} 方法
转换
<br/>
*/
@Data
@NoArgsConstructor
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/entity/ElCascaderData.java
0 → 100644
View file @
a0a51905
package
com.ibeetl.admin.core.entity
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/** 前端级联器的数据格式类 */
@Data
@NoArgsConstructor
public
class
ElCascaderData
{
private
Long
id
;
private
String
label
;
private
String
value
;
}
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/service/CoreBaseService.java
View file @
a0a51905
package
com.ibeetl.admin.core.service
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.lang.Assert
;
import
cn.hutool.core.util.ClassUtil
;
import
cn.hutool.core.util.ReflectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.ibeetl.admin.core.dao.SQLManagerBaseDao
;
import
com.ibeetl.admin.core.entity.DictType
;
import
com.ibeetl.admin.core.util.AnnotationUtil
;
import
com.ibeetl.admin.core.util.FileDownloadUtil
;
import
com.ibeetl.admin.core.util.cache.DictCacheUtil
;
import
java.beans.BeanInfo
;
import
java.beans.IntrospectionException
;
import
java.beans.Introspector
;
import
java.beans.PropertyDescriptor
;
import
com.ibeetl.admin.core.util.cache.DictTypeCacheUtil
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.ParameterizedType
;
import
java.util.ArrayList
;
...
...
@@ -22,8 +13,6 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
org.beetl.sql.core.SQLManager
;
import
org.beetl.sql.core.TailBean
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -32,7 +21,6 @@ import com.ibeetl.admin.core.annotation.Dict;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.util.enums.DelFlagEnum
;
import
org.springframework.beans.factory.annotation.Qualifier
;
/**
* 描述:
...
...
@@ -213,12 +201,12 @@ public class CoreBaseService<T> {
}
public
void
processObjectsDictField
(
PageQuery
pageQuery
){
processObjectsDictField
(
pageQuery
.
getList
());
this
.
processObjectsDictField
(
pageQuery
.
getList
());
}
public
void
processObjectsDictField
(
Collection
collection
){
for
(
Object
o
:
collection
)
{
processDictField
(
o
);
this
.
processDictField
(
o
);
}
}
...
...
@@ -236,7 +224,7 @@ public class CoreBaseService<T> {
continue
;
}
DictType
key
=
new
DictType
(
type
,
dictType
.
getValue
());
dictType
=
DictCacheUtil
.
get
(
key
);
dictType
=
Dict
Type
CacheUtil
.
get
(
key
);
ReflectUtil
.
setFieldValue
(
object
,
field
,
dictType
);
}
}
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/service/CoreDictService.java
View file @
a0a51905
package
com.ibeetl.admin.core.service
;
import
cn.hutool.core.util.StrUtil
;
import
com.ibeetl.admin.core.web.JsonResult
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.beetl.sql.core.mapper.internal.LambdaQueryAmi
;
import
org.beetl.sql.core.query.LambdaQuery
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -24,8 +28,6 @@ import com.ibeetl.admin.core.util.enums.DelFlagEnum;
@Transactional
public
class
CoreDictService
extends
CoreBaseService
<
CoreDict
>
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
CoreDictService
.
class
);
@Autowired
private
CoreDictDao
dictDao
;
@Autowired
CorePlatformService
platformService
;
...
...
@@ -57,14 +59,27 @@ public class CoreDictService extends CoreBaseService<CoreDict> {
}
/**
* 级联字段下一级的字段列表
* Method findChildByParent ...<br>
* 获取某类型或者某个父级下的字典列表,参数二选一即可,也可都有。不可都不存在 <br>
*
* @param id : 父级的 parentValue
* @return
* @param parentId of type Long 父级id
* @param type of type String 字典type
* @return List<CoreDict>
*/
@Cacheable
(
value
=
CorePlatformService
.
DICT_CACHE_CHILDREN
)
public
List
<
CoreDict
>
findChildByParent
(
Long
id
)
{
return
dictDao
.
findChildByParent
(
id
);
public
List
<
CoreDict
>
findChildByParent
(
Long
parentId
,
String
type
)
{
if
(
StrUtil
.
isBlank
(
type
)
&&
parentId
==
null
)
{
return
null
;
}
LambdaQuery
<
CoreDict
>
lambdaQuery
=
dictDao
.
getSQLManager
().
lambdaQuery
(
CoreDict
.
class
);
if
(
parentId
!=
null
)
{
lambdaQuery
.
andEq
(
CoreDict:
:
getParent
,
parentId
);
}
if
(
StrUtil
.
isNotBlank
(
type
))
{
lambdaQuery
.
andEq
(
CoreDict:
:
getType
,
type
);
}
List
<
CoreDict
>
coreDictList
=
lambdaQuery
.
orderBy
(
CoreDict:
:
getSort
).
select
();
return
coreDictList
;
}
@Cacheable
(
value
=
CorePlatformService
.
DICT_CACHE_VALUE
)
...
...
@@ -98,7 +113,7 @@ public class CoreDictService extends CoreBaseService<CoreDict> {
if
(
dict
.
getValue
().
equals
(
value
))
{
return
list
;
}
else
{
List
<
CoreDict
>
children
=
findChildByParent
(
dict
.
getId
());
List
<
CoreDict
>
children
=
findChildByParent
(
dict
.
getId
()
,
null
);
if
(
children
.
isEmpty
())
{
continue
;
}
else
{
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/service/CoreUserService.java
View file @
a0a51905
...
...
@@ -76,7 +76,7 @@ public class CoreUserService extends CoreBaseService {
.
getSQLManager
()
.
lambdaQuery
(
CoreUser
.
class
)
.
page
(
page
,
limit
);
processObjectsDictField
(
pageQuery
);
super
.
processObjectsDictField
(
pageQuery
);
return
pageQuery
;
}
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/service/DictTypeService.java
deleted
100644 → 0
View file @
31fc8a95
package
com.ibeetl.admin.core.service
;
import
com.ibeetl.admin.core.dao.CoreDictDao
;
import
com.ibeetl.admin.core.entity.DictType
;
import
java.util.List
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Slf4j
@Service
public
class
DictTypeService
{
@Autowired
private
CoreDictDao
dictDao
;
public
List
<
DictType
>
findAllList
(
String
type
)
{
return
dictDao
.
findAllDictType
(
type
);
}
}
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/util/HttpRequestLocal.java
View file @
a0a51905
...
...
@@ -75,6 +75,10 @@ public final class HttpRequestLocal {
getHttpSession
().
removeAttribute
(
ACCESS_USER_ORGS
);
}
public
static
void
destory
()
{
requests
.
remove
();
}
public
static
Cookie
getCookieByName
(
String
cookieName
)
{
Assert
.
notNull
(
cookieName
);
Cookie
[]
cookies
=
get
().
getCookies
();
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/util/JoseJwtUtil.java
View file @
a0a51905
...
...
@@ -16,28 +16,125 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
/**
* 基于jose4j的jwt库工具类。 包括:生成,验证,解析负载。<br/>
* 可以用对称加密算法在此对token进行加密,逻辑上可以每隔一周或者一天,动态生成对称加密算法的密钥,然后防止破解。<br/>
* 这样可以用jwt来承担更多的数据传递。至于客官怎么选择——萝卜青菜各有所爱<br/>
* 基于jose4j的jwt库工具类。 包括:生成,验证,解析负载。<br>
* 可以用对称加密算法在此对token进行加密,逻辑上可以每隔一周或者一天,动态生成对称加密算法的密钥,然后防止破解。<br>
* 这样可以用jwt来承担更多的数据传递。至于客官怎么选择——萝卜青菜各有所爱<br>
* iss: jwt签发者 sub: jwt所面向的用户 aud: 接收jwt的一方 exp: jwt的过期时间,这个过期时间必须要大于签发时间 nbf: 定义在什么时间之前,该jwt都是不可用的.
* iat: jwt的签发时间 jti: jwt的唯一身份标识,主要用来作为一次性token,从而回避重放攻击。
*
* @author 一日看尽长安花
*/
public
class
JoseJwtUtil
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
JoseJwtUtil
.
class
);
private
static
int
EXPIRATION_TIME
=
10
;
/**
* Method generateJwtToken ... <br>
* 生成jwt token字符串
*
* @param uid of type String
* @return String
*/
public
static
String
generateJwtToken
(
String
uid
)
{
JwtClaims
jwtClaims
=
JoseJwtUtil
.
getJwtClaims
(
uid
);
JsonWebSignature
jsonWebSignature
=
JoseJwtUtil
.
getJsonWebSignature
(
jwtClaims
);
String
jwt
=
"invalid jwt"
;
try
{
jwt
=
jsonWebSignature
.
getCompactSerialization
();
}
catch
(
JoseException
e
)
{
logger
.
error
(
"can't generate jwt of {} user.: detail see next follow: \n {} "
,
uid
,
e
.
getLocalizedMessage
());
}
return
jwt
;
}
public
static
String
generateJwtJson
(
String
uid
)
{
/**
* Method verifyJwtJson ... <br>
* 验证jwt是否过期<br>
*
* @param token of type String
* @return boolean
*/
public
static
boolean
verifyJwtJson
(
String
token
)
{
return
JoseJwtUtil
.
parsePayload
(
token
).
isEmpty
();
}
/**
* Method refreshIssuedAtTime ...<br>
* 刷新颁发时间,达到重置30分钟时间验证窗口
*
* @param token of type String
* @return String
*/
public
static
String
refreshIssuedAtTime
(
String
token
)
{
JwtConsumer
jwtConsumer
=
JoseJwtUtil
.
getJwtConsumer
(
token
);
JwtClaims
jwtClaims
=
null
;
String
jwt
=
"invalid jwt"
;
try
{
jwtClaims
=
jwtConsumer
.
processToClaims
(
token
);
jwtClaims
.
setIssuedAtToNow
();
jwtClaims
.
setExpirationTimeMinutesInTheFuture
(
EXPIRATION_TIME
);
JsonWebSignature
jsonWebSignature
=
JoseJwtUtil
.
getJsonWebSignature
(
jwtClaims
);
jwt
=
jsonWebSignature
.
getCompactSerialization
();
}
catch
(
InvalidJwtException
e
)
{
logger
.
error
(
"parser token fail.detail see next follow: {} "
,
e
.
getLocalizedMessage
());
}
catch
(
JoseException
e
)
{
logger
.
error
(
"can't refresh jwt : detail see next follow: \n {} "
,
e
.
getLocalizedMessage
());
}
return
jwt
;
}
/**
* Method parsePayload ... 解析请求中的jwt token,返回map是为了避免业务中使用jose的类。 若有必要可以自定义一个类
*
* @param token of type String
* @return Map<String, Object>
*/
public
static
Map
<
String
,
Object
>
parsePayload
(
String
token
)
{
JwtConsumer
jwtConsumer
=
JoseJwtUtil
.
getJwtConsumer
(
token
);
Map
<
String
,
Object
>
claimsMap
=
MapUtil
.
newHashMap
(
0
);
try
{
JwtClaims
jwtClaims
=
jwtConsumer
.
processToClaims
(
token
);
claimsMap
=
jwtClaims
.
getClaimsMap
();
}
catch
(
InvalidJwtException
e
)
{
logger
.
error
(
"parser token fail.detail see next follow: {} "
,
e
.
getLocalizedMessage
());
}
return
claimsMap
;
}
public
static
JsonWebSignature
getJsonWebSignature
(
JwtClaims
jwtClaims
)
{
RsaJsonWebKey
rsaJsonWebKey
=
RsaJsonWebKeyBuilder
.
getRasJsonWebKeyInstance
();
JsonWebSignature
jsonWebSignature
=
new
JsonWebSignature
();
jsonWebSignature
.
setPayload
(
jwtClaims
.
toJson
());
jsonWebSignature
.
setKey
(
rsaJsonWebKey
.
getPrivateKey
());
jsonWebSignature
.
setKeyIdHeaderValue
(
rsaJsonWebKey
.
getKeyId
());
jsonWebSignature
.
setAlgorithmHeaderValue
(
AlgorithmIdentifiers
.
RSA_USING_SHA256
);
return
jsonWebSignature
;
}
/**
* Method getJwtClaims ... <br>
* 获取jwt 签名类 <br>
* 包含了登录时间,所以尽可能只用于登录的jwt<br>
*
* @param uid of type String
* @return JwtClaims
*/
public
static
JwtClaims
getJwtClaims
(
String
uid
)
{
JwtClaims
jwtClaims
=
new
JwtClaims
();
jwtClaims
.
setExpirationTimeMinutesInTheFuture
(
30
);
/* 以分钟为单位的过期时间 */
/* who creates the token and signs it */
/*设置过期时间*/
/* 颁发签名者 */
jwtClaims
.
setIssuer
(
"Issuer"
);
/*
to whom the token is intended to be sent
*/
/*
接收签名者
*/
jwtClaims
.
setAudience
(
"Audience"
);
/* a unique identifier for the token */
jwtClaims
.
setGeneratedJwtId
();
/* when the token was issued/created (now) */
jwtClaims
.
setIssuedAtToNow
();
/* time before which the token is not yet valid (2 minutes ago) */
/* 以分钟为单位的过期时间 */
jwtClaims
.
setExpirationTimeMinutesInTheFuture
(
EXPIRATION_TIME
);
/* 参照jwt规范中nbf字段。用于解决多服务中时间差问题 */
jwtClaims
.
setNotBeforeMinutesInThePast
(
2
);
/*主题:签证*/
jwtClaims
.
setSubject
(
"Bearer"
);
...
...
@@ -46,33 +143,21 @@ public class JoseJwtUtil {
/*登录时间*/
jwtClaims
.
setClaim
(
"ltm"
,
System
.
currentTimeMillis
());
RsaJsonWebKey
rsaJsonWebKey
=
RsaJsonWebKeyBuilder
.
getRasJsonWebKeyInstance
();
JsonWebSignature
jsonWebSignature
=
new
JsonWebSignature
();
jsonWebSignature
.
setPayload
(
jwtClaims
.
toJson
());
jsonWebSignature
.
setKey
(
rsaJsonWebKey
.
getPrivateKey
());
jsonWebSignature
.
setKeyIdHeaderValue
(
rsaJsonWebKey
.
getKeyId
());
jsonWebSignature
.
setAlgorithmHeaderValue
(
AlgorithmIdentifiers
.
RSA_USING_SHA256
);
String
jwt
=
"invalid jwt"
;
try
{
jwt
=
jsonWebSignature
.
getCompactSerialization
();
}
catch
(
JoseException
e
)
{
logger
.
error
(
"can't generate jwt of user: {}. detail see next follow: \n {} "
,
uid
,
e
.
getLocalizedMessage
());
}
return
jwt
;
}
public
static
boolean
verifyJwtJson
(
String
token
)
{
return
JoseJwtUtil
.
parsePayload
(
token
).
isEmpty
();
return
jwtClaims
;
}
public
static
Map
<
String
,
Object
>
parsePayload
(
String
token
)
{
/**
* Method getJwtConsumer ... 获取 jwt 验证消费者
*
* @param token of type String
* @return JwtConsumer
*/
public
static
JwtConsumer
getJwtConsumer
(
String
token
)
{
JwtConsumer
jwtConsumer
=
new
JwtConsumerBuilder
()
.
setRequireExpirationTime
()
// the JWT must have an expiration time
.
setMaxFutureValidityInMinutes
(
30
)
// but the expiration time can't be too crazy
.
setMaxFutureValidityInMinutes
(
EXPIRATION_TIME
)
// but the expiration time can't be too crazy
.
setAllowedClockSkewInSeconds
(
30
)
// 允许校准过期时间的偏差30秒
.
setRequireSubject
()
// the JWT must have a subject claim
.
setExpectedIssuer
(
"Issuer"
)
// whom the JWT needs to have been issued by
...
...
@@ -81,16 +166,15 @@ public class JoseJwtUtil {
RsaJsonWebKeyBuilder
.
getRasJsonWebKeyInstance
()
.
getPublicKey
())
// verify the signature with the public key
.
build
();
// create the JwtConsumer instance
Map
<
String
,
Object
>
claimsMap
=
MapUtil
.
newHashMap
(
0
);
try
{
JwtClaims
jwtClaims
=
jwtConsumer
.
processToClaims
(
token
);
claimsMap
=
jwtClaims
.
getClaimsMap
();
}
catch
(
InvalidJwtException
e
)
{
logger
.
error
(
"parser token fail.detail see next follow: {} "
,
e
.
getLocalizedMessage
());
}
return
claimsMap
;
return
jwtConsumer
;
}
/**
* Class RsaJsonWebKeyBuilder : <br>
* 描述:线程安全
*
* @author 一日看尽长安花 Created on 2020/1/11
*/
private
static
class
RsaJsonWebKeyBuilder
{
private
static
volatile
RsaJsonWebKey
rsaJsonWebKey
;
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/util/cache/DictCacheUtil.java
→
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/util/cache/Dict
Type
CacheUtil.java
View file @
a0a51905
...
...
@@ -10,7 +10,13 @@ import com.ibeetl.admin.core.util.SpringUtil;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
DictCacheUtil
{
/**
* Class DictTypeCacheUtil : <br/>
* 描述:{@link DictType} 类的缓存工具类,同时提供将 {@link CoreDict} 转换至 {@link DictType} 方法
* @author 一日看尽长安花
* Created on 2020/1/11
*/
public
class
DictTypeCacheUtil
{
private
static
final
Cache
<
String
,
Object
>
CACHE
=
Caffeine
.
newBuilder
().
maximumSize
(
1024
).
recordStats
().
build
();
...
...
@@ -38,6 +44,12 @@ public class DictCacheUtil {
});
}
/**
* Method getKey ...
* 一个字典记录的key应该由type + value 构成
* @param dictType of type DictType
* @return String
*/
public
static
String
getKey
(
DictType
dictType
)
{
return
dictType
.
getType
()
+
":"
+
dictType
.
getValue
();
}
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/util/enums/ElColumnType.java
View file @
a0a51905
...
...
@@ -7,7 +7,10 @@ public interface ElColumnType {
/** 前端页面输入框 */
String
STRING
=
"string"
;
/** 前端页面下拉选择器 */
/**
* 不出现在搜索面板中,只出现在数据表格中。
* 建议下拉选择器通过级联选择器实现
* */
String
DICT
=
"dict"
;
/** 前端页面的日期选择器 */
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/web/CoreDictController.java
View file @
a0a51905
...
...
@@ -46,7 +46,7 @@ public class CoreDictController {
@ResponseBody
public
JsonResult
<
List
<
CoreDict
>>
viewChild
(
String
group
,
String
value
)
{
CoreDict
dict
=
dictService
.
findCoreDict
(
group
,
value
);
List
<
CoreDict
>
list
=
dictService
.
findChildByParent
(
dict
.
getId
());
List
<
CoreDict
>
list
=
dictService
.
findChildByParent
(
dict
.
getId
()
,
null
);
return
JsonResult
.
success
(
list
);
}
}
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/web/Dict
Data
ElController.java
→
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/web/Dict
Cascader
ElController.java
View file @
a0a51905
package
com.ibeetl.admin.core.web
;
import
c
om.ibeetl.admin.core.annotation.RequestBodyPlus
;
import
c
n.hutool.core.util.StrUtil
;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.entity.
DictType
;
import
com.ibeetl.admin.core.entity.
ElCascaderData
;
import
com.ibeetl.admin.core.service.CoreDictService
;
import
com.ibeetl.admin.core.service.CorePlatformService
;
import
com.ibeetl.admin.core.service.DictTypeService
;
import
java.util.ArrayList
;
import
java.util.List
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -22,19 +20,35 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping
(
value
=
"/core/dicts"
)
public
class
Dict
Data
ElController
{
public
class
Dict
Cascader
ElController
{
@Autowired
DictTypeService
dictType
Service
;
@Autowired
CoreDictService
coreDict
Service
;
/**
*
根据字典类型type,获取所有字典数据并返回
*
Method obtainDcitsByCascader ... 获取子级字典列表。如果不传父级id,只获取type指定的列表而已。
*
* @param type
* @return
* @param parentId of type Long 父级id
* @param type of type String 子级字典列表type
* @return JsonResult<List < ElCascaderData>>
*/
@GetMapping
public
JsonResult
<
List
<
DictType
>>
dictList
(
String
type
)
{
List
<
DictType
>
list
=
dictTypeService
.
findAllList
(
type
);
return
JsonResult
.
success
(
list
);
public
JsonResult
<
List
<
ElCascaderData
>>
obtainDcitsByCascader
(
Long
parentId
,
String
type
)
{
if
(
StrUtil
.
isBlank
(
type
)
&&
parentId
==
null
)
{
return
JsonResult
.
failMessage
(
"parentId and type should have at least one."
);
}
List
<
CoreDict
>
childDictList
=
coreDictService
.
findChildByParent
(
parentId
,
type
);
return
JsonResult
.
success
(
convertToCascaderData
(
childDictList
));
}
private
List
<
ElCascaderData
>
convertToCascaderData
(
List
<
CoreDict
>
coreDicts
)
{
List
<
ElCascaderData
>
cascaderDataArrayList
=
new
ArrayList
<
ElCascaderData
>(
coreDicts
.
size
());
for
(
CoreDict
dict
:
coreDicts
)
{
ElCascaderData
data
=
new
ElCascaderData
();
data
.
setId
(
dict
.
getId
());
data
.
setLabel
(
dict
.
getName
());
data
.
setValue
(
dict
.
getValue
());
cascaderDataArrayList
.
add
(
data
);
}
return
cascaderDataArrayList
;
}
}
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/web/
Core
UserElController.java
→
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/web/User
Login
ElController.java
View file @
a0a51905
...
...
@@ -12,7 +12,6 @@ import com.ibeetl.admin.core.service.CoreUserService;
import
com.ibeetl.admin.core.util.HttpRequestLocal
;
import
com.ibeetl.admin.core.util.JoseJwtUtil
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.web.JsonResult
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -21,7 +20,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
public
class
Core
UserElController
{
public
class
User
Login
ElController
{
@Autowired
private
RoleRoutesElService
roleRoutesService
;
...
...
@@ -67,7 +66,7 @@ public class CoreUserElController {
HttpRequestLocal
.
setLoginerInfo
(
info
.
getUser
(),
info
.
getCurrentOrg
(),
info
.
getOrgs
());
Map
<
String
,
Object
>
resultMap
=
MapUtil
.<
String
,
Object
>
builder
()
.
put
(
"token"
,
JoseJwtUtil
.
generateJwt
Jso
n
(
String
.
valueOf
(
user
.
getId
())))
.
put
(
"token"
,
JoseJwtUtil
.
generateJwt
Toke
n
(
String
.
valueOf
(
user
.
getId
())))
.
build
();
return
JsonResult
.
success
(
resultMap
);
}
...
...
plus-admin/admin-core/src/main/resources/sql/core/coreDict.md
View file @
a0a51905
...
...
@@ -32,7 +32,6 @@ findChildByParent
WHERE
parent = #id# and del_flag = 0 order by sort DESC
bathDelByValue
===
update core_dict set del_flag =1 where value in in ( #join(values)#)
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment