Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataease
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
njgzx
dataease
Commits
f297fd7a
提交
f297fd7a
authored
6月 07, 2021
作者:
fit2cloud-chenyw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 优化 授权、安装插件、更新lic、lic到期 不需要重新登录(需要刷新浏览器)才能刷新权限数据
上级
f1c552ff
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
202 行增加
和
4 行删除
+202
-4
F2CRealm.java
backend/src/main/java/io/dataease/auth/config/F2CRealm.java
+7
-0
JWTUtils.java
backend/src/main/java/io/dataease/auth/util/JWTUtils.java
+0
-3
LicCacheEventListener.java
...main/java/io/dataease/listener/LicCacheEventListener.java
+80
-0
CacheUtils.java
...d/src/main/java/io/dataease/listener/util/CacheUtils.java
+61
-0
XAuthServer.java
...src/main/java/io/dataease/plugins/server/XAuthServer.java
+12
-0
AboutService.java
backend/src/main/java/io/dataease/service/AboutService.java
+12
-1
PluginService.java
.../src/main/java/io/dataease/service/sys/PluginService.java
+12
-0
ehcache.xml
backend/src/main/resources/ehcache/ehcache.xml
+14
-0
request.js
frontend/src/utils/request.js
+4
-0
没有找到文件。
backend/src/main/java/io/dataease/auth/config/F2CRealm.java
浏览文件 @
f297fd7a
...
...
@@ -8,6 +8,8 @@ import io.dataease.auth.entity.TokenInfo;
import
io.dataease.auth.service.AuthUserService
;
import
io.dataease.auth.util.JWTUtils
;
import
io.dataease.commons.utils.BeanUtils
;
import
io.dataease.commons.utils.LogUtil
;
import
io.dataease.listener.util.CacheUtils
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.AuthenticationInfo
;
import
org.apache.shiro.authc.AuthenticationToken
;
...
...
@@ -54,6 +56,11 @@ public class F2CRealm extends AuthorizingRealm {
@Override
protected
AuthenticationInfo
doGetAuthenticationInfo
(
AuthenticationToken
auth
)
throws
AuthenticationException
{
try
{
CacheUtils
.
get
(
"lic_info"
,
"lic"
);
}
catch
(
Exception
e
)
{
LogUtil
.
error
(
e
);
}
String
token
=
(
String
)
auth
.
getCredentials
();
// 解密获得username,用于和数据库进行对比
TokenInfo
tokenInfo
=
JWTUtils
.
tokenInfoByToken
(
token
);
...
...
backend/src/main/java/io/dataease/auth/util/JWTUtils.java
浏览文件 @
f297fd7a
...
...
@@ -6,12 +6,9 @@ import com.auth0.jwt.algorithms.Algorithm;
import
com.auth0.jwt.exceptions.JWTDecodeException
;
import
com.auth0.jwt.interfaces.DecodedJWT
;
import
io.dataease.auth.entity.TokenInfo
;
import
io.dataease.auth.filter.JWTFilter
;
import
io.dataease.commons.utils.CommonBeanFactory
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.springframework.core.env.Environment
;
import
java.util.Date
;
...
...
backend/src/main/java/io/dataease/listener/LicCacheEventListener.java
0 → 100644
浏览文件 @
f297fd7a
package
io
.
dataease
.
listener
;
import
io.dataease.commons.constants.AuthConstants
;
import
io.dataease.listener.util.CacheUtils
;
import
net.sf.ehcache.CacheException
;
import
net.sf.ehcache.Ehcache
;
import
net.sf.ehcache.Element
;
import
net.sf.ehcache.event.CacheEventListener
;
import
net.sf.ehcache.event.CacheEventListenerFactory
;
import
org.springframework.stereotype.Component
;
import
java.util.Properties
;
@Component
public
class
LicCacheEventListener
extends
CacheEventListenerFactory
implements
CacheEventListener
{
private
static
CacheEventListener
cacheEventListener
;
public
LicCacheEventListener
()
{
cacheEventListener
=
cacheEventListener
==
null
?
this
:
cacheEventListener
;
}
@Override
public
void
notifyElementRemoved
(
Ehcache
ehcache
,
Element
element
)
throws
CacheException
{
/*System.out.println("notifyElementRemoved");*/
}
@Override
public
void
notifyElementPut
(
Ehcache
ehcache
,
Element
element
)
throws
CacheException
{
/*long expirationTime = element.getExpirationTime();
System.out.println(expirationTime);
System.out.println("notifyElementPut");*/
}
@Override
public
void
notifyElementUpdated
(
Ehcache
ehcache
,
Element
element
)
throws
CacheException
{
/*System.out.println("notifyElementUpdated");*/
}
/**
* lic过期触发: 清除用户、角色、权限缓存
* @param ehcache
* @param element
*/
@Override
public
void
notifyElementExpired
(
Ehcache
ehcache
,
Element
element
)
{
// System.out.println("notifyElementExpired");
/*String token = ServletUtils.getToken();
Long userId = JWTUtils.tokenInfoByToken(token).getUserId();
authUserService.clearCache(userId);*/
CacheUtils
.
removeAll
(
AuthConstants
.
USER_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_ROLE_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_PERMISSION_CACHE_NAME
);
}
@Override
public
void
notifyElementEvicted
(
Ehcache
ehcache
,
Element
element
)
{
/*System.out.println("notifyElementEvicted");*/
}
@Override
public
void
notifyRemoveAll
(
Ehcache
ehcache
)
{
/*System.out.println("notifyRemoveAll");*/
}
@Override
public
void
dispose
()
{
}
@Override
public
CacheEventListener
createCacheEventListener
(
Properties
properties
)
{
return
cacheEventListener
;
}
@Override
public
Object
clone
()
throws
CloneNotSupportedException
{
return
super
.
clone
();
}
}
backend/src/main/java/io/dataease/listener/util/CacheUtils.java
0 → 100644
浏览文件 @
f297fd7a
package
io
.
dataease
.
listener
.
util
;
import
net.sf.ehcache.Cache
;
import
net.sf.ehcache.Element
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.ehcache.EhCacheCacheManager
;
import
org.springframework.context.annotation.Configuration
;
import
java.util.Date
;
@Configuration
public
class
CacheUtils
{
private
static
CacheManager
manager
;
@Autowired
public
void
setManager
(
CacheManager
manager
)
{
CacheUtils
.
manager
=
manager
;
}
public
static
Object
get
(
String
cacheName
,
Object
key
)
{
Element
element
=
cache
(
cacheName
).
get
(
key
);
if
(
null
==
element
)
return
null
;
return
element
.
getObjectValue
();
}
private
static
void
put
(
String
cacheName
,
Object
key
,
Object
value
,
Integer
ttl
,
Integer
tti
)
{
Element
e
=
new
Element
(
key
,
value
);
//不设置则使用xml配置
if
(
ttl
!=
null
)
e
.
setEternal
(
false
);
e
.
setTimeToLive
(
ttl
);
if
(
tti
!=
null
)
e
.
setTimeToIdle
(
tti
);
cache
(
cacheName
).
put
(
e
);
}
private
static
boolean
remove
(
String
cacheName
,
Object
key
)
{
return
cache
(
cacheName
).
remove
(
key
);
}
public
static
void
removeAll
(
String
cacheName
)
{
cache
(
cacheName
).
removeAll
();
}
private
static
Cache
cache
(
String
cacheName
)
{
net
.
sf
.
ehcache
.
CacheManager
cacheManager
=
((
EhCacheCacheManager
)
manager
).
getCacheManager
();
if
(!
cacheManager
.
cacheExists
(
cacheName
))
cacheManager
.
addCache
(
cacheName
);
Cache
cacheManagerCache
=
cacheManager
.
getCache
(
cacheName
);
return
cacheManagerCache
;
}
public
static
void
updateLicCache
(
Date
expDate
){
long
time
=
expDate
.
getTime
();
long
exp
=
(
time
-
System
.
currentTimeMillis
())
/
1000
;
int
intExp
=
(
int
)
exp
;
removeAll
(
"lic_info"
);
put
(
"lic_info"
,
"lic"
,
"lic"
,
intExp
,
intExp
);
}
}
backend/src/main/java/io/dataease/plugins/server/XAuthServer.java
浏览文件 @
f297fd7a
...
...
@@ -2,18 +2,22 @@ package io.dataease.plugins.server;
import
io.dataease.auth.api.dto.CurrentUserDto
;
import
io.dataease.commons.constants.AuthConstants
;
import
io.dataease.commons.utils.AuthUtils
;
import
io.dataease.controller.handler.annotation.I18n
;
import
io.dataease.listener.util.CacheUtils
;
import
io.dataease.plugins.config.SpringContextUtil
;
import
io.dataease.plugins.xpack.auth.dto.request.XpackBaseTreeRequest
;
import
io.dataease.plugins.xpack.auth.dto.request.XpackSysAuthRequest
;
import
io.dataease.plugins.xpack.auth.dto.response.XpackSysAuthDetail
;
import
io.dataease.plugins.xpack.auth.dto.response.XpackSysAuthDetailDTO
;
import
io.dataease.plugins.xpack.auth.dto.response.XpackVAuthModelDTO
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.web.bind.annotation.*
;
import
io.dataease.plugins.xpack.auth.service.AuthXpackService
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
@RequestMapping
(
"/plugin/auth"
)
@RestController
...
...
@@ -45,5 +49,13 @@ public class XAuthServer {
AuthXpackService
sysAuthService
=
SpringContextUtil
.
getBean
(
AuthXpackService
.
class
);
CurrentUserDto
user
=
AuthUtils
.
getUser
();
sysAuthService
.
authChange
(
request
,
user
.
getUserId
(),
user
.
getUsername
(),
user
.
getIsAdmin
());
// 当权限发生变化 前端实时刷新对应菜单
Optional
.
ofNullable
(
request
.
getAuthSourceType
()).
ifPresent
(
type
->
{
if
(
StringUtils
.
equals
(
"menu"
,
type
))
{
CacheUtils
.
removeAll
(
AuthConstants
.
USER_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_ROLE_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_PERMISSION_CACHE_NAME
);
}
});
}
}
backend/src/main/java/io/dataease/service/AboutService.java
浏览文件 @
f297fd7a
package
io
.
dataease
.
service
;
import
io.dataease.commons.constants.AuthConstants
;
import
io.dataease.commons.license.DefaultLicenseService
;
import
io.dataease.commons.license.F2CLicenseResponse
;
import
io.dataease.commons.utils.CommonBeanFactory
;
import
io.dataease.commons.utils.LogUtil
;
import
io.dataease.listener.util.CacheUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.core.env.Environment
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.util.Date
;
import
java.util.Optional
;
@Service
...
...
@@ -23,6 +25,15 @@ public class AboutService {
public
F2CLicenseResponse
updateLicense
(
String
licenseKey
)
{
F2CLicenseResponse
f2CLicenseResponse
=
defaultLicenseService
.
updateLicense
(
product
,
licenseKey
);
Optional
.
ofNullable
(
f2CLicenseResponse
).
ifPresent
(
resp
->
{
if
(
resp
.
getStatus
()
==
F2CLicenseResponse
.
Status
.
valid
){
CacheUtils
.
updateLicCache
(
new
Date
(
f2CLicenseResponse
.
getLicense
().
getExpired
()));
CacheUtils
.
removeAll
(
AuthConstants
.
USER_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_ROLE_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_PERMISSION_CACHE_NAME
);
}
});
return
f2CLicenseResponse
;
}
...
...
backend/src/main/java/io/dataease/service/sys/PluginService.java
浏览文件 @
f297fd7a
...
...
@@ -5,9 +5,11 @@ import io.dataease.base.domain.MyPlugin;
import
io.dataease.base.mapper.MyPluginMapper
;
import
io.dataease.base.mapper.ext.ExtSysPluginMapper
;
import
io.dataease.base.mapper.ext.query.GridExample
;
import
io.dataease.commons.constants.AuthConstants
;
import
io.dataease.commons.utils.DeFileUtils
;
import
io.dataease.commons.utils.ZipUtils
;
import
io.dataease.controller.sys.base.BaseGridRequest
;
import
io.dataease.listener.util.CacheUtils
;
import
io.dataease.plugins.config.LoadjarUtil
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -89,6 +91,10 @@ public class PluginService {
jarPath
=
DeFileUtils
.
copy
(
jarFile
,
targetDir
);
loadJar
(
jarPath
,
myPlugin
);
myPluginMapper
.
insert
(
myPlugin
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_ROLE_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_PERMISSION_CACHE_NAME
);
}
catch
(
Exception
e
)
{
if
(
StringUtils
.
isNotEmpty
(
targetDir
))
{
DeFileUtils
.
deleteFile
(
targetDir
);
...
...
@@ -137,6 +143,9 @@ public class PluginService {
* @return
*/
public
Boolean
uninstall
(
Long
pluginId
)
{
CacheUtils
.
removeAll
(
AuthConstants
.
USER_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_ROLE_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_PERMISSION_CACHE_NAME
);
myPluginMapper
.
deleteByPrimaryKey
(
pluginId
);
return
true
;
}
...
...
@@ -148,6 +157,9 @@ public class PluginService {
* @return
*/
public
Boolean
changeStatus
(
Long
pluginId
,
Boolean
status
)
{
CacheUtils
.
removeAll
(
AuthConstants
.
USER_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_ROLE_CACHE_NAME
);
CacheUtils
.
removeAll
(
AuthConstants
.
USER_PERMISSION_CACHE_NAME
);
return
false
;
}
...
...
backend/src/main/resources/ehcache/ehcache.xml
浏览文件 @
f297fd7a
...
...
@@ -69,5 +69,18 @@
memoryStoreEvictionPolicy=
"LRU"
/>
<cache
name=
"lic_info"
eternal=
"false"
maxElementsInMemory=
"10"
overflowToDisk=
"false"
diskPersistent=
"false"
timeToIdleSeconds=
"60"
timeToLiveSeconds=
"60"
memoryStoreEvictionPolicy=
"FIFO"
>
<cacheEventListenerFactory
class=
"io.dataease.listener.LicCacheEventListener"
/>
</cache>
</ehcache>
\ No newline at end of file
frontend/src/utils/request.js
浏览文件 @
f297fd7a
...
...
@@ -83,6 +83,10 @@ const checkAuth = response => {
const
linkToken
=
response
.
headers
[
LinkTokenKey
.
toLocaleLowerCase
()]
setLinkToken
(
linkToken
)
}
// 许可状态改变 刷新页面
// if (response.headers['lic-status']) {
// location.reload()
// }
}
// 请根据实际需求修改
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论